rtk-ai/rtk

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

Open

#1,833 创建于 2026年5月11日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Rust (2,914 fork)batch import
area:clienhancementhelp wantedpriority:medium

仓库指标

Star
 (48,085 star)
PR 合并指标
 (平均合并 11天 1小时) (30 天内合并 45 个 PR)

描述

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.

贡献者指南