You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Edit tool returns "File has been unexpectedly modified" when file is NOT modified #12462
I have searched existing issues and this hasn't been reported yet
This is a single bug report (please file separate reports for different bugs)
I am using the latest version of Claude Code
What's Wrong?
Bug Description
The Edit tool repeatedly returns error "File has been unexpectedly modified. Read it again before attempting to write
it." even when no external process is modifying the file.
Steps to Reproduce
Read a file with the Read tool
Immediately attempt to Edit the file
Error appears despite no changes to the file
Verification
Verified with certutil -hashfile <file> MD5 - hash remains identical between reads
No Python, VS Code, or other editor processes running
Seeing this same problem. Started 11/26/2025 and continuing 11/27. Claude Code version 2.0.55.
Platform: Windows (MINGW64_NT-10.0-20348)
Claude Opus tried several different ways to edit the file (sed, full re-write of file) that failed with the same or equivalent error. It was successful using python to do the file edits.
I will just add I am seeing this as well. Running Windows 11. Claude Code 2.0.55. Running in a powershell terminal. I see no edits to the file claude complains about being edited.
Environment:
Claude Code VSCode Extension
Windows 10/11
Directory: D:/Projects/RPGs/Arcanum/[SYS] Memory Bank/
Files affected: 01_State.md, 02_Log.md
Reproduction:
Read file using Read tool — succeeds
Attempt Edit tool on same file — fails with "File has been unexpectedly modified"
Re-read file — succeeds
Re-attempt Edit — fails again with same error
Loop continues indefinitely regardless of retries
Diagnostics performed:
Restarted IDE — no effect
Restarted computer — no effect
Removed read-only file attributes via PowerShell — no effect
Verified no cloud sync (disabled Google Drive sync, killed GDrive/OneDrive processes)
Ran disk check — no errors
Verified basic write access works (echo "test" > test_write.txt succeeds)
No other processes holding file locks
Key observation: Basic file I/O works fine. The issue is isolated to the Edit tool's internal cache/comparison mechanism. The tool appears to compare against a stale cached version rather than the actual file on disk. Workaround used: Bypassed Edit tool entirely using sed -i for inline text replacement. All edits completed successfully via bash, confirming this is an Edit tool-specific issue, not a system-level file access problem. Versions tested: This session occurred on 2025-11-29. Issue persisted through multiple IDE restarts and a full computer reboot.
Not certain this is related, but I'm mainly seeing this issue repeat when Opus is editing files within a skill. I also get prompted with every edit for skills even when I select #2 to accept all edits. Perhaps a permissions bug rather than a cache bug?
Cross-referencing: A verified fix for this issue has been posted at #12805 (comment) - patches the timestamp validation logic in cli.js to bypass the broken Windows detection.
Just hit this bug again on Windows/MINGW. Workaround was using cat > file << 'EOF' via Bash instead of the Edit tool.
Hypothesis on root cause: I suspect CRLF line ending normalization is the culprit.
Git on Windows often has core.autocrlf=true, which converts LF <-> CRLF. If the Read tool normalizes content to LF internally when storing/hashing, but the Edit tool re-reads the raw file (which has CRLF on disk) before comparing, the hashes won't match - triggering a false "file has been unexpectedly modified" error.
A potential fix would be to normalize line endings before hashing, or use a content comparison that's line-ending agnostic.
Environment: Windows 10, MINGW64_NT-10.0-17763, Git Bash
I’ll be more sympathetic to the the idea AGI is near when we don’t have
breaking bugs in the code base that’s supposed to be AGI that the AGI goes
for months without fixing
I analyzed the Claude Code source code and found the root cause.
Root Cause
Claude Code uses file system timestamps (mtimeMs) instead of content hashes to detect file changes. This causes false positives when cloud sync tools (Dropbox, OneDrive), IDE auto-save, or antivirus software touch file metadata without changing content.
Workaround: PreToolUse Hook with Content Hashing
I created a hook that uses SHA256 content hashing instead of timestamps.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Closing as a duplicate of #3513 — please follow and 👍 that issue instead so we can track it in one place. If you think this was closed in error, comment here and we'll reopen.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.
Activity
ryancogswell commentedon Nov 27, 2025
Seeing this same problem. Started 11/26/2025 and continuing 11/27. Claude Code version 2.0.55.
Platform: Windows (MINGW64_NT-10.0-20348)
Claude Opus tried several different ways to edit the file (sed, full re-write of file) that failed with the same or equivalent error. It was successful using python to do the file edits.
visma-mrange commentedon Nov 28, 2025
I will just add I am seeing this as well. Running Windows 11. Claude Code 2.0.55. Running in a powershell terminal. I see no edits to the file claude complains about being edited.
Exzyle-lab commentedon Nov 29, 2025
Environment:
Claude Code VSCode Extension
Windows 10/11
Directory: D:/Projects/RPGs/Arcanum/[SYS] Memory Bank/
Files affected: 01_State.md, 02_Log.md
Reproduction:
Read file using Read tool — succeeds
Attempt Edit tool on same file — fails with "File has been unexpectedly modified"
Re-read file — succeeds
Re-attempt Edit — fails again with same error
Loop continues indefinitely regardless of retries
Diagnostics performed:
Restarted IDE — no effect
Restarted computer — no effect
Removed read-only file attributes via PowerShell — no effect
Verified no cloud sync (disabled Google Drive sync, killed GDrive/OneDrive processes)
Ran disk check — no errors
Verified basic write access works (echo "test" > test_write.txt succeeds)
No other processes holding file locks
Key observation: Basic file I/O works fine. The issue is isolated to the Edit tool's internal cache/comparison mechanism. The tool appears to compare against a stale cached version rather than the actual file on disk. Workaround used: Bypassed Edit tool entirely using sed -i for inline text replacement. All edits completed successfully via bash, confirming this is an Edit tool-specific issue, not a system-level file access problem. Versions tested: This session occurred on 2025-11-29. Issue persisted through multiple IDE restarts and a full computer reboot.
ryancogswell commentedon Dec 1, 2025
Not certain this is related, but I'm mainly seeing this issue repeat when Opus is editing files within a skill. I also get prompted with every edit for skills even when I select #2 to accept all edits. Perhaps a permissions bug rather than a cache bug?
ryancogswell commentedon Dec 4, 2025
Uninstalling Claude Code and reinstalling it, seems to have resolved the issue for me (none of these errors in the last day).
erwinh22 commentedon Dec 6, 2025
Cross-referencing: A verified fix for this issue has been posted at #12805 (comment) - patches the timestamp validation logic in cli.js to bypass the broken Windows detection.
davidrimshnick commentedon Dec 17, 2025
Just hit this bug again on Windows/MINGW. Workaround was using
cat > file << 'EOF'via Bash instead of the Edit tool.Hypothesis on root cause: I suspect CRLF line ending normalization is the culprit.
Git on Windows often has
core.autocrlf=true, which converts LF <-> CRLF. If the Read tool normalizes content to LF internally when storing/hashing, but the Edit tool re-reads the raw file (which has CRLF on disk) before comparing, the hashes won't match - triggering a false "file has been unexpectedly modified" error.A potential fix would be to normalize line endings before hashing, or use a content comparison that's line-ending agnostic.
Environment: Windows 10, MINGW64_NT-10.0-17763, Git Bash
kevinjbradshaw commentedon Dec 24, 2025
Really need to get on this. It makes claude borderline unusable!
davidrimshnick commentedon Dec 24, 2025
LiangMu-Studio commentedon Dec 30, 2025
Root Cause Analysis & Workaround
I analyzed the Claude Code source code and found the root cause.
Root Cause
Claude Code uses file system timestamps (
mtimeMs) instead of content hashes to detect file changes. This causes false positives when cloud sync tools (Dropbox, OneDrive), IDE auto-save, or antivirus software touch file metadata without changing content.Workaround: PreToolUse Hook with Content Hashing
I created a hook that uses SHA256 content hashing instead of timestamps.
Setup:
~/.claude/hooks/PathValidation.ps1~/.claude/settings.jsonClick to expand: settings.json
Click to expand: PathValidation.ps1 (full script)
How it works
Suggested Fix
Consider using content hashing instead of timestamps for file change detection, or as a fallback when timestamp check fails.
webmasterfsd commentedon Jan 1, 2026
I'm getting the same error, Error: File has been unexpectedly modified. Read it again before attempting to write it.
Actually, the issue started when the conversation has compacted automatically or manually. Once it is compacted, the issue has started.
19317362 commentedon Jan 2, 2026
Why Anthropics CAN NOT solve this BUG for SO LONG? It comes everyday for so many users . What's doing on this?
github-actions commentedon Feb 12, 2026
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
bcherny commentedon Aug 19, 2026
Closing as a duplicate of #3513 — please follow and 👍 that issue instead so we can track it in one place. If you think this was closed in error, comment here and we'll reopen.
🤖 Generated with Claude Code
github-actions commentedon Oct 9, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.