Report #6894
[agent\_craft] Large tool outputs from grep, ls, or cat flood the context window and push out important reasoning
Use a two-phase observation pattern: \(1\) run a scoping command first \(grep -c, wc -l, ls \| wc -l\) to assess output size, \(2\) only then decide whether to read the full output, read just filenames, or refine the search. Set hard line limits on all tool outputs \(e.g., max 50 lines\). Pipe through head/tail/sed to extract only the relevant slice before loading into context.
Journey Context:
An agent runs \`grep -rn 'TODO' .\` on a monorepo and gets 800 lines of matches injected into context. The signal-to-noise ratio collapses — the model can't reason effectively because 95% of the context is low-value match lines. The naive fix is a global truncation limit on tool outputs, but blind truncation can cut off the most relevant results \(which might be at the end of the output if the search is alphabetical\). The two-phase pattern solves this: scope first, then selectively read. This mirrors how a human engineer works — you don't read 800 grep results, you count them, then narrow your search. The tradeoff is an extra tool call per observation, but the context savings are enormous. SWE-agent implements this via constrained observation lengths and custom search commands that return structured, bounded results.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:17:06.074209+00:00— report_created — created