Skip to content

Possible false negatives when using rtk rg #2806

Closed

Description

@mrctito

Title

Possible false negatives when using rtk rg

Description

Hi, first of all, thanks for building RTK. I have been trying it with Claude Code and the token reduction idea is very useful.

I noticed a possible issue with rg/ripgrep when executed through RTK. I am not yet sure if this is a bug, a limitation, or something specific to my setup, but I wanted to report it because it can affect code-search reliability.

In one Claude Code Fable 5 session, the assistant reported that an RTK-wrapped rg search returned no matches for strings that were later confirmed to exist in the repository.

The relevant Claude Code messages were:

The rtk wrapper interfered with some searches. Let me load the dedicated Grep/Glob tools for reliable results.

Grep/Glob aren't available as tools. Let me use raw ripgrep via rtk proxy to avoid wrapper interference.

Then later:

The rtk-wrapped rg gave FALSE NEGATIVES — output_subagent and generative_ui_dashboard clearly exist (deepagent.py:287, :251) but rg returned empty. This is exactly the false-negative trap. I must not trust that tool for absence claims. Let me use plain grep and verify it actually finds known-present strings.

And after switching to plain grep:

grep works reliably; rtk-rg is broken. I'll use grep going forward. Now let me map the full dead-stack surface and the demo YAML.

The strings involved were:

output_subagent
generative_ui_dashboard

Claude reported they existed in:

deepagent.py:287
deepagent.py:251

but the RTK-wrapped search apparently returned empty output.

Why I think this is worth checking

For most commands, summarization or aggressive compression is fine. But for search commands like rg, grep, or git grep, false negatives can be risky because coding agents often use search results to decide whether something exists, whether a legacy path was fully removed, or whether a symbol is unused.

So even if RTK compresses the output, it would be safer if search commands never silently drop matches.

Expected behavior

If the underlying rg command finds matches, rtk rg should preserve at least enough information to show that matches exist.

If the output is too large, a truncated result with an explicit marker would be safer than returning empty output, for example:

[RTK truncated output — underlying command produced more matches]

Possible commands to compare

I can try to reproduce with something like:

rg "output_subagent" .
rtk rg "output_subagent" .

rg "generative_ui_dashboard" .
rtk rg "generative_ui_dashboard" .

and also:

rg -n "output_subagent" .
rtk rg -n "output_subagent" .

rg --json "output_subagent" .
rtk rg --json "output_subagent" .

Environment

I can provide exact versions if useful:

rtk --version
rtk gain
which rtk
rg --version
grep --version
uname -a

The setup is:

Claude Code
RTK wrapper
WSL/Linux development environment
ripgrep / rg

Request

Could you please check whether RTK’s handling of rg can produce false negatives or suppress matches in some cases?

I may also be missing a recommended way to run search commands through RTK, so guidance would be welcome.

Activity

  1. pszymkowiak commented on Jul 3, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 55%

    Summary

    Reporter relays a Claude Code session claiming rtk-wrapped rg returned empty results for strings confirmed present via plain grep, suggesting possible silent false negatives in search output; no first-hand reproduction or exact command/output provided yet.


    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. nbruzzi commented on Sep 6, 2026

    @nbruzzi

    Confirming this on rtk 0.38.0 with Claude Code, and adding a precise root cause + a working config workaround.

    Reproduced: a bare rg recursive search issued through Claude Code's Bash tool returned zero matches for a string that was present in the repo the whole time. An explicit single-file rg pattern path/to/file worked fine; only recursive/directory searches failed.

    Root cause (mechanism): rtk's PreToolUse hook rewrites rg → rtk grep. rtk grep falls through to the system grep, and when handed ripgrep-style args (a directory argument without -r, --files, etc.) the underlying grep errors — e.g. grep: <dir>: Is a directory → exit 2, empty stdout. Because agents commonly append 2>/dev/null, that error is swallowed and the result is indistinguishable from a clean "no matches" — a silent false negative on absence claims. Verified via rtk's own dry-run:

    $ rtk hook check 'rg -l -i "some string" /path/to/dir'
    rtk grep -l -i "some string" /path/to/dir     # <-- rewritten; rtk grep can't do this like ripgrep
    

    The trap is that rg (ripgrep) is not flag-compatible with grep: they collide on value-taking flags (-r, -E, -m, etc.), so aliasing one to the other silently corrupts search semantics. This overlaps with #2253 and #2817 (rtk grep shells to system grep, not ripgrep).

    Workaround (not mentioned elsewhere in the thread) — exclude rg from the hook via rtk config so it runs as genuine ripgrep, while keeping the grep/ls/find proxies intact:

    # ~/Library/Application Support/rtk/config.toml (macOS)
    # ~/.config/rtk/config.toml (Linux/XDG)
    [hooks]
    exclude_commands = ["rg"]

    Verified after the change:

    $ rtk hook check 'rg -l -i "some string" /path/to/dir'
    No rewrite for: rg -l -i "some string" /path/to/dir
    $ rtk hook check 'grep -rn foo src/'
    rtk grep -rn foo src/        # grep proxy still works
    

    rg (and command rg) then pass through untouched in every position (leading, post-pipe, post-;, post-&&), and recursive searches find matches again.

    Suggested fix: rtk shouldn't alias rg → rtk grep at all — ripgrep and grep are not drop-in equivalents, and a search tool that silently returns wrong/empty results is worse than no proxy. At minimum, rg could be excluded by default, and rtk grep should not silently change recursion semantics relative to the underlying grep (a directory without -r should not silently start recursing, nor silently return empty).

  3. in-moonshadow commented on Oct 1, 2026

    @in-moonshadow

    0.50.0 fixed the rg path but regressed the grep path on directory arguments

    Following up on the false-negative class reported here. I have both 0.42.0 and 0.50.0 binaries available and measured the same inputs against both, so I can show exactly what changed.

    Short version: in 0.50.0 rg and grep were split onto separate paths. The new rtk rg path behaves correctly. The old rtk grep path lost directory-recursion — it now fails on any directory argument, where 0.42.0 recursed. This is still #3611, not a new rewrite bug, so I am not reopening that part; the useful new datum is the regression plus the fact that the two paths no longer agree.

    The rewrite table changed between the two versions

    $ rtk --version                                # 0.42.0
    $ rtk --version                                # 0.50.0
    rtk 0.50.0
    
    $ rtk rewrite 'rg -n PAT .'
    # 0.42.0 ->  rtk grep -n PAT .
    # 0.50.0 ->  rtk rg -n PAT .        <- new, separate subcommand
    
    $ rtk rewrite 'grep -n PAT .'
    # both  ->  rtk grep -n PAT .

    rtk rg is new in 0.50.0 (--help: "Compact ripgrep - runs rg natively, same output filter as grep"). strace confirms it execs the real binary:

    execve("/usr/bin/rg", ["/usr/bin/rg","-n","--with-filename","--null","-n","-e","PAT","--","."])
    

    The regression: rtk grep on a directory now fails

    $ rtk grep -n PAT .
    # 0.42.0:  6 matches in 6 files: ...        (recursed)
    # 0.50.0:  /usr/bin/grep: .: Is a directory
    #          exit=2

    Exit 2, zero matches reported. Full form matrix, same file tree, both versions:

    invocation 0.42.0 0.50.0
    rtk grep -n PAT . recursed, 6 matches Is a directory, exit=2
    rtk grep -n PAT ./ recursed Is a directory, exit=2
    rtk grep -rn PAT . recursed recursed
    rtk grep -n PAT a.txt ok ok
    rtk grep -n PAT *.txt ok ok

    So rtk grep now requires an explicit -r for directories. That is not wrong on its own — GNU grep 3.7 also does not recurse on a bare directory — but it is a regression from 0.42.0, and it interacts badly with the rewrite: grep -rn survives (the user's own -r is preserved as rtk grep -rn), while grep -n PAT <dir> is rewritten to a form that cannot work.

    Both paths were inconsistent in 0.42.0; only one got fixed

    The inconsistency behind the grep -c false negative reported on this thread is the same in both versions on the grep side — -c/-l/-L/-o/-Z take a raw path that does not add -r, while -n took a filtered path that implied recursion:

    0.42.0 0.50.0
    rtk grep -c PAT . 0 + Is a directory 0 + Is a directory, exit=2
    rtk grep -rc PAT . correct correct
    rtk grep -n PAT . recursed now fails too
    rtk rg -c PAT . did not exist correct
    rtk rg -l PAT . did not exist correct

    Ground truth for the tree: /usr/bin/rg -c PAT . returns 2 matching files with 1 hit each.

    Why the 0 is the dangerous part

    rtk grep -c returns a clean 0. 0 is a plausible answer to "how many matches?", and it is what the caller receives whether the true count is zero or the search never ran. GNU grep's "Is a directory" text goes to stderr and is lost when stdout is captured or piped. There is no formatting tell and no distinct exit code in the -c case (it is 0), so for the "is there residue / did this file change" class of check this reads as a clean bill of health.

    Worth noting rtk proxy does not help here — it is not an output-filtering problem:

    $ rtk proxy grep -c PAT .
    0
    /usr/bin/grep: .: Is a directory

    The natural instinct is to bypass the wrapper, so this seems worth stating explicitly.

    Ripgrep semantics restored on the rg path

    For completeness on #2606's point about losing ripgrep's skip behaviour — that no longer applies to rg in 0.50.0:

    $ rtk rg -n PAT .    # honours .gitignore, skips hidden dirs
    $ rtk grep -n PAT .  # (fails on the directory)

    RTK_DISABLED=1 does not disable the rewrite

    $ RTK_DISABLED=1 rtk rewrite 'rg -n PAT .'
    rtk grep -n PAT .

    Still rewritten. Only an absolute path (/usr/bin/rg ..., which the rewrite table does not match) or rtk proxy bypass it. Mentioning it because the env var reads like it should be the escape hatch.

    Not reported here (still present, adjacent)

    rtk rg -r is ripgrep's --replace, and rtk rg -h prints help — both differ from the grep flags of the same name, and rtk rg -r returns empty with a success-looking exit rather than erroring. Separate from the above, but the same "silently different semantics" family, so noting it for completeness.

    Environment

    • rtk 0.50.0 (compared against 0.42.0, both local)
    • Linux 6.8.0 x86_64, GNU grep 3.7, ripgrep 13.0.0 at /usr/bin/rg
    • Claude Code hook: PreToolUse → matcher Bash → rtk hook claude

    Happy to test a nightly or a specific build if that is more useful than the released 0.50.0.

    Reported by @in-moonshadow — measurements reproducible with rtk 0.42.0 and 0.50.0 on Linux x86_64.

  4. KuSh commented on Oct 3, 2026

    @KuSh
    Collaborator

    Fixed by #2641, shipped in v0.43.0: rg commands are now rewritten to rtk rg, which runs the real ripgrep instead of falling back to grep, so recursive and directory searches return their matches again. If you still see missing matches with rtk rg on the latest release, please comment with the exact command and we will reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions