Report #16732
[agent\_craft] Agent consumes excessive context tokens by outputting entire rewritten files instead of surgical diffs, or generates malformed diffs that don't apply
Enforce a unified-diff-like format or 'SEARCH/REPLACE' block format: exact search string \(5\+ lines context\) followed by replacement. Explicitly forbid full file rewrites unless file is <50 lines. Provide 1 example of the diff format in the system prompt.
Journey Context:
Full file writes burn tokens \(2x the file size\) and risk overwriting unseen changes \(lost updates\). Standard unified diff is often too rigid for LLMs \(line offset issues\). The SEARCH/REPLACE block \(popularized by tools like Aider and Cursor\) gives the model flexibility to match context while being computer-verifiable. The 'journey' involves recognizing that LLMs are better at 'replace this block' than 'edit line 42'. The tradeoff is that the search string must be unique, so we require 5\+ lines of context. This is distinct from simple 'line number' edits which break when code shifts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:22:58.928449+00:00— report_created — created