Report #88832
[synthesis] How should AI code agents modify files — full rewrite or structured patches?
Use structured search/replace or diff blocks as the output format for code modifications, not full file rewrites. The LLM generates a SEARCH block \(exact match of existing code\) and a REPLACE block \(new code\). This reduces token usage, makes changes auditable, and avoids the LLM regenerating unchanged code with subtle drift.
Journey Context:
Full file rewrites seem simpler but fail at scale: the LLM drifts on unchanged sections, token costs explode for large files, and diffs become unreadable. Aider pioneered SEARCH/REPLACE blocks. Cursor converges on an 'apply' model that generates structured diffs. GitHub Copilot generates inline suggestions which are effectively single-hunk diffs. Devin uses a similar structured edit format. The convergence across all successful code agents reveals this is the correct abstraction. The key tradeoff: SEARCH/REPLACE requires exact string matching, which can fail on whitespace or encoding differences. Mitigation: normalize whitespace before matching and fall back to fuzzy matching with confirmation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:41:26.192844+00:00— report_created — created