[BUG] Write tool fails with false positives when IDE opens files, causing token waste and slow UX
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?
When Claude Code attempts to write generated code to files, the Write tool's safety mechanism frequently triggers false positives and blocks the write operation. This occurs even when the user hasn't edited the file - simply opening it in an IDE is enough to trigger the safety check.
Note: This is a macOS/cross-platform variant of existing file modification detection issues (see #7918, #9614, #10123, #10437). While those issues focus on Windows path handling and general false positives, this report specifically documents the IDE interaction trigger and metadata vs content distinction.
The safety mechanism checks file modification time (mtime) instead of actual file content, causing it to reject writes when only metadata has changed. This is particularly problematic when:
- Claude Code generates large blocks of code (400-1000+ lines)
- User's IDE automatically opens, previews, or updates file metadata
- Write operation fails despite no actual content changes
- Claude Code must re-read the file and regenerate/retry the write
- This wastes significant tokens and context window space
Impact:
- Token waste: Every failed write requires re-reading the file and potentially regenerating code
- Context window waste: Failed attempts consume limited conversation context
- Slow developer experience: Adds 5-30+ seconds of retry delay per failure
- Frustrating UX: Users see confusing errors for actions they didn't take
- Compounds over time: Multiple file operations in a session amplify the problem
What Should Happen?
The Write tool's safety mechanism should:
- Check content hash instead of modification time
- Only block writes if actual file content has changed
- Ignore metadata-only changes (mtime, atime, IDE state)
- Auto-retry intelligently
- When metadata-only changes are detected, automatically re-read and retry
- Don't require manual intervention or waste tokens on regeneration
- Be transparent
- Show users when and why a write was blocked
- Distinguish between "user edited file" vs "metadata changed"
Expected workflow:
1. Claude Code reads file
2. User opens file in IDE (metadata changes)
3. Claude Code writes → Safety check detects only metadata changed
4. Write succeeds (or auto-retries once if needed)
5. No token waste, no delay, no user confusion
Error Messages/Logs
When the issue occurs, users see two error messages:
**1. Brief UI message:**
⏺ Write(file_path)
⎿ Error writing file
**2. Detailed error message (in error details/logs):**
File has been modified since read, either by the user or by a linter.
Read it again before attempting to write it.
The detailed error is technically correct but misleading - it triggers on **metadata changes** (modification time), not actual content changes. The brief UI message provides no context about what went wrong or how to fix it.
**Note**: The detailed error message is the same as reported in #7918, #9614, #10123, and #10437, but with a different trigger mechanism (IDE interaction vs path handling/file size/state tracking).
Steps to Reproduce
Requirements:
- Claude Code CLI
- A Solidity project with
forgeinstalled - An IDE that auto-opens or previews files (VS Code, etc.)
Reproduction Steps:
- Create a minimal test file in your project:
```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
contract TestWrite {
uint256 public value;
}
``contracts/TestWriteBug.sol`
Save as
- In Claude Code, run this sequence:
```
Step 1: Read the file
> Read contracts/TestWriteBug.sol
Step 2: Open file in IDE and save it (even with no content changes) - The save operation updates the file's modification time without changing content
> (Open contracts/TestWriteBug.sol in VS Code or your IDE)
Step 3: Attempt to write new content WITHOUT re-reading
> Write this to contracts/TestWriteBug.sol:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
contract TestWriteBug {
uint256 public value;
uint256 public anotherValue;
function setValue(uint256 _value) public {
value = _value;
}
}
```
- Observe the error:
````
File has been modified since read, either by the user or by a linter.
Read it again before attempting to write it.
- Verify no content actually changed:
``bash``
# The file content is still the original - only metadata changed
cat contracts/TestWriteBug.sol
# Shows original content, but modification time is updated
stat contracts/TestWriteBug.sol
Key Finding:
- If you don't open the file in your IDE (step 3), the write succeeds
- If you do open the file in your IDE, the write fails
- The file content is identical in both cases - only metadata differs
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.28
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗