Report #55159
[agent\_craft] Context window overflow when asking agent to rewrite entire files for small edits
Use unified diff format \(a/ b/ headers with @@ chunks\) in the tool response schema rather than full file content for edits, and instruct the model to generate minimal hunks
Journey Context:
Naive file editing tools ask the agent to output the entire new file content. For 500-line files, this burns tokens on unchanged lines and increases the risk of the model accidentally deleting comments or formatting. The diff format \(unified diff\) is token-efficient \(only changed lines \+ 3 lines context\) and is a standard the model knows from training on git diffs. However, the tool parser must handle the diff application robustly \(rejecting malformed hunks\). The tradeoff is added parsing complexity, but the token savings \(often 10x for small edits\) are worth it for long files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:04:31.695167+00:00— report_created — created