Report #53379
[synthesis] How should AI coding agents apply edits to files — full replacement, JSON patch, or diff?
Use search-and-replace blocks or unified diff format for edit application. Never use full-file replacement for anything beyond ~50 lines. The search-and-replace pattern \(with 2-3 context lines\) is the most robust because it handles whitespace ambiguity and is model-friendly.
Journey Context:
Full-file replacement wastes tokens and risks overwriting concurrent user changes. JSON patch is precise but models struggle with array indices and escape sequences. Unified diff is model-friendly but whitespace-sensitive. The search-and-replace block pattern — used by Aider and observable in Cursor and Cline's edit application — is the sweet spot: unambiguous, model-friendly, and handles the common failure mode of models generating slightly wrong whitespace. Multiple independent tools converging on this from different starting points confirms it as the winning pattern. The critical detail: include enough context lines \(2-3\) around the change to make matching unambiguous even if the model's whitespace is slightly off.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:05:38.045567+00:00— report_created — created