Edit tool falsely claims 'File has been unexpectedly modified' on Opus 4.5
Environment
- Claude Code with Opus 4.5 (claude-opus-4-5-20251101)
- Platform: win32 (MSYS_NT-10.0-26100)
Steps to Reproduce
- Check file hash and modify time:
md5sum file && stat file - Use Read tool to read the file
- Immediately check hash and modify time again (identical - file unchanged)
- Use Edit tool with valid old_string that exists in the file
- Edit fails with 'File has been unexpectedly modified'
Evidence
- File:
H:/skydiving-manifest/src/ManifestApp.Client/Pages/Login.razor - MD5 hash before Read:
fe48316a07481bc25545326baa745bac - MD5 hash after Read:
fe48316a07481bc25545326baa745bac(identical) - Modify time before:
2025-11-30 23:32:47.746767100 -0700 - Modify time after:
2025-11-30 23:32:47.746767100 -0700(identical) - Only Access time changed (expected behavior for a read operation)
Observed Behavior
The Edit tool rejects the edit claiming the file was modified, even though:
- The file content hash is identical
- The file modify timestamp is identical
- No external processes modified the file (VS Code closed, File Explorer closed)
Expected Behavior
Edit should succeed since the file contents match what was read.
Additional Context
- User reports this issue started occurring with Opus 4.5
- Issue is reproducible across multiple files in the same session
- The Write tool also fails with 'File has not been read yet' immediately after a successful Read
- Workaround using bash heredoc (
cat > file << 'EOF') works, suggesting the issue is in the Edit/Write tool's internal state tracking, not file system permissions
Additional Data Point
Experiencing the same issue on Windows (MINGW64_NT-10.0-26100) with Opus 4.5.
Observation: Context Compression Correlation
In my case, this issue appears to be triggered or exacerbated by context compression/summarization. The pattern observed:
- Long conversation with many file Read/Edit operations
- Context compression occurs (automatic or due to context limit)
- All subsequent Edit/Write operations fail with "File has been unexpectedly modified"
- Even freshly reading the file doesn't fix it - Edit immediately after Read still fails
- Issue persists for the remainder of the session
Supporting Evidence: Stale Internal State
In the same sessions where this Edit bug occurs, I also see stale background bash reminders - system shows 7 "background bash shells" as "running" with "new output available", but:
KillShellreports they're already deadtasklist | grep pythonshows no matching processes- PowerShell child process inspection shows only 1 actual shell
This suggests internal state tracking becomes corrupted/stale after context compression, affecting both:
- File checksum/hash tracking (causing false "modified" errors)
- Background process tracking (causing phantom shell reminders)
Workaround Confirmed
Using Python via Bash to directly write files (python -c "open('file','w').write(content)") bypasses the issue completely, confirming this is internal tool state, not OS-level file locking.