Repository navigation
Description
RTK v0.42.4 — Bug Report
Summary: rtk gain reports token-savings figures that are not reproducible via measured output size. The largest reported contributor (rtk read, credited with ~90M tokens saved) produces byte-identical output to the raw command (0% reduction) in controlled tests, including on 1.2 MB and 10.7 MB files. Separately, the highest-token commands (read/cat, grep, head, tail) receive 0% compression, while only small structured-output commands (ls, find, ps, env, wc) are actually compressed.
Environment
rtk 0.42.4(/home/<user>/.local/bin/rtk)- Linux (WSL2), commands run via the Claude Code Bash hook (auto-prefixing
rtk) rtk gainreported (global scope): 116 commands, "Tokens saved: 90.0M (100.0%)", top rowrtk read16 calls / 90.0M saved
Methodology
For each command we compared:
- Raw output:
rtk proxy <cmd> | wc -c - Filtered output:
rtk <cmd> | wc -c
Savings % = (raw - filtered) / raw. Correctness verified by grepping for a unique marker in filtered output (it survived → no corruption). Command counter (rtk gain → "Total commands") was checked before/after and did increment, confirming the hook is active.
Results (measured output bytes)
| Command | Raw (bytes) | Filtered (bytes) | Savings |
|---|---|---|---|
wc -l <file> |
30 | 4 | 86% ✅ |
env |
3,785 | 749 | 80% ✅ |
ls -la <dir> |
1,760 | 568 | 67% ✅ |
find <dir> -name '*.py' |
251 | 101 | 59% ✅ |
ps aux |
4,794 | 2,742 | 42% ✅ |
cat <file> / read |
6,025 | 6,025 | 0% ❌ |
read amrts.log (1.2 MB) |
1,215,833 | 1,215,833 | 0% ❌ |
read yields.json (10.7 MB) |
10,777,373 | 10,777,373 | 0% ❌ |
grep -rn def <dir> |
2,871 | 2,871 | 0% ❌ |
head -100 <log> |
9,822 | 9,822 | 0% ❌ |
tail -100 <log> |
11,516 | 11,516 | 0% ❌ |
du -ah <dir> |
623 | 623 | 0% ❌ |
df -h |
870 | 862 | ~0% ❌ |
Issue 1 — rtk gain savings appear overstated / not reproducible
rtk gain credits ~90.0M tokens saved (100%), dominated by rtk read (16 calls, 90.0M). But in controlled tests, rtk read returns output identical to the raw file at the byte level for every size tested (24 KB, 1.2 MB, 10.7 MB) → 0% actual reduction. The reported savings cannot be reproduced from output size and appear inconsistent with observed behavior. Recommend auditing how read savings are computed and what baseline gain compares against.
Issue 2 — Highest-token commands are not compressed
The commands that produce the most output — and therefore where token savings would matter most — are exactly the ones with 0% compression: read/cat, grep, head, tail. Meanwhile the commands that are compressed (ls, find, ps, env, wc) already emit small outputs, so the absolute savings are minor (e.g., 80% of 3.8 KB). Net practical token savings on real workloads (reading files, grepping code, tailing logs) appear negligible.
What works well (credit where due)
- No output corruption — a unique marker survived filtering; byte-for-byte passthrough on reads.
- Real compression on structured commands:
ls(67%),find(59%),ps(42%),env(80%),wc(86%). - Hook/tracking is active — command counter increments correctly.
Reproduction
# Compression per command (raw vs filtered)
t() { raw=$(rtk proxy "$@" 2>/dev/null | wc -c); filt=$(rtk "$@" 2>/dev/null | wc -c);
echo "$1: raw=$raw filt=$filt saved=$(( raw>0 ? (raw-filt)*100/raw : 0 ))%"; }
t cat <some_file>
t read <some_large_file> # 0% even on multi-MB files
t grep -rn def <some_dir> # 0%
t head -100 <some_log> # 0%
t ls -la <some_dir> # ~67%
t env # ~80%
t wc -l <some_file> # ~86%
# gain metric vs reality
rtk gain # note "rtk read ... saved" — compare to the 0% measured aboveSuggested priorities
- Fix/validate
rtk gainaccounting (esp. thereadsavings attribution) so reported savings match measured output reduction. - If
read/grepcompression is intended, verify it's actually engaging (it returns raw output in this build). - Consider that compressing
read/grep/tailoutput (the large ones) is where the real token wins are.
Findings gathered via controlled raw-vs-filtered byte measurements, 2026-06-30.
Activity
pszymkowiak commentedon Jul 1, 2026
🔍 Automated Triage
bughighSummary
rtk gain overstates savings with unreproducible accounting (90M tokens credited to read with 0% measured compression); read/grep/head/tail produce byte-identical output to raw, while only small structured-output commands are actually compressed
Triaged automatically by wshm · This is an automated analysis, not a human review.
thangtran7314 commentedon Jul 1, 2026
Hi, I can help with this and keep the change focused.
I looked at "
rtk gainreports unreproducible savings —read/grep/tailshow 0% compression" in rtk-ai/rtk and the scope looks suitable for a small, reviewable fix.What stood out to me: Summary: rtk gain reports token-savings figures that are not reproducible via measured output size. The largest reported contributor (rtk read, cre... / rtk 0.42.4 (/home/<user/.local/bin/rtk)
How I would approach it:
I will keep the first PR small; if the fix needs to touch more than expected, I will call that out before widening the scope.
HARUWE: Small, testable fixes with clear progress and reliable handoff.
Profile: HARUWE | @thangtran7314 (https://github.com/thangtran7314)
Estimated turnaround: same day to 24 hours.
For payment, I can follow the project bounty/payment flow after acceptance.
If you are comfortable with this plan, I can start with reproduction and a narrow PR.
Payment details can follow after assignment through the project-approved flow.
aeppling commentedon Jul 2, 2026
Hey @Co8epp most of this should be fixed since 0.43.0
Thus being said some tools like grep can sometimes produce 0 savings, because outputs are already enough compressed.
Could you please upgrade to 0.43.0 and give me your results ?
Also i'm working on #2781 which should help for more coverage as 0.44.0 lands
fix: address issue rtk-ai#2762
fix: address issue rtk-ai#2762
RichelynScott commentedon Jul 21, 2026
Independent corroboration at ~100x the sample size, plus one detail that may explain why this is hard to debug post-hoc.
Sample: 11,932 tracked commands over 5 weeks, 15+ projects, rtk 0.42.2, Linux/WSL2, Claude Code Bash hook.
1. Same pattern, same magnitude
rtk gainreports 187.8M saved (96.6%). A single row accounts for 176.1M of it: onecatof a large CSV. Excluding just that one command drops the global figure to 63.6%; excluding all >1M-token single commands drops it to 56.6%. As in your report,rtk readis credited with the overwhelming majority of all savings (184.3M of 187.8M).2. Not reproducible here either
Yet the DB has rows for that same
cat FYI.mdrecordinginput_tokens=71827, output_tokens=588 (99.2% saved).The
rtk readsavings distribution across 1,092 calls is strikingly bimodal:That top bucket — 310 calls claiming ~184M input compressed to 91K output — is where essentially all reported savings live, and it's the bucket that does not reproduce.
3. Why post-hoc diagnosis is blocked:
rtk_cmdis a constant forreadsrc/cmds/system/read.rstracks with a hardcoded label:So every
rtk readrow storesrtk_cmd = "rtk read"regardless of the flags actually used (--max-lines,--tail, filter level, etc.). The recorded invocation cannot be replayed, which makes it impossible to tell from history whether a 99% row used a filter level/flag that the bare reproduction command doesn't.Suggest, independent of the root cause: record the real argv in
rtk_cmdforread(as other handlers appear to). That alone would make this class of discrepancy diagnosable from the DB instead of requiring live re-runs against files that have since changed.4. Consequence for
rtk gainBecause savings are this concentrated (one row = 94% of the global total; one bucket = ~99% of
read's total), a mean-only report is very fragile. Worth considering forgain: outlier flagging/exclusion, a distribution view, and a "0% savings" bucket count — currently 55.3% of all 11,932 commands here saved exactly 0% and that's invisible in the headline.Yohjisakamoto commentedon Jul 22, 2026
This unreproducible savings report reinforces why end-to-end agent outcomes matter more than compressed text alone: DeepSWE found Tura cuts coding-agent rounds by 89% and total token cost by 80%; would you evaluate the methodology? https://turaai.net/docs#benchmark-current-test-set-record
negativetime commentedon Aug 10, 2026
Reproduced on v0.45.0 (macOS, Apple Silicon), three minor versions after the v0.42.4 report.
readis unchanged.grepis not — the claim there needs narrowing, which I think makes this report stronger rather than weaker.read— still 0%, confirmedByte-identical to
catat every size tried:catrtk readMeanwhile
rtk gainon this machine creditsrtk readwith 4.2M tokens saved over 1,092 calls (18.0% avg). Measured compression for that command is zero, so that entire line is unearned — about 19% of the reported global total.grep— the 0% claim doesn't hold on v0.45.0This is where I'd refine the report.
rtk grepcompresses substantially on large results and no-ops on small ones:grep -rn juce <dir>grep -rn ZoneEqParams <dir>So "grep receives 0% compression" is true only below some size threshold. On big outputs — the ones that actually matter for context — it's doing real work. Worth splitting that out from the
readfinding, since they have different causes and only one of them is a no-op across the board.Controls behave as this issue describes
ps auxwc -l <file>ls -la <dir>envMethodology note for anyone reproducing
rtk proxy read <file>is not a valid raw baseline —readis an rtk subcommand, not a shell command, soproxyruns the shell builtin and yields 0 bytes. It looks like infinite savings. Compare againstcat <file>instead. (I got this wrong first time round.)Everything above was written to files and measured with
stat -f%z, so nowcin a pipeline could itself be rewritten and skew the count.Suggestion
The gap seems to be that
gainrecords an expected saving per command class rather than the measured delta for that invocation. If it recorded actual pre/post byte counts per call — and attributed 0 when a filter passes through unchanged — the headline would be smaller but defensible, andread-style no-ops would surface immediately instead of being the single largest reported contributor.Related: for anyone auditing their own numbers, note that Claude Code's native Read/Grep tools never reach the Bash hook (#538), so
gaindescribes one lane of token usage rather than the total, independently of this bug.randomparity commentedon Aug 24, 2026
Independent reproduction on rtk 0.45.0 (macOS arm64), against a different codebase and a different harness — this reproduces the
read/grephalf of the report. Adding it since the issue carriesneeds-reproduction.Method: same as the original. Raw output bytes vs
rtk <cmd>output bytes, on a pinned Rust repository (457.rsfiles, ~92k LOC).git statuswc -l src/main.rsls -la srcgit log -20git diff HEAD~3grep -rn TODO .rg "impl" src --type rustrg -n "pub fn" srcgrep -rn unsafe srcrg -l test srccat Cargo.tomlcat README.mdcat src/main.rsgit diff HEAD~3 --statls -R srcls srcConsistent with the original report:
read(fromcat) is 0% on every file tested, andgrep/rgare 0–17%. The structured-output commands compress as advertised.Two things I can add beyond the original:
1. Flags matter as much as the command. The same command compresses well or not at all depending on form —
git logis −52% bare and 0% with--oneline;git diffis −48% bare and 0% with--stat. Agents overwhelmingly use the compact forms, since they are already minimising their own context. Mining 188,376 realBashtool calls from local Claude Code transcripts, only 13.3% were bare commands; 59.8% contained a pipe.2. Weighting by real-world usage, the weak handlers dominate. Asking
rtk rewriteabout a random sample of 5,000 of those real calls, RTK offers a rewrite on 42.2% of them. Of those rewrites,grep(18.2%),rg(12.7%) andread(9.8%) together take 40.7% — i.e. the handlers measured at 0–17% above account for the plurality of RTK's real-world reach, while the handlers that genuinely compress (git status,git log,git diff,git show) total about 19%.So the "unreproducible savings" in the title has, I think, two distinct causes worth separating:
lsnotls -la#561, wherertk lsmeasures against an internally synthesisedls -la.saved_tokensis computed withsaturating_subonusizeatsrc/core/tracking.rs:425, so the+29%and+35%rows above record as0saved rather than negative. Filed asrtk gaincannot represent a regression: saturating_sub floors negative savings to zero #3702.Neither fully explains the ~90M figure in the original report, but both push the aggregate upward and would need fixing before
rtk gaincould be reconciled against measured output.Full method and data: happy to share the harness if useful.
KuSh commentedon Sep 13, 2026
Closing as a duplicate of #2805, which explains the numbers measured here:
rtk reademits the file unchanged but records the whole file as the baseline, labelled as acatthe caller never ran, so the byte-identical output and the 100%-saved rows are two faces of the same accounting defect. #2805 carries the root cause and the fix discussion, and the aggregate tables from this thread are directly useful there - please continue on #2805.