Repository navigation
fix(rewrite): migrate rewrite_command output prefix rtk X -> contextcrawler X (#62) - #72
Merged
Merged
Conversation
…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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #62.
rewrite_commandwas returning"rtk git status"for every rewrite, but the binary iscontextcrawler— Claude Code's hook substitutes the rewritten command intoupdatedInput.commandand tried to exec the non-existentrtkbinary. The bug stayed hidden because most session traffic flows via codex (which callscontextcrawler Xdirectly per AGENTS.md template).Empirical fix
Pre:
{"updatedInput":{"command":"rtk git status"}}→ command-not-foundPost:
{"updatedInput":{"command":"contextcrawler git status"}}→ executesChanges
rtk_cmd:values + 5 inlineformat!builders rebrandedclassify_commandacceptscontextcrawler Xas already-wrapped (added to IGNORED_PREFIXES alongside existingrtk)rewrite_segment_inner+rewrite_commandaccept BOTH prefixes for backcompatformat!("rtk ...")+ 53 plain-literal tracking labels across 36 cmd modules migratedinit.rshook-content detection accepts bothrtk rewrite/contextcrawler rewriteguardsgain.rs::display_cmdstrips both prefixes so historical + new rows bucket together#[cfg(test)]blocks (scoped Python; never touched production literals)Stays
rtkdeliberatelyLEGACY_*_HOOK_COMMANDconstants (legacy hook detection from chore(cleanup): delete 6 orphan modules + wire legacy hook constants (zero cargo warnings) #64)IGNORED_PREFIXESkeeps"rtk "so legacy already-wrapped input passes through unchangedRtkRule/RtkStatus/rtk_cmdfield names + SQLite column NAME (internal identifiers)Migration
None required.
gain.rs::display_cmdstrips both prefixes, so historical rows inhistory.dbcontinue bucketing correctly with new rows.Verified
contextcrawler X(the actual binary name)rewrite "rtk git status"returns the input unchangedrtk Xvscontextcrawler Xduplicate rowsCloses #62.