[BUG] Edit/Write tools permanently stuck with "unexpectedly modified" error after initial failure, despite file being unchanged on disk

Resolved 💬 4 comments Opened Mar 13, 2026 by khunjon Closed Apr 12, 2026

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?

After an Edit tool call fails once on a file (due to a legitimate race condition or external modification), subsequent Edit and Write calls to the same file path keep failing with "File has been unexpectedly modified" / "File has been modified since read" — even when the file is provably stable on disk (confirmed via md5 hash check with a 2-second gap). The tool's internal file state tracking never recovers for that file path. Other files in the same session can be edited normally.

What Should Happen?

A fresh Read call should reset the tool's internal state for that file path, allowing a subsequent Edit or Write to succeed. If the file hasn't changed between the Read and the Edit/Write, the operation should proceed.

Error Messages/Logs

Edit tool: "File has been unexpectedly modified. Read it again before attempting to write it."
Write tool: "File has been modified since read, either by the user or by a linter. Read it again before attempting to write it."

Both errors persist across 5+ read-then-edit/write cycles on the same file. Manual verification:

MD5 (.claude/skills/project-audit/SKILL.md) = 5e91a2e1ae16a14cda1d5a46daa33970
# 2 seconds later
MD5 (.claude/skills/project-audit/SKILL.md) = 5e91a2e1ae16a14cda1d5a46daa33970

Steps to Reproduce

  1. Open a session and make a successful Edit to a file (this worked — output format section was updated earlier in the session)
  2. Later in the same session, attempt another Edit to the same file with a different old_string
  3. If the first attempt fails (e.g., due to a timing issue with an external process touching the file), the tool enters a broken state
  4. All subsequent Read → Edit and Read → Write attempts on that file fail with "unexpectedly modified," regardless of how many times you re-read
  5. Edits to other files in the same session continue to work normally
  6. The only recovery is starting a new session

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.74

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

  • The file in question was a .md file in .claude/skills/ — not being touched by any external watcher or auto-commit process
  • Approximately 5 Edit attempts and 1 Write attempt all failed after the initial failure
  • Multiple Read calls between attempts all returned consistent, correct content
  • The session had one prior successful Edit to the same file earlier in the conversation

View original on GitHub ↗

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