[BUG] "File has been unexpectedly modified"
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?
Title: Edit/Write tools fail with "File has been unexpectedly modified" after Read due to system-reminder injection
Description:
When attempting to edit a file using the Edit or Write tools, the operation fails repeatedly with one of these errors:
- "File has been unexpectedly modified. Read it again before attempting to write it."
- "File has not been read yet. Read it first before writing to it."
This occurs even immediately after a successful Read operation on the same file.
Steps to reproduce:
- Read a file using the Read tool
- Immediately attempt to Edit or Write to that file
- Error: "File has been unexpectedly modified"
- Read the file again
- Attempt Edit/Write again
- Same error - infinite loop
Root cause (suspected):
The <system-reminder> tags that are injected into tool results appear to mark the file as "modified" from the tool's perspective, even though the actual file content hasn't
changed. Each Read operation triggers a system-reminder injection, which then invalidates the read state.
Workaround:
Create a new file with a different name using Write, then use Bash mv to replace the original:
# Instead of editing original.py directly:
Write new content to original_v2.py
mv original_v2.py original.py
Environment:
- Platform: Windows (MINGW64_NT-10.0)
- Claude Code CLI
Impact:
- Significant time wasted in loops (10+ retry attempts)
- Poor user experience
- Forces use of workaround for basic file editing
---
What Should Happen?
Claude should be able to edit any of the code files
Error Messages/Logs
Steps to Reproduce
I don't know, it happens sometimes but not always
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
Claude Code 2.0.57
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗