Skip to content

/usr/bin/env <cmd> not classified or rewritten (130 calls/30d) #83

Closed

Description

@thehoff

Symptom

`/usr/bin/env git status` (and equivalents — `/usr/bin/env `) bypasses the rewrite hook entirely:

```
$ echo '{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"/usr/bin/env git status"}}' | contextcrawler hook claude
$ echo "exit $?"
exit 0 # no JSON output → no rewrite
```

Local data shows 130 `env git …` invocations in the last 30 days, all routed raw (mostly from `git status` / `git diff` shells inside Codex).

Root cause

In `src/discover/registry.rs::classify_command`:

  1. `ENV_PREFIX.replace(trimmed, "")` runs first (line 113). Its pattern is `^(?:sudo\s+|env\s+|VAR=val\s+)+` — it matches the literal token `env` only, not the absolute path `/usr/bin/env`.
  2. `strip_absolute_path` runs second (line 120). Only then does the first word become `env`. By that point `ENV_PREFIX` has already been skipped and is not re-applied.

Net result: `env git status` is the input to the rule matcher, which has no rule for a leading `env` token, so it's marked `Unsupported { base_command: "env git" }`. Same defect in `rewrite_command` (uses the same `ENV_PREFIX` -> classify flow).

Fix

Two-line change: re-apply `ENV_PREFIX` after `strip_absolute_path`:

```rust
let cmd_normalized = strip_absolute_path(cmd_clean);
let cmd_normalized = ENV_PREFIX.replace(&cmd_normalized, "").to_string();
let cmd_normalized = strip_git_global_opts(&cmd_normalized);
```

(`strip_absolute_path` already returns owned `String`, so the borrow checker is content.)

Acceptance

  • Unit test: `classify_command("/usr/bin/env git status")` returns `Classification::Supported { rtk_equivalent: "contextcrawler git", … }`.
  • Hook smoke test: `echo '{...command: "/usr/bin/env git status"}' | contextcrawler hook claude` emits `updatedInput.command = "contextcrawler git status"`.
  • Same coverage for `/usr/bin/env `.

Notes

`/usr/bin/env` is the standard way Codex CLI and some shell wrappers invoke commands. Fixing this alone recovers ~130 calls/30d in my own data and probably much more in heavy Codex users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions