Skip to content

scope: standardise rewrite_command output prefix ( vs ) #62

Closed

Description

@thehoff

Context

Caught during the branding sweep round 3 (PR for #62): rewrite_command(cmd) returns strings prefixed with rtk regardless of binary name.

Example:

$ contextcrawler rewrite "git status"
rtk git status
$ contextcrawler rewrite "head -20 file.txt"
rtk read file.txt --max-lines 20

The hook caller is the consumer of this string. If a hook tries to exec rtk git status literally, it would fail (no rtk binary). Either:

  • (a) The hook does NOT exec the rewrite output directly (uses a different translation)
  • (b) Users have rtk symlinked or aliased to contextcrawler
  • (c) There's a latent execution bug nobody's hit yet

Investigation needed

  1. Trace what consumes rewrite_command output end-to-end (hooks::hook_cmd?, the Claude Code hook script?)
  2. Determine whether the rtk prefix is intentional protocol (e.g. the hook script substitutes the binary) or accidental.
  3. If accidental: change rewrite_command to output contextcrawler X + update the ~169 test assertions. Likely also touches tracking::track() callers that store the same string in the DB (which would invalidate historical analytics).
  4. If intentional: document why with a comment block in src/discover/registry.rs.

Why filed separately

Branding sweep #62 is bounded to user-visible STRING content (help text, error prefixes, init messages). The rewrite-output prefix is a CORRECTNESS/PROTOCOL question affecting hook execution semantics, plus would force a destructive change to historical SQLite tracking labels in history.db. Deserves its own scope + plan.

Activity

  1. added
    enhancement
    on May 18, 2026
  2. thehoff commented on May 18, 2026

    @thehoff
    OwnerAuthor

    Live confirmation (2026-05-18 session)

    Empirically verified the hook substitutes the broken command:

    $ 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
    

    Claude Code's updatedInput.command becomes rtk git status and there is no rtk binary on PATH. The user has not seen errors only because most of the session's traffic goes through codex (which uses contextcrawler ... directly per the AGENTS.md template post-PR #54) and never invokes the rewrite path.

    Any raw-command Claude Code user with our hook installed would hit "rtk: command not found" on every rewrite-attempted command.

    Fix scope (refined)

    Single change in src/discover/registry.rs: replace the literal "rtk " prefix used to build rewritten command strings with "contextcrawler ". Touches:

    • The internal rewrite_command builder (the "rtk X" literals at lines 487, 758, 608, 623, 794, 2944, 2957)
    • ~169 test assertion strings (Some("rtk git status") etc. — bulk-rewrite via sed/python)
    • The rtk_cmd SQLite column NAME stays (it's a column identifier, not a value — preserves historical analytics)
    • The VALUES going INTO rtk_cmd change from "rtk git status" to "contextcrawler git status" (historical rows keep their rtk X label; new rows record under the new label — dashboard will show both bucketed separately for a transition period, eventually the rtk-prefixed bucket ages out)

    Migration note for the dashboard

    contextcrawler gain aggregates by command label. After the change:

    • Old rows aggregated as "rtk git" (legacy bucket)
    • New rows aggregated as "contextcrawler git" / displayed as just "git"

    The dashboard's bucket-stripping logic in analytics/gain.rs probably already strips the rtk prefix for display — would need to also strip contextcrawler for the new rows to land in the same bucket.

    Recommended sequence

    1. This PR: change rewrite_command output + bulk-fix the ~169 tests
    2. Follow-up: update analytics/gain.rs bucket-stripping to also recognise contextcrawler prefix so old + new rows merge
    3. Optionally: write a one-shot migration contextcrawler migrate-tracking-labels that rewrites legacy rtk X labels in the SQLite DB to contextcrawler X so the transition is clean

    Severity: medium-high for any user running the Claude Code hook with raw commands. Worth doing soon.

  3. added a commit that references this issue on May 18, 2026
  4. added a commit that references this issue on May 18, 2026
    0ff327f
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions