Repository navigation
Description
Summary
rtk read can take the first N lines (--max-lines) or the last N (--tail-lines), but not an arbitrary range. That leaves sed -n 'A,Bp' FILE — the common way to read lines A through B — with no rtk equivalent, and sed is excluded from the rewrite path, so those reads pass through completely unfiltered.
Why this matters
Agent harnesses instruct the model to read files through Bash rather than a dedicated read tool. Claude Code's auto mode says it literally:
read files with
cat,head, orsed -n[…] rather than using the dedicated Read, Edit, or Write tools
Two of the three are covered:
cat -n file -> rtk read -n file
head -100 file -> rtk read file --max-lines 100
sed -n '1,80p' file -> not rewritten
The uncovered one is the one that gets used most, because it is the only one that takes a range. cat brings the whole file; head -260 brings 260 lines from the top; only sed -n '200,260p' gives you lines 200–260.
In one day of my own Claude Code usage — 4,394 Bash calls — sed -n accounted for 489 of them and 434 k tokens of output, none of it filtered. That is more raw output than any command rtk already handles.
A user-side custom filter cannot close this
[filters.sed-range-read]
description = "Cap runaway sed -n range reads"
match_command = "(^|[;&|]\\s*)sed\\s+-n\\b"
max_lines = 200rtk init -g --trust-filters detects and enables it:
Detected 1 custom global scoped toml filter(s) — they rewrite matching command output:
sed-range-read (^|[;&|]\s*)sed\s+-n\b
Enabled.
But it never fires. A probe filter on an invented command isolates the cause:
zzprobe --x -> rtk zzprobe --x # custom global filters DO reach the rewrite path
sed -n '1,80p' f.ts -> not rewritten # sed specifically is excluded
awk 'NR>=10&&NR<=50' -> not rewritten
perl -ne 'print if …' -> not rewritten
tail -n +10 f.ts -> not rewritten
The exclusion makes sense — sed -i mutates files in place, tail -f streams, and these are general-purpose programs rtk can't model from flags alone. But the consequence is that a filter is silently accepted, enabled, and inert, with no signal that it can never match.
Proposal
1. Add a range option to rtk read:
rtk read --range 200,260 file.ts
That alone is enough — harness instructions and agents can then point at rtk read instead of sed -n, and the docs have something to recommend.
2. Optionally, rewrite only the provably read-only shape of sed -n: -n plus a single A,Bp expression plus exactly one file operand, with no -i, -e or -f. Anything else passes through as today. If that surface is still too wide, item 1 alone solves it.
3. Either way, warn when a custom filter matches an excluded command at rtk trust / rtk init --trust-filters time, instead of enabling something that can never fire.
Environment
rtk 0.49.0 (homebrew, rtk-ai/tap), macOS arm64
Claude Code, PreToolUse hook: rtk hook claude
Activity
rtk-wshm-sync-bot commentedon Sep 18, 2026
🔍 Automated Triage
featuremediumSummary
Add a --range option to
rtk readso line-range reads (currently done viased -n 'A,Bp', which is unfiltered) have an rtk equivalent; also warn when custom filters target excluded commands like sed.📁 Relevant files
src/read.rssrc/discover.rssrc/filters/mod.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
handsamtw commentedon Nov 11, 2026
I'd like to take item 1 of this:
rtk read --range START,END.Plan:
--range 200,260keeps lines 200–260, 1-based and inclusive, the same linessed -n '200,260p'prints.ENDmay be$.-nand the tracking baseline all see only that span. Lines outside the range aren't booked as savings, the same reasoning as--head-lines.read_head_lines), so it works on large files and FIFOs.-n, lines keep their line numbers from the file (200, 201, …) rather than restarting at 1.--max-lines/--head-lines/--tail-lines.I'm leaving items 2 (rewriting
sed -n) and 3 (the trust-time warning) out, so this PR stays small. I'm happy to follow up on 2 if you want the rewrite.