fix(read): don't count --max-lines truncation as token savings (#1045)#1076
Open
ousamabenyounes wants to merge 3 commits intortk-ai:developfrom
Open
fix(read): don't count --max-lines truncation as token savings (#1045)#1076ousamabenyounes wants to merge 3 commits intortk-ai:developfrom
ousamabenyounes wants to merge 3 commits intortk-ai:developfrom
Conversation
Ready-to-use Claude Code PreToolUse hook that intercepts destructive CLI operations before execution: - rm -rf on root/home/parent → block - rm -rf on non-safe dirs → ask confirmation - git push --force (but allows --force-with-lease) → block - git reset --hard, clean -f, checkout -- ., branch -D → ask - Secrets exposure (cat .env, .pem, API keys in commands) → block - Destructive DB ops (DROP, TRUNCATE, DELETE ALL) → block - Docker mass removal / system prune -a → ask Container-aware: skips host-path checks inside docker/kubectl exec since paths resolve inside the container, not the host. See rtk-ai#1007 for design discussion. Co-Authored-By: Claude <noreply@anthropic.com>
39 test cases covering all categories: - File ops: rm -rf block/ask, safe dirs allowed, container exec bypass - Git: force-push block, force-with-lease allowed, destructive ops ask - Secrets: .env/.pem/.key blocked, API keys in commands blocked - Database: DROP/TRUNCATE blocked, SELECT allowed - Docker: prune -a ask, normal commands allowed - Edge cases: empty input, safe commands pass through Co-Authored-By: Claude <noreply@anthropic.com>
…i#1045) When --max-lines or --tail-lines is active, timer.track() was comparing the full raw file against the truncated output, inflating savings by the entire skipped portion (250M+ tokens reported for large files). Fix: capture post-filter, pre-truncation content and use it as the tracking baseline when a line window is active. Savings now reflect only RTK's actual compression, not user-requested truncation. Same fix applied to run_stdin(). Adds 4 regression tests covering max-lines, tail-lines, no-truncation (unchanged behaviour), and a numerical proof that the bug inflated savings >1k tokens while the fix reports 0 for uncompressed content. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rtk read file --max-lines Nwas comparing the full raw file against the truncated output intimer.track(), inflating reported savings by the entire skipped portion — 250M+ tokens reported for a single command on large files--max-linesor--tail-linesis activerun_stdin()Root cause
Test plan
4 new regression tests in
src/cmds/system/read.rs:test_max_lines_tracking_uses_pretruncation_content— tracking baseline equals full filtered content, not truncated slicetest_tail_lines_tracking_uses_pretruncation_content— same invariant for--tail-linestest_no_truncation_tracking_unchanged— without truncation flags, behaviour is identical to beforetest_savings_inflation_is_zero_with_fix— numerical proof: buggy code reports >1k fake tokens, fix reports 0Fixes #1045
🤖 Generated with Claude Code