[BUG] Edit tool fails with "File has been unexpectedly modified" on unmodified files

Resolved 💬 4 comments Opened Dec 18, 2025 by StorebuilderUK Closed Dec 22, 2025

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?

Title: Edit tool fails with "File has been unexpectedly modified" on unmodified files

Environment:

  • Claude Code v2.0.72
  • Windows 10/11
  • Model: Opus 4.5

Description:
The Edit/Update tool consistently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when:

  1. The file has not been modified
  2. Reading and editing happen in immediate succession
  3. It's a fresh session with no prior context

Reproduction steps:

  1. Start fresh Claude Code session
  2. Read any file: Read file X
  3. Immediately request an edit: Write "test" to the top of file X
  4. Edit fails with "unexpectedly modified" error
  5. Re-read the file
  6. Try edit again - still fails

Diagnostic evidence:

File hash remains constant before, during, and after failed edits:
certutil -hashfile "file.md" MD5
# Returns same hash: d2589ea81be4b71471b0dbed440e59bb
# 3 seconds later - same hash
# After failed edit - same hash

Tested and ruled out:

  • OneDrive sync (not running)
  • Windows Search Indexer
  • Antivirus interference
  • VS Code auto-save (closed)
  • Multiple Claude Code sessions (all closed)
  • Session compaction/context continuation
  • CRLF vs LF line endings (converted to LF, still fails)
  • File-specific issues (reproduced on newly created test files)

Workaround:
Using Python/sed/Bash to edit files directly works fine - only the Edit tool's internal comparison is broken.

python -c "
with open('file.md', 'r') as f: content = f.read()
content = content.replace('old', 'new')
with open('file.md', 'w') as f: f.write(content)
"

Expected behaviour:
Edit should succeed when the file content matches what was just read.

Actual behaviour:
Edit fails claiming file was modified, even when hash proves it wasn't.

What Should Happen?

Expected behaviour:
Edit should succeed when the file content matches what was just read.

Error Messages/Logs

● Update(clients\anglia_labels\client_success\week_51\visibility_intelligence_week_51.md)
  ⎿  Error: File has been unexpectedly modified. Read it again before attempting to write
     it.

Steps to Reproduce

Reproduction steps:

  1. Start fresh Claude Code session
  2. Read any file: Read file X
  3. Immediately request an edit: Write "test" to the top of file X
  4. Edit fails with "unexpectedly modified" error
  5. Re-read the file
  6. Try edit again - still fails

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

Claude Code v2.0.72

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗