[BUG] Edit Tool "File has been unexpectedly modified" Errors

Resolved 💬 3 comments Opened Oct 30, 2025 by DatabaseDat Closed Nov 3, 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?

Environment:

  • OS: Windows (win32)
  • Platform: Local by Flywheel WordPress environment
  • Claude Code Version: [You'll need to add this - check with claude --version]
  • Working Directory: WordPress plugin development

Issue Description:

The Edit tool consistently fails with "File has been unexpectedly modified" errors, even when:

  1. No external file watchers are running
  2. The target file is not open in any editor
  3. The file has not been modified by any external process
  4. File timestamps show no changes between Read and Edit operations

Investigation Results:

  • VS Code auto-save is configured but VS Code is not running during failures
  • No file watcher processes detected (nodemon, gulp, webpack, etc.)
  • File modification timestamps remain unchanged between Read and Edit calls
  • Only 7 background processes running (minimal system state)
  • File is accessible and not locked (verified by successful Node.js write operations)

Workaround:

Using Node.js file operations bypasses the issue:
node -e "const fs = require('fs'); const content = fs.readFileSync('file.js', 'utf8'); const updated = content.replace('old', 'new'); fs.writeFileSync('file.js', updated, 'utf8');"

Expected Behavior:

Edit tool should successfully apply changes when file state is genuinely unchanged.

Actual Behavior:

Edit tool incorrectly detects file modifications and refuses to apply edits, even when no modifications occurred.

Additional Context:

  • Issue occurs consistently across multiple edit attempts
  • Affects large JavaScript files (42k+ tokens)
  • Reading file in chunks (with offset/limit) doesn't resolve the issue
  • Problem persists even after system reboots

Hypothesis:

The Edit tool's file-state verification mechanism may be overly sensitive or have timing issues related to:

  • File system caching on Windows
  • Large file handling
  • Hash/timestamp comparison logic

What Should Happen?

Should've been able to edit the files just fine.

Error Messages/Logs

Steps to Reproduce

Reproduction Steps:

  1. Use Read tool to read a file (e.g., entity-manager.js)
  2. Immediately attempt to use Edit tool with exact string match from Read output
  3. Edit tool fails with: "File has been unexpectedly modified. Read it again before attempting to write it."
  4. Re-reading the file and retrying produces the same error repeatedly

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.29 (Claude code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

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