grep -o silently discards all output and exits 0
Summary
When the Claude Code hook rewrites grep to rtk grep, any invocation using
-o / -oE returns no output at all with exit code 0. The caller
concludes "no matches" when there are matches.
This is not lossy compression — it is total, silent data loss with a success exit code. For an LLM agent (the stated target audience) this is worse than crashing: the agent acts on a false negative and never learns the output was dropped.
Environment
- rtk 0.43.0
- Windows 11 (10.0.26200), Git Bash / MINGW64, bash 5.2.37
- GNU grep 3.0
- Claude Code, hook:
PreToolUse→matcher: "Bash"→rtk hook claude
Reproduction
Any file with matches works. Using a React router file with 36 occurrences of
path="...":
# through the hook (rtk grep)
$ grep -o 'path="[^"]*"' src/App.tsx
$ echo $?
0
# same command, system binary
$ /usr/bin/grep -o 'path="[^"]*"' src/App.tsx
path="/"
path="/login"
path="/register"
...
$ /usr/bin/grep -o 'path="[^"]*"' src/App.tsx | wc -l
36
Cross-check that the matches really exist:
$ grep -c 'path=' src/App.tsx
36
So grep -c reports 36 while grep -o reports nothing.
Also reproducible with -oE. Non--o forms (-n, -c, -E) behave
correctly, so the bug looks specific to only-matching output.
rtk proxy grep -o ... also returned empty in my shell, though I did not
confirm whether the hook re-wrapped that invocation.
Impact
In one long session this cost two silent wrong conclusions. I only noticed
because a separate grep -c on the same file disagreed, and re-extracting
with Node produced 36 matches.
Suggested fix
If a flag combination isn't supported by the parser, fall back to raw passthrough rather than emitting nothing. Emitting empty output with exit 0 is indistinguishable from a legitimate "no matches".
wshm · Automated triage by AI
🔍 Automated Triage
| 🐛 Category | bug |
| 🟠 Priority | high |
| 🎯 Confidence | 95% |
Summary
rtk's grep rewrite silently drops all output and returns exit 0 for -o/-oE (only-matching mode), producing false 'no matches' results; fix by falling back to raw passthrough when the flag combination isn't supported by the parser.
This looks like a simple fix that could be auto-resolved. Repo maintainers can use
/wshm fixto attempt it.
📁 Relevant files
src/filters/grep.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
This looks fixed by #3728, shipped in v0.50.0: rtk now quotes arguments that contain double quotes so MSYS grep on Git Bash receives the pattern intact; a pattern like 'path="[^"]*"' was the one being mangled. grep -o works on Linux, but there is no Windows host available here, so marking this resolved-pending-close. Could you check grep -o with that pattern on the latest release and comment if it still prints nothing?
Fixed by #3728, shipped in v0.50.0: rtk now quotes arguments that contain double quotes, so MSYS grep on Git Bash receives a pattern like 'path="[^"]*"' intact. grep -o with that pattern prints every match on Linux with the current code; there is no Windows host here to confirm it directly. Closing this as resolved. If it still prints nothing on Windows with the latest release, please reopen.