rtk-ai/rtk

[grep] reduce fallbacks for common flag combinations (-rn, -l, -A/-B/-C, -E, -o, -c)

Open

#1833 aperta il 11 mag 2026

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)Rust (2914 fork)batch import
area:clienhancementhelp wantedpriority:medium

Metriche repository

Star
 (48.085 star)
Metriche merge PR
 (Merge medio 11g 1h) (45 PR mergiate in 30 g)

Descrizione

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.

Guida contributor