rtk-ai/rtk
View on GitHubrtk git diff/show --max-lines may inflate savings same way as #1045
Open
#1561 opened on Apr 27, 2026
bugeffort-smallfilter-qualitygood first issue
Description
Context
Follow-up flagged by @pszymkowiak in PR #1076 review.
#1045 was about rtk read counting user-requested line truncation as RTK token savings. The same pattern likely exists in:
src/cmds/git/git.rs:200—git difftrackingsrc/cmds/git/git.rs:314—git showtracking
Both currently track against the compacted output. compact_diff itself is real RTK compression so that part is legitimate — but when a user passes --max-lines N to rtk git diff / rtk git show, the truncated portion gets counted as savings same as the original bug.
Reproduce (likely)
rtk git diff --max-lines 5 # large diff
rtk gain --history # check if the saved-tokens row for this command is suspiciously high
Suggested fix
Apply the same pattern as #1076:
- Extract a
pick_tracking_output(pre_truncation: Option<&str>, rtk_output: &str) -> &strhelper (already lives insrc/cmds/system/read.rsafter #1076 merges — could be promoted tosrc/core/utils.rs). - Capture the post-compact / pre-truncation content via
std::mem::takewhen--max-linesis active. - Pass the pre-truncation slice to
timer.track()instead of the windowed output.
Out of scope here
- Polluted historical data (separate concern — needs server-side cap or one-off migration, also flagged in #1076 review).
cc @pszymkowiak — opening as you suggested.