[BUG] Edit tool fails with "File has been unexpectedly modified" CRITICAL
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?
EDIT AND UPDATE TOOL DOES NOT WORK. ONLY NEW FILE WRITE WORKS.
RECENT VERSION PATCH CREATED CRITICAL ISSUE
IT KEEPS READ UPDATE FAIL READ UPDATE FAIL READ UPDATE FAIL READ UPDATE FAIL
THIS IS EMERGENCY BUG THAT NEEDS TO BE HANDLED IMMEDIATELY
What Should Happen?
Edit successfully after read
Error Messages/Logs
Steps to Reproduce
Edit existing file
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
Any before most recent version
Claude Code Version
1.0.111
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
No response
Found 1 possible duplicate issue:
- https://github.com/anthropics/claude-code/issues/7443
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and š the existing issue instead
- To prevent auto-closure, add a comment or š this comment
š¤ Generated with Claude Code
https://github.com/anthropics/claude-code/issues/7443 is locked - would have updated that one. This is still happening to me:
- CC v2.0.22
- Windows
- CC running in PowerShell within vscode using the plugin (configured in Terminal Mode, not native)
Error: File has been unexpectedly modified. Read it again before attempting to write it.
It's intermittent for sure. But it also happened once over the weekend, in the middle of a long session that I was loath to restart. Really frustrating. We had a possibly-false belief that the problem is worse running CC in a Git Bash, which is why I'm running it in a PowerShell, but it clearly still can happen.
I'm also just now experiencing this. It worked fine yesterday but now it cant write any files at all, not even new ones.
I encountered the same problem under 2 scenarios below (all under windows env):
- When I use openspec.
- When I use 2 concurrent Claude Code sessions for one project, editing different file.
I searched the web there is one post think might addressed the issue:
Apparently, whenever we have another application accessing the same folder (e.g., we have a second instance of claude making changes to the same directory OR we have a
flutter runrunning in parallel). This process changes thelast-modified-timein the system config, which Claude thinks this file has changed. This is myworking hypothesis, there is no documentation on this idea, for the record.
https://www.reddit.com/r/ClaudeAI/comments/1l7ilhu/comment/mxs5y44/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
I've been getting this error for about a week on every edit on the VSC extension, but not at all on the CLI. My tests show that the issue is when CC uses a different backslash vs. forwardslash format on the file paths between read and write. For example, it reads file "D:\repos\project\file.tsx" and then tries to write on file "D:/repos/project/file.tsx". So I've added this section to my CLAUDE.md file:
CRITICAL: File Editing on Windows
ā ļø Path Consistency Requirement for Edit Tools
When using Read/Edit/Write tools on Windows, you MUST be consistent with path format within the same file operation sequence.
The Rule: Path Format Consistency
The Edit tool tracks which files have been read during the session based on the exact path format used. Before editing a file, it checks if that file was previously read using the same path format.
- If you read with
c:\Users\...(backslashes), you must edit withc:\Users\...(backslashes) - If you read with
c:/Users/...(forward slashes), you must edit withc:/Users/...(forward slashes) - Mixing path formats causes "File has not been read yet" errors
ā BEST PRACTICE: Use Backslashes (Windows Convention)
Read(file_path: "c:\Users\Maria\project\file.tsx")
Edit(file_path: "c:\Users\Maria\project\file.tsx", ...)
ā ļø ALSO WORKS: Forward Slashes (If Consistent)
Read(file_path: "c:/Users/Maria/project/file.tsx")
Edit(file_path: "c:/Users/Maria/project/file.tsx", ...)
ā WRONG - Mixing Formats Causes Errors:
Read(file_path: "c:\Users\Maria\project\file.tsx")
Edit(file_path: "c:/Users/Maria/project/file.tsx", ...) // ERROR: File not read yet
Recommendation: Always use backslashes on Windows for consistency with Windows conventions and to avoid confusion.
In most cases antivirus real-time scanning or cloud synchronization services are responsible for such file modification errors. Start by checking and adjusting those, then use Process Explorer or ProcMon to confirm the specific culprit.
-
Many antivirus or endpoint protection tools (like Windows Defender, Avast, Bitdefender, or McAfee) actively scan and temporarily lock files while they are being written. Try temporarily disabling real-time protection or adding the folder to the antivirus exclusions list to see if the issue disappears. If the error stops, the antivirus is likely the cause. You can then fine-tune its settings rather than turning it off completely.
-
Cloud storage tools like OneDrive, Dropbox, or Google Drive can modify files automatically while syncing. Pause synchronization temporarily and check if the problem persists.
-
Disable indexing or real-time backup tools File indexing or backup software (like Windows Search Indexer, Acronis, or similar) can also change timestamps or metadata. Try pausing or disabling them temporarily.
You can use Process Monitor (ProcMon) from Sysinternals to record file system activity. Apply a filter for the specific file path and look for WriteFile or SetInformationFile operations. This helps identify which process modifies the file unexpectedly.
- IDE (like VS Code or JetBrains tools) use features such as auto save, auto format on save, code cleanup on save, Hot Reload, and so on. Which can conflict with external tools writing to the same files simultaneously, and cause race condition.
On Windows, antivirus or Defender is almost always the culprit ā causing slowdowns, file write or lock issues ā so Iād suggest starting by checking that first.
Just to add this to issue, when you're working on OneDrive, the file system drives Claude Code completely nuts. So, CC attempts to use the various Read/Write tools, sed/awk, even Python scripts -- resulting in a lot of file corruption. Using Python scripts eventually turns out to be the best solution, but it's a roundabout process.
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.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
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.