[grep] reduce fallbacks for common flag combinations (-rn, -l, -A/-B/-C, -E, -o, -c)
#1,833 opened on May 11, 2026
Repository metrics
- Stars
- (48,085 stars)
- PR merge metrics
- (Avg merge 11d 1h) (45 merged PRs in 30d)
Description
Observation
On a 30-day Claude Code history (~13.5k tracked commands), rtk grep filters
99 % of token volume in the calls it accepts (22.5M saved / 22.8M input).
However, 2327 additional grep calls fall through rtk fallback: grep …
where no filter runs and RTK cannot even measure the bypassed token volume.
Top fallback triggers
| Flag | Calls | Why it should be handled |
|---|---|---|
-rn |
748 | Already implicitly supported (rg is recursive + line-numbered); just parse the combined flag |
-r |
563 | Same as above |
-l |
248 | rg --files-with-matches |
-A/-B/-C N |
212 | Already exposed as --context-only but with different semantics; map directly to rg's -A/-B/-C |
-n |
198 | Line numbers are always on — accept the flag as a no-op |
-E |
140 | rg uses regex by default — accept as a no-op |
-o |
79 | rg -o |
-i/-in |
86 | rg -i |
-c |
27 | rg -c |
Note: -r/-rn/-n without -E must be mapped to rg -F to preserve
GNU-grep's literal-string semantics (otherwise patterns containing ., *,
etc. would be silently re-interpreted as regex).
Suggested approach
Extend the rtk grep argument parser to recognise these common GNU-grep
flags and forward them to the ripgrep backend rather than dropping to the
unfiltered fallback. For flags that are no-ops under ripgrep (-n, -E),
silently accept them. The -F injection rule above should kick in
automatically when -E is absent.