-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Context
The recommended Claude Code hook blindly prefixes find and grep/rg commands with rtk, which breaks in many common cases (relates to #204, #229).
find — syntax mismatch
rtk find has a completely different syntax than GNU find:
- GNU:
find <path> <predicates>(e.g.,find . -not -path '*/.git/*' -name '*.pdf') - RTK:
rtk find <PATTERN> [PATH] [--max N] [-t f|d]
The hook rewrites find . -not -path ... | head -n 500 → rtk find . -not -path ... | head -n 500, which fails because:
- RTK's Clap parser doesn't know
-not,-path,-type,-exec, etc. - The argument order is reversed (pattern vs path)
- Piped commands like
| head -nget their flags parsed by Clap (the-nerror fromfindandgrepcommands fail (unexpected argument '-n' found) #204)
grep — Clap intercepts rg flags
rtk grep declares extra_args: Vec<String> with trailing_var_arg = true, but Clap still intercepts short flags like -i, -r, -n, -A etc. before reaching the trailing var arg. This means:
rtk grep -i "pattern" .→error: unexpected argument '-i' foundrtk grep -rn "pattern" .→error: unexpected argument '-n' found(grep: unexpecter argument #229)
The only way to pass rg flags is AFTER the positionals: rtk grep "pattern" path -- -i
Workaround: smart hook translation
We wrote a hook that properly translates instead of blindly prefixing:
find — syntax translation with safety guards
# Detect unsupported find features using case patterns
FIND_UNSUPPORTED=false
case "$MATCH_CMD" in
*-exec*|*-delete*|*-print0*|*-newer*|*-mtime*|*-not*|*'!'*) FIND_UNSUPPORTED=true ;;
*-maxdepth*|*-mindepth*|*-path*|*'|'*|*'&&'*) FIND_UNSUPPORTED=true ;;
esac
# Only translate simple: find <path> -name <pattern> [-type f|d]
# Complex cases pass through to native find
if [ "$FIND_UNSUPPORTED" = false ]; then
# Translate: find . -name "*.pdf" -type f → rtk find *.pdf . -t f
FIND_PATH=<extracted>
FIND_PATTERN=<extracted>
REWRITTEN="rtk find ${FIND_PATTERN} ${FIND_PATH}"
figrep — flag reorganization
# Parse args, separate RTK-known flags from rg-passthrough flags
# Strip -r/-R/-n/--recursive (redundant: rtk grep is recursive + line-numbered)
# Map --type → -t (RTK's Clap flag)
# Move unknown flags (like -i, -w, -A 3) after positionals with -- separator
# Result: grep -rn -i -A 3 "pattern" src/ → rtk grep "pattern" src/ -- -i -A 3Suggestions for RTK
find: Consider either addingexternal_subcommand/ passthrough fallback (like PR feat: passthrough fallback when Clap parse fails #200 suggests), or documenting that the hook should translate syntax rather than prefixgrep: Thetrailing_var_argonextra_argsdoesn't work as expected — Clap intercepts short flags before they reachextra_args. Consider usingallow_hyphen_values = trueonextra_args, or moving to a--separator approach in the Clap definition- Hook template: The default hook in the README should handle these edge cases — happy to contribute the full working hook if helpful
Environment
- RTK: installed via Homebrew
- OS: macOS (Darwin 24.6.0)
- Claude Code hook (PreToolUse:Bash)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels