[BUG] Edit tool fails with "File has been unexpectedly modified" on unmodified files
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Title: Edit tool fails with "File has been unexpectedly modified" on unmodified files
Environment:
- Claude Code v2.0.72
- Windows 10/11
- Model: Opus 4.5
Description:
The Edit/Update tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when:
- The file has not been modified
- Reading and editing happen in immediate succession
- It's a fresh session with no prior context
Reproduction steps:
- Start fresh Claude Code session
- Read any file: Read file X
- Immediately request an edit: Write "test" to the top of file X
- Edit fails with "unexpectedly modified" error
- Re-read the file
- Try edit again - still fails
Diagnostic evidence:
File hash remains constant before, during, and after failed edits:
certutil -hashfile "file.md" MD5
# Returns same hash: d2589ea81be4b71471b0dbed440e59bb
# 3 seconds later - same hash
# After failed edit - same hash
Tested and ruled out:
- OneDrive sync (not running)
- Windows Search Indexer
- Antivirus interference
- VS Code auto-save (closed)
- Multiple Claude Code sessions (all closed)
- Session compaction/context continuation
- CRLF vs LF line endings (converted to LF, still fails)
- File-specific issues (reproduced on newly created test files)
Workaround:
Using Python/sed/Bash to edit files directly works fine - only the Edit tool's internal comparison is broken.
python -c "
with open('file.md', 'r') as f: content = f.read()
content = content.replace('old', 'new')
with open('file.md', 'w') as f: f.write(content)
"
Expected behaviour:
Edit should succeed when the file content matches what was just read.
Actual behaviour:
Edit fails claiming file was modified, even when hash proves it wasn't.
What Should Happen?
Expected behaviour:
Edit should succeed when the file content matches what was just read.
Error Messages/Logs
● Update(clients\anglia_labels\client_success\week_51\visibility_intelligence_week_51.md)
⎿ Error: File has been unexpectedly modified. Read it again before attempting to write
it.
Steps to Reproduce
Reproduction steps:
- Start fresh Claude Code session
- Read any file: Read file X
- Immediately request an edit: Write "test" to the top of file X
- Edit fails with "unexpectedly modified" error
- Re-read the file
- Try edit again - still fails
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Claude Code v2.0.72
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗