Skip to content

Need fix grep savings to much lower #545

Open

Description

@irfndi

Problem

rtk gain shows much lower savings for rtk grep

On my session, rtk gain reported:

  • Command: rtk grep
  • Count: 94
  • Saved: 3.3M
  • Avg%: 17.9%
Image

But the README advertises roughly -80% savings for grep / rg.

Why this is confusing

This makes it look like rtk grep underperforms badly in real usage, even though the likely issue is broader:

  • Claude Code prefers native tools like Grep, Read, and Glob
  • those native tools bypass the Bash hook
  • RTK therefore does not see or compress much of the actual search workload
  • rtk gain ends up showing a result that users can easily interpret as “grep savings are poor”

Expected behavior

One of these should happen:

  1. rtk gain / rtk discover should show “reachable vs unreachable” search activity
  2. the UI should otherwise make it clearer that this is a tooling-path limitation, not necessarily an rtk grep filter-quality problem

Actual behavior

rtk gain shows low rtk grep savings without enough context to explain why.

Environment

  • RTK version: 0.28.2
  • OS: [26.3 (25D125)
  • Agent/client: OpenCode & Codex (CLI & desktop)
  • Hook installed: yes

Activity

  1. changed the title [-]`rtk gain` makes `grep` savings look much lower[/-] [+]Need fix `grep` savings to much lower[/+] on Mar 12, 2026
  2. added
    effort-medium
    enhancement
    on Apr 12, 2026
  3. pszymkowiak commented on Apr 12, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 78%

    Summary

    Enhance rtk gain reporting to surface tooling-path limitations (native Grep/Read/Glob bypassing hook) so low grep savings aren't misread as filter-quality problems


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

  4. realityjunky commented on Aug 2, 2026

    @realityjunky

    This is still reproducible on RTK 0.42.4 (Headroom 0.33.0) and has now corrupted the aggregate twice on the same workstation.

    The second incident came from three grep -rn records in ~/.local/share/rtk/history.db:

    Command scope input_tokens output_tokens saved_tokens
    scoped recursive grep under knowledge-bases/lightrag 49,616,821 13,267 49,603,554
    grep -rn 'pyright|mypy|basedpyright' . 3,514,722,717 4,393 3,514,718,324
    scoped recursive grep under knowledge-bases/lightrag 85,465,729 1,411 85,464,318

    Together these three rows added 3,649,786,196 saved tokens. Headroom consequently reported:

    • RTK session savings: about 3.65B / 99.5%
    • all-layer savings: about 3.97B / 75.53%

    After backing up the SQLite database and deleting only those exact rows, the same live /stats endpoint reported:

    • RTK session savings: 4.84M / 21.42%
    • all-layer savings: 323.45M / 20.04%

    The earlier incident had the same signature: three recursive grep rows contributed 6,055,215,004 saved tokens. This therefore appears systematic rather than a one-off damaged row.

    The problematic value appears to be the estimated unfiltered recursive grep output, including large ignored/generated content, rather than context actually delivered to the agent. A single broad grep can dominate lifetime and downstream dashboard totals indefinitely.

    Suggested acceptance criteria:

    1. Recursive grep estimates honor configured ignored directories/files and repository ignore rules.
    2. A single command cannot contribute an unbounded multi-billion-token estimate without being marked anomalous or excluded from aggregates.
    3. RTK exposes a configurable per-command accounting cap or anomaly threshold.
    4. rtk gain and downstream consumers can distinguish measured tokens from extrapolated/estimated raw-output savings.

    I can provide additional sanitized SQLite fingerprints if useful.

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

    area:clieffort-mediumenhancementhelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions