Skip to content

Claude Code native tools bypass RTK hook — majority of token-heavy ops never reach Bash #538

Open

Description

@roman-rr

Problem

RTK's Claude Code hook intercepts only the Bash tool, but Claude Code has built-in native tools (Read, Grep, Glob, Edit, Write) that handle the majority of file and search operations without ever touching Bash.

Claude Code's system prompt explicitly instructs:

"Do NOT use the Bash to run commands when a relevant dedicated tool is provided."

  • Read files → Read tool (not cat/head/tail)
  • Search content → Grep tool (not grep/rg)
  • Find files → Glob tool (not find/ls)
  • Edit files → Edit tool (not sed/awk)

This means ~60% of the commands RTK is designed to compress (cat, grep, find, ls) never reach the Bash tool and are invisible to the RTK hook.

Evidence

On a real system with RTK 0.28.2 properly installed (hook v2, settings.json configured, RTK.md referenced):

  • rtk discover reports 6,302 Bash commands in 7 days and claims 248K tokens saveable
  • But rtk gain shows only 4 commands ever processed by RTK
  • The hook was installed and working correctly — the gap is because rtk discover scans Claude's JSONL logs and cannot distinguish between Bash tool calls and native tool calls, so it overestimates saveable tokens

Architecture mismatch

Claude Code Tool Routing:
┌─────────────┐
│  Read tool   │──→ direct file read (no Bash, no hook, no RTK)
│  Grep tool   │──→ direct ripgrep  (no Bash, no hook, no RTK)
│  Glob tool   │──→ direct glob     (no Bash, no hook, no RTK)
│  Edit tool   │──→ direct edit     (no Bash, no hook, no RTK)
│  Bash tool   │──→ hook fires ──→ RTK rewrites ✅
└─────────────┘

Impact

  • RTK's headline claim of "80% savings across ~118K tokens per session" is significantly overstated for Claude Code users
  • rtk discover gives misleading savings estimates because it counts native tool usage as "missed Bash commands"
  • Users install RTK expecting large savings but see minimal impact, leading to confusion

What RTK still helps with (Bash-only commands)

  • git operations (status, diff, log, add, commit, push)
  • gh CLI (pr, issue, run)
  • npm run build/test, cargo test/build
  • docker commands
  • curl, ssh

These are real savings, but a fraction of the advertised total.

Suggestions

  1. rtk discover accuracy: Filter out or flag commands that likely used native tools (Read/Grep/Glob) rather than Bash, so savings estimates are realistic
  2. Hook non-Bash tools: Investigate intercepting Read, Grep, Glob tool calls via the PreToolUse hook to compress their outputs (different matcher + updatedInput schema)
  3. Documentation: Clarify that Claude Code's native tools bypass RTK, and set realistic expectations for savings (git/gh/build/test commands only)
  4. rtk gain context: Show estimated "reachable" vs "unreachable" commands so users understand why savings are lower than rtk discover suggests

Environment

  • RTK 0.28.2 (Homebrew, macOS)
  • Claude Code with Opus model
  • Hook v2 (thin delegator), correctly installed and verified working

Activity

  1. roman-rr commented on Mar 12, 2026

    @roman-rr
    Author

    README savings table is misleading for Claude Code

    The README's "Token Savings (30-min Claude Code Session)" table claims ~118K → ~24K tokens (80% savings), but the top 3 rows — which account for 45% of claimed savings — never go through Bash in Claude Code:

    README Row Claimed Freq Claimed Savings Claude Code Reality
    cat / read 20x 28,000 tokens Uses Read tool, not cat — RTK never sees it
    grep / rg 8x 12,800 tokens Uses Grep tool, not grep — RTK never sees it
    ls / tree 10x 1,600 tokens Uses Glob tool, not ls — RTK never sees it
    Subtotal 42,400 (45% of total) 0 tokens saved

    Claude Code's system prompt explicitly instructs the model to use native tools over Bash:

    "Do NOT use the Bash to run commands when a relevant dedicated tool is provided: Read instead of cat, Grep instead of grep, Glob instead of find/ls, Edit instead of sed"

    Realistic savings estimate

    Operation Goes through Bash? Realistic Savings
    cat / read No (Read tool) 0
    grep / rg No (Grep tool) 0
    ls / tree No (Glob tool) 0
    git status/diff/log (20x) Yes ~4,600
    git add/commit/push (8x) Yes ~1,480
    npm test / cargo test (5x) Yes ~22,500
    ruff/pytest/go test (10x) Yes ~1,400
    docker ps (3x) Yes ~720
    Total ~30K saved (~25%)

    RTK genuinely helps with git/gh/test/build/docker — but the headline "80% savings, 118K → 24K" is benchmarked against an agent that uses raw cat/grep/ls via Bash, which isn't how Claude Code works.

    Suggestion

    Consider either:

    1. Renaming the table to "Token Savings (generic AI agent session)" and adding a separate Claude Code-specific table
    2. Adding a note that Claude Code uses native tools for file ops, so real-world savings are lower
    3. Showing a range: "25-80% savings depending on agent architecture"
  2. added
    enhancement
    on Mar 12, 2026
  3. added
    effort-large
    and removed
    enhancement
    effort-large
    on Mar 20, 2026
  4. pszymkowiak commented on Mar 24, 2026

    @pszymkowiak
    Collaborator

    The discover module only counts Bash tool_use blocks (filters on "Bash" in the JSONL). Native tools (Read, Grep, Glob) are not counted.

    The gap between discover (6302 commands) and gain (4 commands) is likely a hook issue — several users reported hooks not firing correctly between v0.25-v0.28 (see #260, #361). The hook has been significantly improved since then.

    Could you try:

    1. Upgrade to latest: brew upgrade rtk or curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
    2. Reinstall hook: rtk init -g --auto-patch
    3. Verify: rtk init --show (should show [ok] for hook + settings)
    4. Run a few commands in Claude Code, then compare rtk gain vs rtk discover

    If gain still shows 0 after the upgrade, please share the output of rtk init --show.

    Thanks!

  5. roman-rr commented on Mar 24, 2026

    @roman-rr
    Author

    Lets measure. Today my stats, as following.

    romanrr@Romans-MacBook-Pro-Max aelita % rtk gain
    RTK Token Savings (Global Scope)
    ════════════════════════════════════════════════════════════
    
    Total commands:    557
    Input tokens:      2.0M
    Output tokens:     730.1K
    Tokens saved:      1.3M (64.1%)
    Total exec time:   47m29s (avg 5.1s)
    Efficiency meter: ███████████████░░░░░░░░░ 64.1%
    
    By Command
    ────────────────────────────────────────────────────────────────────────
      #  Command                   Count   Saved    Avg%    Time  Impact    
    ────────────────────────────────────────────────────────────────────────
     1.  rtk git show 26940ff          1  180.2K   97.0%    98ms  ██████████
     2.  rtk git show 9229901          1  166.6K   97.5%    61ms  █████████░
     3.  rtk git show c044c7a          1  127.3K   84.5%    70ms  ███████░░░
     4.  rtk git show 77a2f9e          1   90.3K   94.0%    76ms  █████░░░░░
     5.  rtk curl -s -X POST h...      2   89.4K   59.0%   12.3s  █████░░░░░
     6.  rtk curl -s -X POST h...      1   83.8K   92.6%    5.7s  █████░░░░░
     7.  rtk read                     57   74.3K    6.6%     0ms  ████░░░░░░
     8.  rtk git show 0c62aac          1   72.8K   93.0%    79ms  ████░░░░░░
     9.  rtk grep                     28   71.9K   26.2%     4ms  ████░░░░░░
    10.  rtk git show 55084ab          1   68.9K   91.4%    59ms  ████░░░░░░
    ────────────────────────────────────────────────────────────────────────
    
    romanrr@Romans-MacBook-Pro-Max something % rtk discover
    RTK Discover -- Savings Opportunities
    ====================================================
    Scanned: 581 sessions (last 30 days), 14648 Bash commands
    Already using RTK: 34 commands (0%)
    
    MISSED SAVINGS -- Commands RTK already handles
    ------------------------------------------------------------------------
    Command                  Count    RTK Equivalent     Status        Est. Savings
    git add                   2532    rtk git            existing      ~307.7K tokens
    grep -n                    540    rtk grep           existing      ~110.4K tokens
    gh run                     444    rtk gh             existing      ~86.3K tokens
    tail -5                    239    rtk read           existing      ~75.8K tokens
    find /Users/romanrr/D..    213    rtk find           existing      ~43.8K tokens
    curl -s                    108    rtk curl           existing      ~29.7K tokens
    npm run                    154    rtk npm            existing      ~16.9K tokens
    ls -la                     246    rtk ls             existing      ~16.6K tokens
    docker buildx               76    rtk docker         existing      ~8.2K tokens
    npx tsc                     75    rtk tsc            existing      ~6.4K tokens
    npx vite                    31    rtk npx            existing      ~4.4K tokens
    npx next                    11    rtk next           existing      ~3.0K tokens
    rsync -avz                   3    rtk rsync          existing      ~244 tokens
    du -sh                       4    rtk du             existing      ~45 tokens
    diff -rq                     1    rtk diff           existing      ~4 tokens
    ------------------------------------------------------------------------
    Total: 4678 commands -> ~709.5K tokens saveable
    
    TOP UNHANDLED COMMANDS -- open an issue?
    ----------------------------------------------------
    Command                  Count    Example
    ssh                       4446    ssh -i ~/.ssh/id_ed25519_something roman@..
    node                       708    node --check src/routes/signals/adminA..
    git checkout               185    git checkout -b agent/remove-batching-..
    })                         110    })
    cat                        108    cat <<'LOCALEOF' > /tmp/avnt_investiga..
    deploy.sh                   96    ./scripts/deploy.sh --both
    print(json.load(sys.s..     92    print(json.load(sys.stdin).get('status..
    git merge                   77    git merge agent/remove-batching-expand..
    scp                         76    scp -i ~/.ssh/id_ed25519_something roman@..
    \""                         66    \""
    await                       55    await mongoose.connect(process.env.MON..
    process.exit(0)             54    process.exit(0)
    \"" 2>&1                    48    \"" 2>&1
    process.exit(1)             40    process.exit(1)
    \" 2>&1"                    32    \" 2>&1"
    ----------------------------------------------------
    -> github.com/rtk-ai/rtk/issues
    
    ~estimated from tool_result output sizes
    romanrr@Romans-MacBook-Pro-Max something % 

    I'll post once again after 1-2 weeks.

  6. roman-rr commented on Apr 2, 2026

    @roman-rr
    Author

    After a week @pszymkowiak so its obviously advantage, but only from read command ?!

    romanrr@Romans-MacBook-Pro-Max aelita % rtk gain
    RTK Token Savings (Global Scope)
    ════════════════════════════════════════════════════════════
    
    Total commands:    852
    Input tokens:      37.0M
    Output tokens:     755.5K
    Tokens saved:      36.3M (98.0%)
    Total exec time:   59m42s (avg 4.2s)
    Efficiency meter: ████████████████████████ 98.0%
    
    By Command
    ────────────────────────────────────────────────────────────────────────
      #  Command                   Count   Saved    Avg%    Time  Impact    
    ────────────────────────────────────────────────────────────────────────
     1.  rtk read                     79   34.9M    9.8%     1ms  ██████████
     2.  rtk git show 26940ff          1  180.2K   97.0%    98ms  ░░░░░░░░░░
     3.  rtk git show 9229901          1  166.6K   97.5%    61ms  ░░░░░░░░░░
     4.  rtk git show c044c7a          1  127.3K   84.5%    70ms  ░░░░░░░░░░
     5.  rtk git show 77a2f9e          1   90.3K   94.0%    76ms  ░░░░░░░░░░
     6.  rtk curl -s -X POST h...      2   89.4K   59.0%   12.3s  ░░░░░░░░░░
     7.  rtk curl -s -X POST h...      1   83.8K   92.6%    5.7s  ░░░░░░░░░░
     8.  rtk grep                     35   76.0K   25.2%     9ms  ░░░░░░░░░░
     9.  rtk git show 0c62aac          1   72.8K   93.0%    79ms  ░░░░░░░░░░
    10.  rtk git show 55084ab          1   68.9K   91.4%    59ms  ░░░░░░░░░░
    ────────────────────────────────────────────────────────────────────────
    
    romanrr@Romans-MacBook-Pro-Max aelita % rtk discover
    RTK Discover -- Savings Opportunities
    ====================================================
    Scanned: 964 sessions (last 30 days), 19095 Bash commands
    Already using RTK: 34 commands (0%)
    
    MISSED SAVINGS -- Commands RTK already handles
    ------------------------------------------------------------------------
    Command                  Count    RTK Equivalent     Status        Est. Savings
    git add                   3497    rtk git            existing      ~415.1K tokens
    grep -n                    816    rtk grep           existing      ~173.6K tokens
    tail -5                    306    rtk read           existing      ~104.6K tokens
    gh run                     444    rtk gh             existing      ~86.3K tokens
    find /Users/romanrr/D..    170    rtk find           existing      ~43.9K tokens
    curl -s                    153    rtk curl           existing      ~41.6K tokens
    ls -la                     449    rtk ls             existing      ~30.7K tokens
    npm run                    196    rtk npm            existing      ~22.2K tokens
    npx vite                   261    rtk npx            existing      ~22.0K tokens
    npx tsc                    115    rtk tsc            existing      ~9.8K tokens
    npx next                    13    rtk next           existing      ~3.4K tokens
    docker run                  13    rtk docker         existing      ~1.4K tokens
    rsync -avz                  48    rtk rsync          existing      ~1.2K tokens
    diff /tmp/landing-v1-..      2    rtk diff           existing      ~317 tokens
    pip3 install                 2    rtk pip            existing      ~110 tokens
    ------------------------------------------------------------------------
    Total: 6489 commands -> ~956.4K tokens saveable
    
    TOP UNHANDLED COMMANDS -- open an issue?
    ----------------------------------------------------
    Command                  Count    Example
    ssh                       5268    ssh -i ~/.ssh/id_ed25519 roman@..
    node                       822    node --check src/routes/signals/adminA..
    git checkout               276    git checkout -b agent/sonar-cache-opti..
    cat                        164    cat <<'LOCALEOF' > /tmp/avnt_investiga..
    scp                        156    scp -i ~/.ssh/id_ed25519 -r /Us..
    print(json.load(sys.s..    146    print(json.load(sys.stdin).get('status..
    })                         120    })
    git merge                  109    git merge agent/sonar-cache-optimizati..
    deploy.sh                   74    ./scripts/deploy.sh --both
    \""                         69    \""
    await                       65    await mongoose.connect(process.env.MON..
    process.exit(0)             56    process.exit(0)
    \"" 2>&1                    53    \"" 2>&1
    process.exit(1)             46    process.exit(1)
    # Check                     37    # Check the 159KB files - they're all ..
    ----------------------------------------------------
    -> github.com/rtk-ai/rtk/issues
    
    ~estimated from tool_result output sizes
    
  7. added
    bug
    effort-large
    enhancement
    on Apr 12, 2026
  8. pszymkowiak commented on Apr 12, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 72%

    Summary

    RTK's Bash-only hook misses Claude Code's native tools (Read/Grep/Glob/Edit), causing rtk discover to overstate potential savings — fix requires analytics filtering and/or extending hook coverage to PreToolUse native tools

    📁 Relevant files
    • src/discover.rs
    • src/hook.rs
    • src/analytics.rs
    • docs/claude-code.md

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

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:clibugeffort-largeenhancementhelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions