Repository navigation
Description
Environment
- rtk version: 0.43.0 (
rtk --version→rtk 0.43.0) - Repo: rtk-ai/rtk
- Install: Homebrew (linuxbrew), bottled
- OS: Linux (devcontainer, linux 6.12.5-linuxkit)
Summary
rtk grep -r drops content in two ways with no flags set and no clear inline warning that recovers full content: (1) it truncates individual matched lines mid-sentence with ... once a line exceeds a length threshold, and (2) it caps results per file to roughly ~25 lines, replacing the remainder with a "+N more" pointer to a tee log — but that tee log's lines are also truncated with ..., so there is no path back to full-fidelity output from rtk grep alone. This contradicts the tool's own stated behavior in at least one place: rtk grep --help's one-line description reads "Compact grep - strips whitespace, truncates, groups by file" (so truncation is at least implied there), but it's easy to read that as a compaction feature and not realize it can silently drop match content with no way to fully recover it — even via the recovery path the tool itself points you to. Filing this because the failure is silent (no error, no non-zero-looking exit signal) and the stated recovery path (tee log) does not actually restore the elided content.
Repro steps
- Create a disposable fixture directory with two markdown files, each containing ~30 lines that match a search term, where roughly half the lines are padded past 80 characters:
mkdir -p /tmp/fixture/foo # foo/bar.md and foo/baz.md, each 30 lines, alternating: # "widget line {n}: this is a synthetic sentence about widgets that is deliberately # padded past eighty characters so truncation logic can be tested, item widget-{n}." # "short widget note {n}" - Run raw grep and the rtk wrapper against the same directory/pattern:
grep -rn "widget" /tmp/fixture/foo rtk grep -r "widget" /tmp/fixture/foo - Compare total match count and line content between the two outputs.
- For any file where
rtk grepprints a "+N more" line, follow the pointed-to recovery command (tail -n +<N> ~/.local/share/rtk/tee/<file>.log) and inspect whether the recovered lines are full or still truncated.
Expected
rtk grep -rreturns the same set of matching lines as rawgrep -rn(same total count), with the tool's stated compaction (whitespace-stripping, deduping, grouping) applied but without dropping match content per line or per file.- If a cap is necessarily applied for token-budget reasons, the recovery mechanism it points to (the tee log) should contain the full, untruncated lines — not the same lossy
...-truncated content.
Actual
On the fixture above (two files, 30 matching lines each = 60 total):
- Raw
grep -rn "widget" /tmp/fixture/foo→ 60 matching lines. rtk grep -r "widget" /tmp/fixture/foo→ 54 lines shown (header correctly reports "60 matches in 2 files", but the body only prints 54).- Long lines are cut mid-sentence with
..., e.g.:
/tmp/fixture/foo/bar.md:1:widget line 0: this is a synthetic sentence about widgets that is deliberately p...
— this happens by default, no--max-len/-lflag passed. - Each file's output stops at line 25 of that file and ends with:
+5 more in /tmp/fixture/foo/bar.md [see remaining: tail -n +26 ~/.local/share/rtk/tee/<hash>_grep_0_..._bar_md.log]
Following that exacttailcommand against the referenced tee log file shows the "remaining" lines are also truncated mid-line with..., e.g.:
.../fixture/foo/bar.md:27:widget line 26: this is a synthetic sentence about widgets that is deliberately ...
There is no rtk-only path to recover the complete matched line text — the recovery pointer leads to more lossy output, not the original.
Additional inconsistency noted
- Running
rtk grep "pattern" <single-file>(no-r, one file, few matches) was observed in separate testing to return the full, untruncated line even with an explicit smaller--max-lenpassed — the flag appeared to have no truncating effect in that non-recursive mode. Only the recursive/multi-file-rpath reliably exhibited the truncation and per-file cap described above. This suggests the truncation/cap logic may be scoped only to the recursive/grouped-output code path, which could be a related but distinct bug from a max-len flag not being respected in single-file mode. Flagging both observations since they may share a root cause in how the length/grouping threshold is applied.
Impact
Any consumer treating rtk grep -r as a faithful (if compact) substitute for raw grep -r will silently miss matched content on any directory/file combination that crosses the per-file line cap or the per-line length threshold, with no reliable signal that content was dropped beyond a header count that is easy to not cross-check, and no way to recover full fidelity even by following the tool's own pointed-to recovery file.
Suggested fix (non-binding)
- Make the per-file cap and per-line truncation opt-in (default OFF) rather than default ON, matching
rtk read's existing default (full content, no filtering, unless a filter level is explicitly requested). - If a cap/truncation must stay default-on for token economy, write the untruncated full lines to the tee log referenced by "+N more", not the same truncated form — the log's entire purpose is fidelity recovery.
- Update
rtk grep --helpand any first-party docs to state plainly, in one place, whether recursive (-r) mode is lossy by default, since the one-line description ("strips whitespace, truncates, groups by file") does hint at this but is easy to miss as a load-bearing warning.
Activity
pszymkowiak commentedon Jul 14, 2026
🔍 Automated Triage
bughighSummary
rtk grep -r silently truncates long matched lines and caps results per file, and the pointed-to tee log recovery path is also truncated, causing undetectable data loss; recommend making truncation/cap opt-in or fixing tee log to store full lines.
📁 Relevant files
src/commands/grep_cmd.rssrc/tee.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
albatrossflyon-coder commentedon Jul 14, 2026
Hi! I'd like to work on this one. Could you assign it to me?