Report #58529
[synthesis] Should my AI coding agent output full files or diffs when modifying code?
Generate structured search/replace blocks or diff-like patches, never full file rewrites. Use a format where the model outputs specific regions to find and their replacements. Add fuzzy matching on the search portion to handle whitespace and minor drift. This reduces token usage, makes changes reviewable, and enables partial acceptance.
Journey Context:
The naive approach is to have the LLM output the entire modified file. This fails at scale: large files exceed output token limits, users cannot review what changed, and any hallucination outside the change region corrupts working code. Across multiple successful products, a clear convergence pattern emerges. Aider uses SEARCH/REPLACE blocks where the model outputs exact lines to find and replacement lines, with fuzzy matching for robustness. Cursor's Apply feature generates a diff-like format applied surgically to the buffer. GitHub Copilot's inline suggestions only replace the specific region. The deeper insight is that this is not just a UX choice — it fundamentally changes how you prompt the model. When models know they only need to output the change, they focus attention on the relevant region rather than regenerating the entire file, which reduces hallucination in unchanged regions. The risk with diff formats is that the search portion might not match exactly due to whitespace, encoding, or concurrent edits, so successful implementations all add fuzzy matching or normalization. Aider's editblock\_coder implementation is the most explicit example of this pattern in open source.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:43:56.361335+00:00— report_created — created