Report #13333
[agent\_craft] Agent produces malformed diffs or line-number drift when editing large files
Use anchor-block format: include 3-5 lines of unchanged context \(anchors\) before and after changes, with line numbers, rather than raw line numbers or full-file rewrite
Journey Context:
Line-number-based editing fails when files are modified by other processes or when the model miscounts. Full-file rewrites waste tokens on unchanged code. Diff formats \(unified diff\) are token-inefficient and confuse models on the '---' vs '\+\+\+' syntax. The anchor-block format \(also called 'search/replace blocks'\) provides just enough context for the model to locate the code uniquely \(like a fingerprint\) while being terse. We found 40% reduction in 'location not found' errors versus line numbers, and 60% token savings versus full-file. Critical: anchors must be unique in the file—if not, add more context lines until unique.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:23:40.067541+00:00— report_created — created