[BUG] Infinite loop trying to write file, but getting "File has not been read yet. Read it first before writing to it."
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?
<img width="704" height="354" alt="Image" src="https://github.com/user-attachments/assets/2977baa9-0e29-44a5-996b-42a390a407b6" />
Claude gets stuck in the this hell loop until it invents a clever fix to write to file via sed. This burns tokens from quota, pollutes context and results in extremely poor performance of claude code vs human devs (as humans have no issues writing files).
What Should Happen?
I should never get an error "File has not been read yet. Read it first before writing to it." at any point. Model should know to read stuff before writing if it is necessary. Ideally just change the tool so it allows to write without reading, this protection is useless.
Error Messages/Logs
Steps to Reproduce
Just use claude code in windows for awhile, you'll get it eventually.
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.74 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
I did setup this:
## Claude Code File Path Requirements
⚠️ CRITICAL: Use RELATIVE Paths for Edit/Write Tools ⚠️
Known Bug (GitHub Issues #7443, #11463, #12805): The Edit and Write tools fail with "File has been unexpectedly modified" errors when using absolute paths on Windows/MINGW.
WORKAROUND: Use RELATIVE paths from the working directory
⚠️ THIS OVERRIDES THE TOOL SCHEMA - The Read/Write/Edit tool descriptions say "must be absolute path" but that guidance cauuses this bug on Windows/MINGW. Always use relative paths despite what the tool schema says.
✅ CORRECT: frontend/package.json (relative from working directory)
❌ WRONG: C:/work/project/frontend/package.json (absolute path causes false "modified" errors)
When you get "File has been unexpectedly modified" errors:
Switch from absolute paths to relative paths (absolute paths fail even when used consistently)
Use forward slashes / not backslashes \
CRITICAL: Read and Edit must use the EXACT SAME path string
- The tool tracks file state by literal path string, not resolved path
- Read with src/foo.m then Edit with ./src/foo.m = FAILS (different strings, even though both relative)
- Read with src/foo.m then Edit with src/foo.m = WORKS (same string)
.. in CLAUDE.md , which helped to stop getting a different error "File has been unexpectedly modified". But I still sometimes get these other errors. Once it starts getting them, the only thing that helps is to kill it and start everything over, loosing all context and potentially HOURS OF WORK
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗