Edit/Write tools fail with 'File has been unexpectedly modified' after Read tool
Open 💬 18 comments Opened Oct 27, 2025 by baldsam
Bug Description
The Edit and Write tools consistently fail with error "File has been unexpectedly modified. Read it again before attempting to write it." even immediately after successfully using the Read tool on the same file.
Reproduction Steps
- Create a file via Bash:
echo "test content" > test.txt - Read the file:
Read(file_path="test.txt")→ Success - Immediately edit the file:
Edit(file_path="test.txt", old_string="test content", new_string="modified")→ Error: "File has been unexpectedly modified"
Expected Behavior
After successfully reading a file, the Edit/Write tools should recognize that the file has been read and allow modifications.
Actual Behavior
Edit/Write tools report "File has been unexpectedly modified" even though:
- No external process modified the file
- The Read tool just successfully read it
- No time has passed between Read and Edit
Additional Evidence
Testing shows this also affects the Write tool:
Read(file_path="test.txt")→ SuccessWrite(file_path="test.txt", content="new")→ Error: "File has not been read yet" (despite just reading it)
Root Cause Analysis
The file state tracking between Read tool and Edit/Write tools appears to be broken:
- Read tool successfully reads files created/modified by Bash
- Edit/Write tools don't recognize that Read occurred
- State is not properly shared between these tools
Impact
This bug forces workarounds:
- Using Python scripts via Bash instead of Edit tool
- Avoiding mixing Bash file modifications with Edit tool
- Significant workflow friction and token waste
Environment
- Platform: Windows 11 with WSL2
- Claude Code CLI version: Latest (as of 2025-10-27)
- Model: claude-sonnet-4-5
Workaround
Use Python for file modifications instead of Edit tool:
uv run python << 'SCRIPT'
from pathlib import Path
file = Path('file.txt')
content = file.read_text()
content = content.replace('old', 'new')
file.write_text(content)
SCRIPT
18 Comments
---
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
---
same issue
I am also seeing this on Windows 11 and v2.0.42
Same here on v2.0.42, i downgraded to 2.0.8 and its working again
Windows 11 here on v2.0.44, same problem. I just downgraded to 2.0.8 as well and so far that seems to be without issues.
Edit: Nope, downgrade didn't help, the issue is back....
If you demand that Claude always use backslashes in read/write/edit commands this goes away. But that's silly, it should already know that.
Systematic Testing Results - Path Separator Bug Confirmed
I've conducted exhaustive testing of all 16 combinations of path formats (relative/absolute × forward/backward slashes) for Read→Edit operations on Windows. Here are the complete results:
Test Matrix Results
| Combo | Read Path Format | Edit Path Format | Result |
|-------|------------------|------------------|--------|
| 1 |
test-dir/file.txt(rel/) |test-dir/file.txt(rel/) | ✅ SUCCESS || 2 |
test-dir/file.txt(rel/) |test-dir\file.txt(rel\) | ✅ SUCCESS || 3 |
test-dir/file.txt(rel/) |C:/st/authz/test-dir/file.txt(abs/) | ❌ FAILED || 4 |
test-dir/file.txt(rel/) |C:\st\authz\test-dir\file.txt(abs\) | ✅ SUCCESS || 5 |
test-dir\file.txt(rel\) |test-dir/file.txt(rel/) | ✅ SUCCESS || 6 |
test-dir\file.txt(rel\) |test-dir\file.txt(rel\) | ✅ SUCCESS || 7 |
test-dir\file.txt(rel\) |C:/st/authz/test-dir/file.txt(abs/) | ❌ FAILED || 8 |
test-dir\file.txt(rel\) |C:\st\authz\test-dir\file.txt(abs\) | ✅ SUCCESS || 9 |
C:/st/authz/test-dir/file.txt(abs/) |test-dir/file.txt(rel/) | ❌ FAILED || 10 |
C:/st/authz/test-dir/file.txt(abs/) |test-dir\file.txt(rel\) | ❌ FAILED || 11 |
C:/st/authz/test-dir/file.txt(abs/) |C:/st/authz/test-dir/file.txt(abs/) | ❌ FAILED * || 12 |
C:/st/authz/test-dir/file.txt(abs/) |C:\st\authz\test-dir\file.txt(abs\) | ❌ FAILED || 13 |
C:\st\authz\test-dir\file.txt(abs\) |test-dir/file.txt(rel/) | ✅ SUCCESS || 14 |
C:\st\authz\test-dir\file.txt(abs\) |test-dir\file.txt(rel\) | ✅ SUCCESS || 15 |
C:\st\authz\test-dir\file.txt(abs\) |C:/st/authz/test-dir/file.txt(abs/) | ❌ FAILED || 16 |
C:\st\authz\test-dir\file.txt(abs\) |C:\st\authz\test-dir\file.txt(abs\) | ✅ SUCCESS |Note: Combo 11 fails with a different error: "File has been unexpectedly modified" instead of "File has not been read yet"
Summary Statistics
Root Cause Analysis
The Edit/Write tools maintain an internal registry of "read files" but use exact string matching without proper Windows path normalization. The issue specifically occurs when:
C:/...) breaks ALL subsequent edit operations regardless of edit path formatC:/...) fails when read path was different formatC:\...) work consistently when used for both read and editWorkaround
Always use backslashes for absolute Windows paths:
Safe patterns:
test-dir/file.txtortest-dir\file.txt(either works)C:\path\to\file.txtTesting Methodology
Each combination was tested with fresh files to avoid caching issues. All failures were verified twice with different filenames to confirm reproducibility. Tests conducted on Windows with Git Bash environment.
I see so many updates to Claude Code - nearly daily. Please can this be fixed?
I have been experiencing this issue on Windows 11 in a 'git bash' window, using starship as my prompt. I traced it back to starships complex prompt corrupting Claude's cache. Below is a writeup by Claude and the updates to my .bashrc that fixed it.
Starship Prompt Causes Cache Corruption and False File Modification Errors in Claude Code
Symptoms
When using https://starship.rs/ prompt with Claude Code on Windows (MSYS2/Git Bash), two issues occur:
Root Cause
Claude Code spawns non-interactive shell sessions for command execution. Starship's ANSI escape sequences (colors, cursor positioning, terminal queries) pollute the output buffer, corrupting:
Solution
Conditionally disable Starship in non-interactive shells by adding this to .bashrc:
How It Works
[[ "$-" == *i* ]]— Checks for interactive shell (Claude uses non-interactive)$TERM_PROGRAM / $WT_SESSION / $ALACRITTY_SOCKET— Verifies real terminal emulatorClaude sessions fail the first check
($- = hBc, no i flag), so Starship never initializes.Environment
Workaround: Add to Global Claude Code Instructions
I found that adding this to the global CLAUDE.md file works reliably. Claude Code reads this file and follows the instructions automatically.
Location: C:\Users\<your-username>\.claude\CLAUDE.md)
Note: Claude Code reads CLAUDE.md files at the start of each conversation, not on every prompt. If you add or modify this file during an existing session, you'll need to start a new conversation (Ctrl+N or /clear) for the changes to take effect or just copy paste the instructions to your existing conversation.
Global Claude Code Instructions
Windows Path Format
On Windows, always use backslashes for absolute file paths in Read/Edit/Write operations:
C:\path\to\project\fileC:/path/to/project/fileThis avoids the "File has been unexpectedly modified" error caused by a path normalization bug in the Claude Code extension.
Relative paths work with either separator.
I've done extensive testing and found an even simpler workaround than using backslashes:
TL;DR: Just use relative paths
Relative paths are "permissive" - they work regardless of how you previously read the file. No need to worry about backslash vs forward slash.
Additional finding: Bug is EXCLUSIVE to Edit tool
The Write tool has no path restrictions - it works with any path format, even without prior Read. This confirms the bug is specifically in Edit's file tracking logic, not a general path issue.
Recommended CLAUDE.md workaround
Add this to your
CLAUDE.mdfor a reliable fix:This is simpler than enforcing backslashes because:
Hope this helps others dealing with this frustrating bug!
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 still exists in version 2.1.39 and is even more severe in Agent teams, occurring almost 100%.
Nothing was fixed at all. People discussed the problem for a long time, and then Anthropic simply auto-closed the issue.
How much money did users waste because of this bug?
Are there any real humans from Anthropic maintaining this repository, or is it all just left to AI now?
Huh, at least it found dup issue among all 5k+ open issues. The sheer number of open issues is insane.
checking if anybody faced this issue for mac. Cant believe such a simple thing like 'Edit' has been ignored by Anthropic for so long....what's happening guys? Should we switch to codex?
This is occurring fairly often for me, usually with larger files. I'm on macOS using the plugin for Visual Studio Code. When I asked for details, the agent said
There's no problem now, I only use codex.
Codex is slightly better than Claude, at least it won't get stuck and completely fail to work.
I am currently working hard to urge OpenAI to fix it