[BUG] Edit Tool False Positive "File has been unexpectedly modified" on Windows
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?
Environment:
- OS: Windows (Git Bash)
- File System: NTFS
- Date: 2025-11-29
Issue:
The Edit tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when
no external process is modifying files.
Steps to Reproduce:
- Close all IDEs (IntelliJ IDEA, VS Code, etc.)
- Create a new test file:
echo "test" > test.txt - Use Read tool to read the file
- Immediately use Edit tool to modify the file
- Error occurs: "File has been unexpectedly modified"
Expected Behavior:
Edit tool should successfully modify the file when no actual modifications have occurred.
Actual Behavior:
Edit tool always fails, even on newly created files that no process has touched.
Investigation Performed:
- ✅ Confirmed no IDE processes running (IntelliJ closed)
- ✅ Confirmed no cloud sync services running (Dropbox, OneDrive, etc.)
- ✅ Confirmed no build tool daemons (Maven, Gradle)
- ✅ Confirmed no file watchers or antivirus active scanning
- ✅ Verified file timestamps are completely stable:
Modify: 2025-11-29 08:43:49.645051300 -0800
Timestamp unchanged over multiple checks
- ✅ Verified file hash (md5sum) remains stable
- ✅ Tested with brand new file - still fails
- ✅ Bash file operations (sed, cat, mv) work perfectly
Root Cause Hypothesis:
The Edit tool's file modification detection logic appears to have issues on Windows NTFS file systems, possibly related to:
- High-precision nanosecond timestamps causing comparison issues
- Internal metadata caching or state management bug
- Race condition when Read and Edit are used in quick succession
Workaround:
Use bash commands instead of Edit tool:
```bash
sed -i 's/old/new/' file.txt # Works reliably
Impact:
Severe - Edit tool is unusable on Windows, forcing users to use bash workarounds for all file modifications.
What Should Happen?
Environment:
- OS: Windows (Git Bash)
- File System: NTFS
- Date: 2025-11-29
Issue:
The Edit tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when
no external process is modifying files.
Steps to Reproduce:
- Close all IDEs (IntelliJ IDEA, VS Code, etc.)
- Create a new test file:
echo "test" > test.txt - Use Read tool to read the file
- Immediately use Edit tool to modify the file
- Error occurs: "File has been unexpectedly modified"
Expected Behavior:
Edit tool should successfully modify the file when no actual modifications have occurred.
Actual Behavior:
Edit tool always fails, even on newly created files that no process has touched.
Investigation Performed:
- ✅ Confirmed no IDE processes running (IntelliJ closed)
- ✅ Confirmed no cloud sync services running (Dropbox, OneDrive, etc.)
- ✅ Confirmed no build tool daemons (Maven, Gradle)
- ✅ Confirmed no file watchers or antivirus active scanning
- ✅ Verified file timestamps are completely stable:
Modify: 2025-11-29 08:43:49.645051300 -0800
Timestamp unchanged over multiple checks
- ✅ Verified file hash (md5sum) remains stable
- ✅ Tested with brand new file - still fails
- ✅ Bash file operations (sed, cat, mv) work perfectly
Root Cause Hypothesis:
The Edit tool's file modification detection logic appears to have issues on Windows NTFS file systems, possibly related to:
- High-precision nanosecond timestamps causing comparison issues
- Internal metadata caching or state management bug
- Race condition when Read and Edit are used in quick succession
Workaround:
Use bash commands instead of Edit tool:
```bash
sed -i 's/old/new/' file.txt # Works reliably
Impact:
Severe - Edit tool is unusable on Windows, forcing users to use bash workarounds for all file modifications.
Error Messages/Logs
Steps to Reproduce
Environment:
- OS: Windows (Git Bash)
- File System: NTFS
- Date: 2025-11-29
Issue:
The Edit tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when
no external process is modifying files.
Steps to Reproduce:
- Close all IDEs (IntelliJ IDEA, VS Code, etc.)
- Create a new test file:
echo "test" > test.txt - Use Read tool to read the file
- Immediately use Edit tool to modify the file
- Error occurs: "File has been unexpectedly modified"
Expected Behavior:
Edit tool should successfully modify the file when no actual modifications have occurred.
Actual Behavior:
Edit tool always fails, even on newly created files that no process has touched.
Investigation Performed:
- ✅ Confirmed no IDE processes running (IntelliJ closed)
- ✅ Confirmed no cloud sync services running (Dropbox, OneDrive, etc.)
- ✅ Confirmed no build tool daemons (Maven, Gradle)
- ✅ Confirmed no file watchers or antivirus active scanning
- ✅ Verified file timestamps are completely stable:
Modify: 2025-11-29 08:43:49.645051300 -0800
Timestamp unchanged over multiple checks
- ✅ Verified file hash (md5sum) remains stable
- ✅ Tested with brand new file - still fails
- ✅ Bash file operations (sed, cat, mv) work perfectly
Root Cause Hypothesis:
The Edit tool's file modification detection logic appears to have issues on Windows NTFS file systems, possibly related to:
- High-precision nanosecond timestamps causing comparison issues
- Internal metadata caching or state management bug
- Race condition when Read and Edit are used in quick succession
Workaround:
Use bash commands instead of Edit tool:
```bash
sed -i 's/old/new/' file.txt # Works reliably
Impact:
Severe - Edit tool is unusable on Windows, forcing users to use bash workarounds for all file modifications.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
not sure
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
Environment:
- OS: Windows (Git Bash)
- File System: NTFS
- Date: 2025-11-29
Issue:
The Edit tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when
no external process is modifying files.
Steps to Reproduce:
- Close all IDEs (IntelliJ IDEA, VS Code, etc.)
- Create a new test file:
echo "test" > test.txt - Use Read tool to read the file
- Immediately use Edit tool to modify the file
- Error occurs: "File has been unexpectedly modified"
Expected Behavior:
Edit tool should successfully modify the file when no actual modifications have occurred.
Actual Behavior:
Edit tool always fails, even on newly created files that no process has touched.
Investigation Performed:
- ✅ Confirmed no IDE processes running (IntelliJ closed)
- ✅ Confirmed no cloud sync services running (Dropbox, OneDrive, etc.)
- ✅ Confirmed no build tool daemons (Maven, Gradle)
- ✅ Confirmed no file watchers or antivirus active scanning
- ✅ Verified file timestamps are completely stable:
Modify: 2025-11-29 08:43:49.645051300 -0800
Timestamp unchanged over multiple checks
- ✅ Verified file hash (md5sum) remains stable
- ✅ Tested with brand new file - still fails
- ✅ Bash file operations (sed, cat, mv) work perfectly
Root Cause Hypothesis:
The Edit tool's file modification detection logic appears to have issues on Windows NTFS file systems, possibly related to:
- High-precision nanosecond timestamps causing comparison issues
- Internal metadata caching or state management bug
- Race condition when Read and Edit are used in quick succession
Workaround:
Use bash commands instead of Edit tool:
```bash
sed -i 's/old/new/' file.txt # Works reliably
Impact:
Severe - Edit tool is unusable on Windows, forcing users to use bash workarounds for all file modifications.
11 Comments
It takes multiple attempts to edit any file and eats all my money very quickly.
This has been ongoing for over 2 months now for me the work around i found is i have to tell claude "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." this resolves the issue i need to reiterate this in each new session or after each compaction I add it to claude.md but it still sometimes forgets on an fresh session
Can you help provide more details around your configurations and repro steps?
claude --debug, anycygpatherrors appear in the log file?This bug is made claude code unusable for our team. We're using native windows which has always been poorly supported, but this one has caused us no end of issues. That workaround doesn't work.
It's broken on windows, but there is workaround to configure special
command on session startup so it works fine.
Just Google Claude bug reading files on windows.
On Fri, Dec 5, 2025, 4:09 PM ant-kurt @.***> wrote:
Here's the workaround that Claude devised:
ME: i want to resolve "File has been unexpectedly modified". create junk.py in the project root. try and edit it like before
Write
source/junk.py
"""Test file for debugging file modification issues."""
def hello():
return "world"
Read source/junk.py
Edit source/junk.py
File has been unexpectedly modified. Read it again before attempting to write it.
There it is. Something is modifying the file between my Read and Edit. Let me check the timing:
Bash
stat "source/junk.py" && sleep 1 && stat "source/junk.py"
Modify: 2025-12-26 15:50:03.086423600 +0100
Change: 2025-12-26 15:50:03.088424700 +0100
Birth: 2025-12-26 15:50:03.086423600 +0100
... +13 lines
The Access time changed between the two stat calls (from 15:50:15 to 15:50:21) but Modify didn't. The issue isn't file content changing - it's likely that Claude Code's file watcher is using access time (atime) rather than modification time (mtime) to detect changes.
When I Read a file, it updates the access time. Then when I try to Edit, the system sees the atime changed and thinks the file was "modified".
This is likely a Windows NTFS behavior or a bug in how Claude Code tracks file changes. The workaround is to read and edit in quick succession or use Bash/Python to write files directly.
ME: devise an elegant fix
Let me look at how Claude Code might be detecting file changes:
Bash
cd "source" && python -c " import os...
... +8 lines
Confirmed: only atime changes on read, not mtime or content hash.
The elegant fix would be a small utility that wraps file operations and uses content hashing instead of timestamps.
ME: write this up, compactly, to add to claude.md
I need to write up the Windows file modification detection bug fix compactly for CLAUDE.md. Let me add this to the CLAUDE.md file:
Edit source\CLAUDE.md
<tool_use_error>File has not been read yet. Read it first before writing to it.</tool_use_error>
The irony! Let me read the file first: ME: HILARIOUS, ROFL
ME: Write source\editw.py
"""Windows-safe file edit via Bash. Replaces Claude's Edit tool."""
Done. Created: editw.py - Windows-safe edit script that:
Takes file path, old_string, new_string as arguments
Validates old_string exists and is unique
Performs replacement and writes back
No timestamp-based change detection
Updated CLAUDE.md with usage instructions:
Known Issue: Windows "File Unexpectedly Modified"
Problem: On Windows/NTFS, reading a file updates its atime. Claude Code detects this as "modification", causing false Edit failures after Read.
Workaround: Use
editw.pyinstead of the Edit tool:ME: now modify junk.py to test it
Edit Source\junk.py
"""Test file for debugging file modification issues."""
def hello():
return "world"
return "moon"
Done. Changed return "world" to return "moon" in junk.py.
ME: let's hope someone on github gives you stars for fixing your own SNAFU
Recognized ironic self-fix situation, prepared humorous acknowledgment.Maurice is making a humorous/ironic point that:
Claude (the AI/Anthropic) has a bug in its Edit tool on Windows
Claude (me, the AI assistant) helped devise a workaround (editw.py)
Now he's sarcastically hoping people on GitHub will "give stars" to Claude for fixing Claude's own bug
It's a SNAFU (Situation Normal: All Fucked Up) - Claude's own tool is broken and Claude had to fix it.
I should acknowledge the irony with appropriate British humour, not take it too seriously, and definitely not make excuses for Anthropic's bug.Fair point. The irony isn't lost on me—Claude Code's Edit tool breaks itself by reading files, then Claude (me) has to write a workaround script to bypass Claude Code's buggy change detection.
Classic SNAFU.
At least the workaround is simple and your GitHub issue documents it well for others hitting the same Windows/NTFS false positive. Hopefully Anthropic fixes the atime vs mtime confusion in the actual tool rather than relying on users to write their own wrappers.
Until then, editw.py works and you've got Filesystem MCP as backup.
I encountered this issue this morning and Claude Code (Opus 4.5) thought the following might be useful:
Key finding: Write tool "resets" the broken state for individual files
After experiencing consistent Edit failures across multiple files, I used the Write tool to completely overwrite one file's contents. After that, subsequent Edit operations on that specific file started working again, while other files that hadn't been overwritten via Write continued to fail.
This suggests the bug is in how Edit tracks/caches file state internally, and that Write properly resets this tracking while Edit compares against stale or corrupted cached metadata.
Session characteristics:
Answering @anthropics/claude-code-team's diagnostic questions:
Suggested diagnostic approach: Compare how Write vs Edit update their internal file tracking state after an operation. Write likely replaces the tracked checksum/timestamp entirely, while Edit may be comparing against cached state that has become invalid. The fact that Write "fixes" a file strongly points to a state management issue rather than an actual filesystem race condition.
Happen usually, since 1.0.xxx version. Edit failed then it trying to use tool like "sed" to edit file (but still failed)
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.