Repository navigation
Description
Summary
saved_tokens is computed as the full size of a command's output minus RTK's output, with no
upper bound. But the whole premise of the tool is tokens reaching a model's context, and
every LLM CLI truncates tool output long before it gets there. Bytes above that truncation
point cost nothing whether RTK filters them or not — the client would have discarded them for
free. RTK currently books all of them as savings.
The effect is not marginal, because command output is long-tailed:
rtk 0.45.0 · 10,321 commands · 90-day window
reported saved 587.9M 96.5%
capped @7500 tok 3.2M 43.8%
overstatement 184x
top 1 command = 69.4% of the reported total
top 8 commands = 92.1%
One recursive grep accounts for 69% of the lifetime figure. It emitted roughly 1.6 GB;
RTK booked 407.9M tokens of credit for not showing it. Under a ~30k-char ceiling its real
contribution is 907 tokens — the client would have truncated the rest regardless.
Worst offenders, shapes only:
billed 407.9M real 907 grep -rEi <arg>
billed 66.1M real 1.7K grep -rniE <arg>
billed 27.4M real 7.3K find <arg> -name <arg>
Where
src/tracking.rs, record:
let saved = input_tokens.saturating_sub(output_tokens);No ceiling. input_tokens is what the command produced, not what could have been consumed.
This is not "RTK doesn't work"
Worth stating plainly, because the headline number invites the opposite reading. Measured
against output that could actually have reached context, RTK cuts 43.8% — a genuinely
good result, and every filter on my install compresses (best: a TOML ps filter at 0.08x,
read 0.61x, ls 0.58x, grep 0.55x). The tool is fine. The scoreboard is what's wrong,
and it's wrong in a direction that makes the tool easy to dismiss once someone checks.
Suggested fix
Keep the raw number, add a capped one. The ceiling is client-specific — Claude Code truncates
around 30k chars; other clients differ — so it should be configuration, not a constant:
[tracking]
context_ceiling_tokens = 7500 # 0 disables capping, preserving current behaviourthen let saved = min(input_tokens, ceiling).saturating_sub(min(output_tokens, ceiling));
Storing both columns would let gain show the honest figure by default and the raw one under
a flag, without discarding history.
How the ceiling was derived
Not assumed — measured. Across 23,204 tool results in my client's own transcript logs:
p50 = 232 chars, p99.9 = 29,726, all-time maximum 63,042, none above 100k. ~4 chars/token
gives ~7,500. The script that derives this on any machine, and the rest of the analysis, can
be shared if useful.
Environment
rtk 0.45.0, Linux x86-64, Claude Code client. All figures from ~/.local/share/rtk/history.db;
command shapes have operands stripped.
Related, from the same analysis: #3506 (gain's by-command table mixes SUM and AVG in one
row) and #3507 (adding a median would make this class of problem visible at a glance). Happy
to open a PR for any of the three if the approach sounds right.
Activity
pszymkowiak commentedon Aug 10, 2026
🔍 Automated Triage
bughighSummary
gain's saved_tokens metric has no ceiling reflecting real context-window truncation, inflating reported savings by up to ~184x on long-tail output; add a configurable context_ceiling_tokens cap in src/tracking.rs and report both raw and capped figures.📁 Relevant files
src/tracking.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
juxtapo9090 commentedon Aug 10, 2026
Correction to my own framing, after reading
docs/guide/resources/savings-explained.md— which I should have found before filing this.That doc already scopes
gaindeliberately: the percentages measure bash output bytes, not cost, and the absolute token counts are explicitly disclaimed as order-of-magnitude rather than an invoice line. My opening line above — "the whole premise of the tool is tokens reaching a model's context" — is my framing, not the project's, and it overstates the case. That's on me for not checking first.What I think still stands, narrowed to two points:
1. Even measured purely as bash output, the raw side of the ratio counts bytes the agent never receives. Agent CLIs truncate tool output before it reaches the model — on my client, around 30k chars; I measured a hard ceiling across 23,204 tool results with none above 100k. The doc's model ("RTK executes it, compresses the output, and returns the compressed version") reasonably assumes the unfiltered output would otherwise have been read in full. Past the truncation point it wouldn't be — the client discards it either way. So
Save%is an accurate ratio of what the command emitted, but not of what RTK prevented from being read, and those diverge sharply on the long tail.2. The concentration effect is independent of the above and isn't addressed anywhere. On my install a single
grep -rEicontributes 69.4% of the 90-day total, and eight commands contribute 92.1%. Whatever denominator you settle on, a headline that one recursive grep can move by two-thirds is hard for a user to read correctly.Both may be better addressed as reporting (#3507) than as a change to what's stored — showing a median and a concentration line would let a user see the long tail without touching
saved_tokensat all.Happy to defer to whatever you consider in scope. If the answer is "working as documented", that's a fair close and I'd rather hear it than have this sit open.
KuSh commentedon Oct 31, 2026
Since v1.0.0 the
rtk gainheadline and the daily, weekly and monthly totals leave out rows whose raw output is past the ~30k-character agent cap, and gain shows how many were excluded. The per-command table still lists those rows in full, for diagnosis. If you still see the headline inflated on v1.1.0 or later, please comment and we will reopen.fix(gain): do not report an all-oversized tracker as empty