You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk read --max-lines N outputs only N/2 lines — head -N hook rewrite silently under-delivers half the requested lines #3370
Claude Code, hook: PreToolUse → matcher: "Bash" → rtk hook claude
Summary
--max-lines N emits exactly N/2 content lines (plus a [K more lines] marker), not N. Because the Claude Code hook rewrites head -N <file> to rtk read <file> --max-lines N, every agent head -N receives half the lines it asked for.
--tail-lines N is exact (verified against tail -N, byte-identical); only --max-lines halves.
Impact
Any agent running head -N file silently gets N/2 lines. The truncation marker is visible in standalone use, but the count contradicts what was requested.
On 0.38.0 this also poisoned pipelines (head -200 f | grep X → grep searched only 100 lines and the marker was consumed by grep → silent false negative). 0.44.2 no longer rewrites head inside pipelines, which contains that failure mode — but the standalone halving remains.
Additional observation (savings accounting)
rtk read ... --max-lines/--tail-lines invocations are logged to history.db with original_cmd synthesized as plain cat <file> (flags erased), input_tokens = the full file, and the difference booked as savings. Example measured entry: a --max-lines 20 read of a 1.27 MB file logged as cat <file>, input=318,445 tokens, output=119, savings 99.96%. A raw head -20 would have produced the same small output without rtk, so the full-file baseline overstates real savings. In our 3-month ledger, 205 such entries account for 71.5M of 79.4M total rtk read "saved" tokens (~90%). Related in spirit to #3339 (different mechanism). Happy to split this into its own issue if you prefer.
rtk read --max-lines N truncates to N/2 lines (not N), so the head -N hook rewrite silently delivers half the requested content to agents; --tail-lines is unaffected.
This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.
📁 Relevant files
src/read.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
Still reproduces on rtk 0.48.0 (Homebrew bottle, macOS arm64), and on a tiny file it is worse than N/2: --max-lines 3 on a 5-line file returns a single line, and the [K more lines] marker over-counts.
$ printf'line1\nline2\nline3\nline4\nline5\n'> five.txt
$ rtk --versionrtk 0.48.0
$ head -3 five.txtline1line2line3
$ rtk read five.txt --max-lines 3line1[4 more lines]
$ rtk read five.txt --max-lines 1line1[5 more lines]
--max-lines 1 prints 1 line and claims 5 remain (only 4 do). --tail-lines 2 is correct (line4 line5).
Larger case: rtk read src/profile.rs --max-lines 3 on a 354-line Rust file prints 2 lines + [352 more lines].
Until fixed, an agent that runs head -N through the hook silently loses content, so I've excluded head/tail/cat/wc in exclude_commands on my side.
Fixed by #3941, shipped in v0.50.0: head -N file now rewrites to rtk read file --head-lines N, which prints exactly the first N lines. --max-lines remains a structural preview, as rtk read --help describes, and the savings accounting point is tracked in #3339. Please reopen if head -N still returns fewer lines on the latest version.
Activity
pszymkowiak commentedon Aug 3, 2026
🔍 Automated Triage
bughighSummary
rtk read --max-lines Ntruncates to N/2 lines (not N), so thehead -Nhook rewrite silently delivers half the requested content to agents; --tail-lines is unaffected.📁 Relevant files
src/read.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
mohammedelkarsh commentedon Aug 3, 2026
I'd like to work on this. Investigating the --max-lines halving bug in \src/read.rs\ and will open a PR with a fix + regression test.
constantin-jais commentedon Sep 8, 2026
Still reproduces on rtk 0.48.0 (Homebrew bottle, macOS arm64), and on a tiny file it is worse than N/2:
--max-lines 3on a 5-line file returns a single line, and the[K more lines]marker over-counts.--max-lines 1prints 1 line and claims 5 remain (only 4 do).--tail-lines 2is correct (line4 line5).Larger case:
rtk read src/profile.rs --max-lines 3on a 354-line Rust file prints 2 lines +[352 more lines].Until fixed, an agent that runs
head -Nthrough the hook silently loses content, so I've excludedhead/tail/cat/wcinexclude_commandson my side.KuSh commentedon Oct 18, 2026
Fixed by #3941, shipped in v0.50.0:
head -N filenow rewrites tortk read file --head-lines N, which prints exactly the first N lines.--max-linesremains a structural preview, asrtk read --helpdescribes, and the savings accounting point is tracked in #3339. Please reopen ifhead -Nstill returns fewer lines on the latest version.docs(adr): address role-separated review of ADR-0055