Skip to content

fix(rewrite): migrate rewrite_command output prefix rtk X -> contextcrawler X (#62) - #72

Merged
thehoff merged 1 commit into
developfrom
fix/rewrite-command-prefix-62
May 18, 2026
Merged

thehoff merged 1 commit into
developfrom
fix/rewrite-command-prefix-62

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #62. rewrite_command was returning "rtk git status" for every rewrite, but the binary is contextcrawler — Claude Code's hook substitutes the rewritten command into updatedInput.command and tried to exec the non-existent rtk binary. The bug stayed hidden because most session traffic flows via codex (which calls contextcrawler X directly per AGENTS.md template).

Empirical fix

Pre: {"updatedInput":{"command":"rtk git status"}} → command-not-found
Post: {"updatedInput":{"command":"contextcrawler git status"}} → executes

Changes

  • 73 RULES rtk_cmd: values + 5 inline format! builders rebranded
  • classify_command accepts contextcrawler X as already-wrapped (added to IGNORED_PREFIXES alongside existing rtk )
  • rewrite_segment_inner + rewrite_command accept BOTH prefixes for backcompat
  • 54 format!("rtk ...") + 53 plain-literal tracking labels across 36 cmd modules migrated
  • init.rs hook-content detection accepts both rtk rewrite / contextcrawler rewrite guards
  • gain.rs::display_cmd strips both prefixes so historical + new rows bucket together
  • ~180 test assertions rebranded inside #[cfg(test)] blocks (scoped Python; never touched production literals)

Stays rtk deliberately

Migration

None required. gain.rs::display_cmd strips both prefixes, so historical rows in history.db continue bucketing correctly with new rows.

Verified

  • 2119 bin tests pass / 0 fail
  • All 10 integration suites green
  • Hook end-to-end returns contextcrawler X (the actual binary name)
  • Backcompat: rewrite "rtk git status" returns the input unchanged
  • Dashboard unified — no rtk X vs contextcrawler X duplicate rows

Closes #62.

…contextcrawler X` (#62)

The Claude Code hook (`hooks/claude/rtk-rewrite.sh`) shells out to
`contextcrawler rewrite "$CMD"` and substitutes the result into Claude
Code's `updatedInput.command`. Pre-fix this returned `rtk git status`
(legacy prefix). Claude Code then attempted to exec `rtk git status`
literally, which fails with "rtk: command not found" on any system
where the binary is installed as `contextcrawler` (i.e. every system).

The bug stayed hidden in the current session because most of the
traffic flows via codex (which uses `contextcrawler X` directly per
the AGENTS.md template) rather than the Claude Code rewrite path.
Any user with raw-command Claude usage + this hook would have hit
"command not found" on every rewrite.

## Empirical confirmation (pre-fix)

```
$ echo '{"tool_input":{"command":"git status"}}' | bash hooks/claude/rtk-rewrite.sh
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow",
 "permissionDecisionReason":"ContextCrawler auto-rewrite",
 "updatedInput":{"command":"rtk git status"}}}
$ which rtk
rtk not found
```

## Empirical confirmation (post-fix)

```
$ echo '{"tool_input":{"command":"git status"}}' | bash hooks/claude/rtk-rewrite.sh
{... "updatedInput":{"command":"contextcrawler git status"}}}
```

## Scope of changes

1. **73 RULES `rtk_cmd:` values** in `src/discover/rules.rs` rebranded
   from `"rtk X"` to `"contextcrawler X"`.
2. **5 inline `format!("rtk ...")` builders** in
   `src/discover/registry.rs` (head/tail/golangci/pnpm/npm cases).
3. **`classify_command`** now treats `contextcrawler X`-prefixed input
   as already-wrapped (added `"contextcrawler "` to IGNORED_PREFIXES).
   The legacy `"rtk "` entry stays for backcompat with historical hook
   captures.
4. **`rewrite_segment_inner` + `rewrite_command`** prefix-detect checks
   accept BOTH `contextcrawler ` and `rtk ` for backcompat.
5. **54 `format!("rtk ...")` tracking labels** across 17 cmd modules
   migrated to `format!("contextcrawler ...")`.
6. **53 plain-literal `"rtk X"` tracking labels** across 19 files
   migrated to `"contextcrawler X"`.
7. **2 inline log/track strings** in main.rs (`"rtk:toml ..."`,
   `"rtk grep (format-flag passthrough...)"`).
8. **`src/hooks/init.rs::show_claude_config`** + `show_cursor_config`
   hook-content detection: accept both legacy `rtk rewrite` and
   current `contextcrawler rewrite` markers, and both
   `command -v rtk` / `command -v contextcrawler` guards.
9. **`src/analytics/gain.rs::display_cmd`**: strips BOTH prefixes
   so historical `rtk X` rows + new `contextcrawler X` rows bucket
   together in the dashboard.

## What stays `rtk` (deliberate)

- `LEGACY_CLAUDE_HOOK_COMMAND = "rtk hook claude"` / cursor — the
  legacy-detection constants wired in PR #64.
- `IGNORED_PREFIXES` includes both `"rtk "` and `"contextcrawler "`
  so the rewriter doesn't double-wrap either form.
- `RtkRule` / `RtkStatus` / `rtk_cmd` field names and the SQLite
  `rtk_cmd` column NAME — internal identifiers, not user-visible
  values.
- `// branding-lint: allow legacy` markers retained where present.

## Migration / tracking-label transition

`gain.rs::display_cmd` now strips both `"rtk "` and `"contextcrawler "`
prefixes at display time. Historical rows in `~/Library/Application
Support/rtk/history.db` continue to bucket correctly with new rows in
the dashboard. No data migration required.

## Test churn

~180 test assertion strings rebranded across registry.rs +
hook_cmd.rs test mods. All done via scoped Python replacement inside
each file's `#[cfg(test)]` block to avoid touching production literals.

## Verified

- cargo build clean: 0 warnings
- cargo test --bin contextcrawler: 2119 pass / 0 fail
- All 10 integration suites green
- Empirical end-to-end:
  - `contextcrawler rewrite "git status"` -> `contextcrawler git status`
  - hook returns `{"updatedInput":{"command":"contextcrawler git status"}}`
  - `contextcrawler rewrite "rtk git status"` -> `rtk git status`
    (backcompat: legacy already-wrapped input passes through)
  - `contextcrawler rewrite "contextcrawler git status"` -> `contextcrawler
    git status` (new already-wrapped passes through)
  - `contextcrawler rewrite "htop"` -> empty + exit 1 (unsupported
    unchanged)
  - dashboard shows unified per-command rows (no rtk/contextcrawler
    duplicates)

Closes #62.
@thehoff
thehoff merged commit 0dbac79 into develop May 18, 2026
3 checks passed
@thehoff
thehoff deleted the fix/rewrite-command-prefix-62 branch May 18, 2026 14:37
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
Manual version bump. 14 PRs merged since v0.1.8 cut at tag 1e967af.

Headline: fix(thehoff#62) the Claude Code hook returned `rtk git status` for
every rewrite but the binary is `contextcrawler` -- exec failed with
"command not found" on every user with raw-command Claude usage +
the hook installed. Fixed in PR thehoff#72; backcompat preserved for
historical `rtk X` already-wrapped inputs.

See GH release v0.1.9 for the full PR list + notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scope: standardise rewrite_command output prefix ( vs )

1 participant