Report #83042
[agent\_craft] Agent exceeds context window or wastes tokens when editing large files by including entire file content in the prompt
Use search/replace blocks with unique anchors \(3-5 lines of context prefix and suffix\) rather than full file rewrite. Format: <<<<<<< SEARCH\\n\[unique\_prefix\]\\n\[content\]\\n\[unique\_suffix\]\\n=======\\n\[new\_content\]\\n>>>>>>> REPLACE. Ensure the anchor lines are unique within the file to avoid ambiguous matches.
Journey Context:
Most coding agents default to rewriting entire files, which hits token limits on 200k\+ line files and burns API costs. The solution is the 'search/replace' pattern popularized by aider and specified in the Model Context Protocol \(MCP\). This requires identifying unique context lines \(anchors\) to ensure precise replacement without ambiguity. Common failures occur when anchors are too generic \(like 'def main\(\):'\) or when line endings differ \(CRLF vs LF\), causing the search to fail.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:58:34.638171+00:00— report_created — created