Repository navigation
Closed as duplicate
Closed as duplicate
Copy link
Labels
area:clibugSomething isn't workingeffort-smallQuelques heures, 1 fichierfilter-qualityFilter produces incorrect/truncated signalgood first issueGood for newcomerspriority:medium
Description
Bug
When rtk read truncates output via --max-lines the dropped content is recorded as "saved tokens" in the
tracking database.
This inflates rtk gain numbers. In my case, a handful of large bioinformatics files (FASTA, SAM) pushed reported savings to 278M tokens — almost entirely fake.
Real data from my history — a few bioinformatics file reads dominate the entire dashboard:
rtk gain --tier pro -q
RTK Token Savings (Global Scope)
════════════════════════════════════════════════════════════
Total commands: 92
Input tokens: 278.1M
Output tokens: 6.0K
Tokens saved: 278.1M (100.0%)
Total exec time: 25.6s (avg 277ms)
Efficiency meter: ████████████████████████ 100.0%
By Command
────────────────────────────────────────────────────────────────────────
# Command Count Saved Avg% Time Impact
────────────────────────────────────────────────────────────────────────
1. rtk read 17 269.2M 88.1% 150ms ██████████
2. rtk curl -sL https://... 1 8.8M 100.0% 1.8s ░░░░░░░░░░
3. rtk ls 27 2.8K 65.5% 1ms ░░░░░░░░░░
...
Reproduction
Environment
- rtk 0.34.2
- Linux 6.12.0
- Claude Code with PreToolUse hook (rtk-rewrite.sh v3)
# 1. Create test file: 1000 lines, ~90KB
python3 -c "for i in range(1000): print(f'line {i}: ' + 'x'*80)" > /tmp/test.txt
wc -c /tmp/test.txt # 90890 bytes
# 2. Read with --max-lines
rtk read --max-lines 1 /tmp/test.txt > /dev/null
# 3. Check tracking DB
sqlite3 ~/.local/share/rtk/history.db \
"SELECT input_tokens, output_tokens, saved_tokens, savings_pct
FROM commands ORDER BY id DESC LIMIT 1;"
# Result:
# input_tokens = 22723 ← ceil(file_size / 4), from stat()
# output_tokens = 9 ← actual output after truncation
# saved_tokens = 22714 ← WRONG: this is discarded data, not savings
# savings_pct = 99.96 ← meaningless
Expected behavior
Does not count dropped data with --max-lines as saved, input_tokens should be derived from the content actually read
Reacted by Ben P.
Metadata
Metadata
Assignees
Labels
area:clibugSomething isn't workingeffort-smallQuelques heures, 1 fichierfilter-qualityFilter produces incorrect/truncated signalgood first issueGood for newcomerspriority:medium
Activity
Flipsi85 commentedon Apr 9, 2026
Additional data point:
rtk grephas the same inflation issuertk version: 0.35.0
OS: macOS (Darwin 25.3.0, arm64)
Same root cause, different command. My
rtk gaindashboard:The per-command breakdown makes the bug obvious:
The math doesn't add up:
rtk grepsaved 7.7M at 34.1% average, the raw input would have been ~22.6M tokens across 14 calls (~1.6M per grep). That's implausible for normal repo searches.input_tokensincludes data that was filtered/truncated before ever reaching the LLM.This confirms the issue isn't limited to
rtk read --max-lines— it affectsrtk grep(and likely other commands) wherever output is filtered or truncated.Suggestion:
input_tokensshould reflect what would have been sent without rtk (i.e., the raw command output), andoutput_tokensshould reflect what was actually sent. The difference is the real saving. Currentlyinput_tokensseems to come fromstat()or a similar pre-filter estimate.pszymkowiak commentedon Apr 12, 2026
🔍 Automated Triage
bugmediumSummary
rtk read --max-lines calculates input_tokens from total file size (stat) instead of bytes actually read, inflating saved-token metrics; PR #2107 is in progress.
📁 Relevant files
src/commands/read.rssrc/tracking/stats.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
fix(git): don't count --max-lines truncation as savings (rtk-ai#1561)
fix(git): don't count --max-lines truncation as savings (rtk-ai#1561)
Yohjisakamoto commentedon Jul 22, 2026
Your RTK measurement is useful context; we published reproducible DeepSWE results focused on repeated coding-agent rounds—would you be open to evaluating the methodology and results? https://turaai.net/docs#benchmark-current-test-set-record
KuSh commentedon Sep 5, 2026
Closing as a duplicate of #2805, which reports the same accounting defect in the same lines of src/cmds/system/read.rs - the full file is used as the baseline while the line window is applied only to the output - and goes further into the counterfactual and the pipe path. Your bioinformatics numbers are a good illustration of the scale, so please carry them into #2805; the fix will be tracked there.
fix(read): window the raw tracking baseline, not just filtered output