You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hook: chained commands (cd dir && cmd) are never rewritten #112
Claude Code frequently emits chained commands like:
cd /Users/me/code/project && git status
cd /some/dir && python3 -m pytest tests/ -v
cd /foo && git add .&& git commit -m "msg"
The hook script sets FIRST_CMD="$CMD" and then matches against patterns like ^git[[:space:]]+status. Since the full command starts with cd, none of the patterns match, and the hook silently passes through.
rtk discover shows this is the dominant source of missed savings -- 271 git status, 65 tail, 81 grep, 105 ls calls missed in 30 days of usage (~84K tokens saveable).
Fix
Extract the last command segment after && or ; for pattern matching, then reassemble the full command after rewriting:
I have hooks that do this, it is actually harder than that to do correctly. You have to use an bash lexer to actually parse the commands and determine if a given chunk is actually a command or part of other commands and params. There are also edge cases like heredocs and comments and many more to get it right.
Activity
ahundt commentedon Feb 14, 2026
I have hooks that do this, it is actually harder than that to do correctly. You have to use an bash lexer to actually parse the commands and determine if a given chunk is actually a command or part of other commands and params. There are also edge cases like heredocs and comments and many more to get it right.
feat: add hybrid command engine with safe execution
ahundt commentedon Feb 15, 2026
Hey @Rmohid I've implemented this request in #131 if you can give it a try let me know what you think!
F0rty-Tw0 commentedon Feb 16, 2026
I had the same issue, and just updated my RTK hooks to catch that.
feat: add Rust-based hook engine with chained command rewriting
pszymkowiak commentedon Feb 17, 2026
Tracked in PR #156 (Hook Engine + Chained Command Rewriting).
Rmohid commentedon Feb 18, 2026
Verified fix: PR #156 adds Rust hook engine with lexer/chain parser.
cd /tmp && git statuscorrectly rewrites tocd /tmp && rtk git status. Build passes, 541 tests pass (336 in hook engine, 15 chain-specific). PR #150 also handles this case.feat: add Rust-based hook engine with chained command rewriting
feat: add Rust-based hook engine with chained command rewriting
feat: add Rust-based hook engine with chained command rewriting
feat: add hybrid command engine with safe execution
feat: add Rust-based hook engine with chained command rewriting