[BUG] Write tool overwrites existing file without prior Read
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?
Summary
The Write tool is supposed to fail when attempting to write to an existing file that hasn't been Read first in the current session. Instead, it silently overwrites the file, destroying the previous content with no warning or error.
Actual Behavior
The Write tool succeeds, overwriting the existing file contents entirely. No error, no warning. The previous content is lost.
Impact
- Data loss: Existing file content is silently destroyed
- No recovery: If the file isn't in git, the content is unrecoverable
- Undermines safety model: The Read-before-Write check exists specifically to prevent blind overwrites. When it doesn't fire, the agent has no awareness of what it's destroying.
Context
Encountered during a real session where an agent used the Write tool to create what it thought was a new file. The file actually existed with ~168 lines of content from a previous session's work (a detailed post-run report with bug findings and verification results). The entire file was overwritten with ~22 lines of new content. The previous content was not committed to git and was only recoverable because the user had the diff visible in their terminal.
What Should Happen?
Expected Behavior
Per the Write tool description:
"If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first."
The Write call should be rejected with an error, forcing the agent to Read the file first.
Error Messages/Logs
Steps to Reproduce
Reproduction Steps
- In session A (or manually), create a file with meaningful content:
````
echo "This is important existing content that should not be lost." > /tmp/test-write-bug.md
- Start a new Claude Code session (session B)
- In session B, ask Claude to write new content to that same file path — but do NOT read it first. For example:
> "Write 'Hello world' to /tmp/test-write-bug.md"
- Expected: The Write tool should error with something like "You must Read this file before overwriting it"
- Actual: The Write tool succeeds. The original content ("This is important existing content...") is gone, replaced with "Hello world"
Key Conditions
- The file must exist on disk but must NOT have been Read in the current session
- The file must not be tracked in the conversation's Read history (i.e., was created in a previous session or by another process)
- The Write tool description says it "will fail" in this case, but it does not
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.110
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗