Claude Code hook misses rtk-eligible commands inside compound invocations (pipes, && chains)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 81k
- Forks
- 5.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 35
Description
Summary
The Claude Code hook (rtk hook claude) rewrites simple Bash commands to their rtk equivalents, but commands embedded in compound invocations — && chains, pipelines, redirects — pass through unrewritten even when rtk already handles them. Over a real 30-day window this accounted for ~43.8K tokens of missed savings in one project.
Environment
- rtk 0.42.4 (Homebrew, macOS / Darwin 25.5.0)
- Claude Code with
rtk hook claudewired as aPreToolUseBash hook
Evidence (rtk discover output)
Scanned: 10 sessions (last 30 days), 941 Bash commands
Already using RTK: 489 commands (52.0%)
MISSED SAVINGS -- Commands RTK already handles
Command Count RTK Equivalent Est. Savings
grep -n 90 rtk grep ~19.6K tokens
head -60 32 rtk read ~6.9K tokens
gh issue 27 rtk gh ~6.3K tokens
git status 40 rtk git ~4.5K tokens
ls bin/ 30 rtk ls ~3.6K tokens
wc -c 15 rtk wc ~1.0K tokens
curl -s 4 rtk curl ~876 tokens
diff -q 3 rtk diff ~536 tokens
find ... 7 rtk find ~357 tokens
Total: 248 commands -> ~43.8K tokens saveable
Spot-checking the session transcripts, nearly all of these misses were inside compound commands, e.g.:
grep -n "pattern" file.py | head -20
git status --short && git log --oneline -5
some-tool --json 2>&1 | head -60
The standalone forms of the same commands are rewritten correctly.
Why this is plausibly intentional (and a suggestion anyway)
Rewriting inside a pipeline can change semantics (e.g. a downstream parser expecting exact upstream output), so skipping compound commands is a defensible safety default. Two ideas that might capture most of the value without that risk:
- Rewrite only the safe positions: the first command of an
&&/;chain, or the head of a pipeline when the rtk equivalent is output-compatible for piping. - Opt-in flag (e.g.
rtk hook claude --compound) for users willing to accept the trade-off, keeping the conservative default.
Even handling just the leading command of && chains would have covered a large share of the 248 misses above.
Happy to provide fuller rtk discover --history data if useful. Thanks for the tool — the 52% that is covered is already saving real money.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the rtk hook claude entry point and reproduce the standalone and compound Bash examples from the issue. Trace how && chains, pipelines, redirects, and the conservative default are handled, then define and verify the selected safe or opt-in behavior against the missed-command cases described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100