-
Notifications
You must be signed in to change notification settings - Fork 84
Closed
Labels
P2-importantDevrait être fixé bientôtDevrait être fixé bientôtbugSomething isn't workingSomething isn't workingeffort-medium1-2 jours, quelques fichiers1-2 jours, quelques fichiers
Description
Problem
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:
CHAIN_PREFIX=""
FINAL_CMD="$CMD"
if [[ "$CMD" == *" && "* ]]; then
CHAIN_PREFIX="${CMD% && *} && "
FINAL_CMD="${CMD##* && }"
elif [[ "$CMD" == *" ; "* ]]; then
CHAIN_PREFIX="${CMD% ; *} ; "
FINAL_CMD="${CMD##* ; }"
fi
# ... match/rewrite against FINAL_CMD ...
# Reassemble
if [ -n "$CHAIN_PREFIX" ]; then
REWRITTEN="${CHAIN_PREFIX}${REWRITTEN}"
fiThis uses bash parameter expansion (no regex issues with && in =~).
Environment
- rtk 0.15.3
- macOS (Tahoe)
- Claude Code CLI
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2-importantDevrait être fixé bientôtDevrait être fixé bientôtbugSomething isn't workingSomething isn't workingeffort-medium1-2 jours, quelques fichiers1-2 jours, quelques fichiers