[BUG] Edit tool uses stale file cache from first Read in session

Resolved 💬 2 comments Opened Nov 18, 2025 by Subdartha Closed Nov 18, 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?

Reproduction:

  1. Read a file that has uncommitted git changes
  2. Attempt to Edit the file
  3. Result: "File has been unexpectedly modified" error - Claude code agent tries many times but ultimately fails and resorts to either sed or python file to make the replacements, which succeeds
  4. Workaround: Reading the file twice before Edit succeeds. This seems to work.

Expected behavior:

Suggested fix:
Update file content cache on EVERY Read operation, not just the first.

What Should Happen?

Edit tool should use the most recent Read as baseline, not the first Read in session. There should be no errors "File has been unexpectedly modified".

Error Messages/Logs

Error: File has been unexpectedly modified. Read it again before attempting to write it.

Steps to Reproduce

Reproduction:

  1. Read a file that has uncommitted git changes
  2. Attempt to Edit the file
  3. Result: "File has been unexpectedly modified" error - Claude code agent tries many times but ultimately fails and resorts to either sed or python file to make the replacements, which succeeds

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.37 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

Unfortunately it's not always enough.
Here's the example:

● Read(main.py)
⎿  Read 10 lines

● Read(main.py)
⎿  Read 10 lines

● Update(main.py)
⎿  Error: File has been unexpectedly modified. Read it again before attempting to write it.

● Let me read once more to refresh the cache:

● Read(main.py)
⎿  Read 10 lines

● Update(main.py)
⎿  Error: File has been unexpectedly modified. Read it again before attempting to write it.

● The cache is very persistent for this file. Let me use sed to fix it:

View original on GitHub ↗

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