Report #47154
[synthesis] Agent rewrites entire files instead of applying targeted diffs, causing context waste and merge conflicts
Provide a strict diff/patch tool and explicitly forbid full file rewrites in the system prompt: 'You MUST use the apply\_diff tool. Do NOT output the entire file.' For Claude, provide the exact line numbers in the tool context. For Gemini, instruct it to output the surrounding context \(3 lines before/after\) in the diff to ensure indentation is preserved.
Journey Context:
Coding agents often waste tokens and risk introducing regressions by rewriting entire files instead of applying surgical patches. Claude 3.5 Sonnet's generative nature makes it default to full rewrites because it is statistically safer for the model to control the whole context. GPT-4o handles search/replace logic well but needs clear delimiters. Gemini struggles with whitespace in diffs. Forcing the model to use a diff tool via system instructions, combined with providing line-numbered context, shifts the model's behavior from 'regeneration' to 'modification.'
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:37:13.812404+00:00— report_created — created