claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Edit tool fails with "File has been unexpectedly modified" CRITICAL

Open ksoftkorea-creator opened this issue 1 year ago • 10 comments

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

ksoftkorea-creator avatar Sep 11 '25 11:09 ksoftkorea-creator

Found 1 possible duplicate issue:

  1. 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

github-actions[bot] avatar Sep 11 '25 11:09 github-actions[bot]

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.

mgoulet101 avatar Oct 20 '25 17:10 mgoulet101

I'm also just now experiencing this. It worked fine yesterday but now it cant write any files at all, not even new ones.

czrptr avatar Oct 21 '25 13:10 czrptr

I encountered the same problem under 2 scenarios below (all under windows env):

  1. When I use openspec.
  2. 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 run running in parallel). This process changes the last-modified-time in the system config, which Claude thinks this file has changed. This is my working 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

firezym avatar Oct 22 '25 09:10 firezym

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 with c:\Users\... (backslashes)
  • If you read with c:/Users/... (forward slashes), you must edit with c:/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.

marianoelsztain avatar Oct 27 '25 19:10 marianoelsztain

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.

  1. 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.

  2. Cloud storage tools like OneDrive, Dropbox, or Google Drive can modify files automatically while syncing. Pause synchronization temporarily and check if the problem persists.

  3. 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.

  1. 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.

eltebe avatar Oct 28 '25 14:10 eltebe

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.

mrconway avatar Nov 14 '25 13:11 mrconway

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.

github-actions[bot] avatar Dec 15 '25 10:12 github-actions[bot]

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.

github-actions[bot] avatar Jan 15 '26 10:01 github-actions[bot]

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.

github-actions[bot] avatar Jan 23 '26 14:01 github-actions[bot]