Edit tool fails with "File has been unexpectedly modified" even after (Quite critical bug as it cannot code)
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?
The Edit and MultiEdit tools consistently fail with "File has been unexpectedly
modified. Read it again before attempting to write it." error, even immediately after
reading the file with the Read tool.
Steps to Reproduce
- Use Read tool to read a file
- Immediately use Edit tool to modify the same file
- Get error: "File has been unexpectedly modified. Read it again before attempting
to write it." ## Actual Behavior Edit tool consistently fails, requiring workarounds with Bash/sed commands
What Should Happen?
Expected Behavior
Edit tool should work after reading the file, as it did previously.
Error Messages/Logs
Error: File has been unexpectedly modified. Read it again before attempting to write
it.
Steps to Reproduce
No steps cannot Edit/modify any file requested to modify Write code or repair bugs.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
1.0.100 Not sure
Claude Code Version
1.0.111
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
No response
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/3513
- https://github.com/anthropics/claude-code/issues/5981
- https://github.com/anthropics/claude-code/issues/3182
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
This is NOT duplicate. I am getting same issue after recent patch. THIS IS CRITICAL IN MY WORKFLOW
We really need this fixed is using BAsh SED , to edit. Terrible
Found a workaround for those with this issue , you need to open another claude instance. And instruct other claude what to do where he s left. At least is something....
I am having the same issue with CC and after testing it provided a breakdown: " Environment
- Claude Code Version: v1.0.111
- Platform: Windows 10, Git Bash/MINGW64
- Project: Next.js TypeScript application
Issue
Edit and MultiEdit tools consistently fail with "File has been unexpectedly modified" error when attempting to modify files that existed before the current Claude Code session started.
Reproduction Steps
- Start a new Claude Code session
- Read any pre-existing file using Read tool
- Attempt to Edit the file with exact string from Read output
- Error: "File has been unexpectedly modified"
Test Results
✅ WORKS: Files created with Write tool in current session ❌ FAILS: Any file that existed before session started ✅ WORKS: Multiple edits on newly created files ❌ FAILS: Both Edit and MultiEdit tools affected
Evidence
- File checksums unchanged (MD5: 6a8903f730a6dbde831965e1729dbd1a)
- File timestamps show no modifications
- Issue persists with dev server stopped
- Same file content can be edited if file is recreated in current session
- Session-based state issue: Files become "un-editable" after Claude Code restarts
- Not file-specific: Same file, same content, different session = different behavior
- Consistent pattern: All pre-existing files fail with "unexpectedly modified" error
Root Cause Hypothesis
Claude Code's internal file state tracking appears to be session-based. Files created during the session have proper state initialization, while pre-existing files lack this state, causing all edit operations to fail.
Impact
- Cannot edit any existing project files
- Forced to use workarounds (bash/sed, manual editing)
- Significantly impacts development workflow"
- We successfully downgraded to v1.0.100 - the npm commands showed it worked
- After restart, editing worked perfectly - multiple successful edits on testme.txt
- Something reverted us back to v1.0.111 without our knowledge
- The bug returned once we were back on v1.0.111
Ok I noticed I could edit files fine in another project, so I tested more. Does this correct the problem for anyone else experiencing it? I'm back to editing... " Root Cause Discovery:
- Issue: Path format used by Claude Code
Solution:
- Use relative paths: projectfolder/... instead of E:/Projects/projectfolder/...
- Use forward slashes: / not \
- Start from workspace root: cd /e/projectfolder then use relative paths
Test Results:
- ❌ Absolute path: E:/projectfolder/test.txt - FAILS
- ✅ Relative path: projectfolder/test.txt - WORKS"
This is the conclusion from the tests I made it do, but It has been whacked out today, so take it with a grain of salt.
CRITICAL DISCOVERY: Sequencing Bug Identified
CORRECTED TEST RESULTS:
| Test Sequence | Path Type | Path Given | Read Result | Edit Result | Error Message |
|---|---|---|---|---|---|
| FIRST | absolute | D:/clients/oakley/test1.txt | ✅ Success | ❌ FAIL | "File has been unexpectedly modified" |
| AFTER REL | absolute | D:/clients/oakley/test1.txt | ✅ Success | ✅ SUCCESS | None |
| FIRST | absolute | D:/clients/salem/test2.txt | ✅ Success | ❌ FAIL | "File has been unexpectedly modified" |
| AFTER REL | absolute | D:/clients/salem/test2.txt | ✅ Success | ✅ SUCCESS | None |
| FIRST | absolute | D:/clients/willdev/test3.txt | ✅ Success | ❌ FAIL | "File has been unexpectedly modified" |
| AFTER REL | absolute | D:/clients/willdev/test3.txt | ✅ Success | ✅ SUCCESS | None |
| FIRST | absolute | D:/clients/stateman/test4.txt | ✅ Success | ❌ FAIL | "File has been unexpectedly modified" |
| AFTER REL | absolute | D:/clients/stateman/test4.txt | ✅ Success | ✅ SUCCESS | None |
ROOT CAUSE IDENTIFIED:
File Caching/State Bug: The Edit tool has a caching or file state tracking issue where:
- First absolute path edit on a file fails with "File has been unexpectedly modified"
- After ANY successful relative path edit on the same file, absolute path edits work perfectly
- This suggests the Edit tool maintains some kind of file state cache that gets properly initialized by relative path operations
BUG PATTERN:
- ❌ Cold Start Absolute Edit: Always fails
- ✅ Warmed Up Absolute Edit: Always works (after any successful relative edit)
- ✅ Relative Edit: Always works regardless of state
WORKAROUND: Before editing with absolute paths, always perform a successful relative path edit first to "warm up" the file state cache.
oooof first time ever I actually have to downgrade. just cannot edit anything.
Version 1.0.112 seems to have fixed the issue for me. Thanks!
Version 1.0.112 seems to have fixed the issue for me. Thanks!
No. it is not over. it happens randomly.
I believe this happens when claude tries to edit a file with an mtime in the future - for example, if you copied it from a box in a different timezone or a LLM generated a zip file for you with UTC timestamps but you are in a negative timezone. Workaround is to just touch all the files, or if you're crazy like me I made this hack: https://github.com/markatto/node-stability
Yeah, it is still happening, but it is better. I am having some luck with this prompt:
Current Claude Code Bug Workaround "There's a file modification bug in Claude Code. The workaround is: always use complete absolute Windows paths with drive letters and backslashes for ALL file operations. Apply this rule going forward, not just for this file."
The prompt provided by @trueshot is working properly.
Thank you @trueshot !!
In my opinion, this shouldn't be closed because this issue wasn't fixed on the CC side.
I agree it should not be closed. It is absolutely broken.
Still happening in 113, need urgent attention! I rolled back to 110.
@Gtm-dev-market you mind keeping this open for everybody's benefit please? A prompt is not a fix.
1.0.113 still has this issue.