claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Edit tool fails with "File has been unexpectedly modified" even after (Quite critical bug as it cannot code)

Open Gtm-dev-market opened this issue 1 year ago • 57 comments

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?

The Edit and MultiEdit tools consistently fail with "File has been unexpectedly modified. Read it again before attempting to write it." error, even immediately after
reading the file with the Read tool.

Steps to Reproduce

  1. Use Read tool to read a file
  2. Immediately use Edit tool to modify the same file
  3. Get error: "File has been unexpectedly modified. Read it again before attempting
    to write it." ## Actual Behavior Edit tool consistently fails, requiring workarounds with Bash/sed commands

What Should Happen?

Expected Behavior

Edit tool should work after reading the file, as it did previously.

Error Messages/Logs

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

Steps to Reproduce

No steps cannot Edit/modify any file requested to modify Write code or repair bugs.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

1.0.100 Not sure

Claude Code Version

1.0.111

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

No response

Gtm-dev-market avatar Sep 11 '25 10:09 Gtm-dev-market

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/3513
  2. https://github.com/anthropics/claude-code/issues/5981
  3. https://github.com/anthropics/claude-code/issues/3182

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Sep 11 '25 10:09 github-actions[bot]

This is NOT duplicate. I am getting same issue after recent patch. THIS IS CRITICAL IN MY WORKFLOW

ksoftkorea-creator avatar Sep 11 '25 11:09 ksoftkorea-creator

We really need this fixed is using BAsh SED , to edit. Terrible

Gtm-dev-market avatar Sep 11 '25 11:09 Gtm-dev-market

Found a workaround for those with this issue , you need to open another claude instance. And instruct other claude what to do where he s left. At least is something....

Gtm-dev-market avatar Sep 11 '25 15:09 Gtm-dev-market

I am having the same issue with CC and after testing it provided a breakdown: " Environment

  • Claude Code Version: v1.0.111
  • Platform: Windows 10, Git Bash/MINGW64
  • Project: Next.js TypeScript application

Issue

Edit and MultiEdit tools consistently fail with "File has been unexpectedly modified" error when attempting to modify files that existed before the current Claude Code session started.

Reproduction Steps

  1. Start a new Claude Code session
  2. Read any pre-existing file using Read tool
  3. Attempt to Edit the file with exact string from Read output
  4. Error: "File has been unexpectedly modified"

Test Results

✅ WORKS: Files created with Write tool in current session ❌ FAILS: Any file that existed before session started ✅ WORKS: Multiple edits on newly created files ❌ FAILS: Both Edit and MultiEdit tools affected

Evidence

  • File checksums unchanged (MD5: 6a8903f730a6dbde831965e1729dbd1a)
  • File timestamps show no modifications
  • Issue persists with dev server stopped
  • Same file content can be edited if file is recreated in current session
  • Session-based state issue: Files become "un-editable" after Claude Code restarts
  • Not file-specific: Same file, same content, different session = different behavior
  • Consistent pattern: All pre-existing files fail with "unexpectedly modified" error

Root Cause Hypothesis

Claude Code's internal file state tracking appears to be session-based. Files created during the session have proper state initialization, while pre-existing files lack this state, causing all edit operations to fail.

Impact

  • Cannot edit any existing project files
  • Forced to use workarounds (bash/sed, manual editing)
  • Significantly impacts development workflow"

Norsninja avatar Sep 11 '25 16:09 Norsninja

  1. We successfully downgraded to v1.0.100 - the npm commands showed it worked
  2. After restart, editing worked perfectly - multiple successful edits on testme.txt
  3. Something reverted us back to v1.0.111 without our knowledge
  4. The bug returned once we were back on v1.0.111

trueshot avatar Sep 11 '25 17:09 trueshot

Ok I noticed I could edit files fine in another project, so I tested more. Does this correct the problem for anyone else experiencing it? I'm back to editing... " Root Cause Discovery:

  • Issue: Path format used by Claude Code

Solution:

  1. Use relative paths: projectfolder/... instead of E:/Projects/projectfolder/...
  2. Use forward slashes: / not \
  3. Start from workspace root: cd /e/projectfolder then use relative paths

Test Results:

  • ❌ Absolute path: E:/projectfolder/test.txt - FAILS
  • ✅ Relative path: projectfolder/test.txt - WORKS"

Norsninja avatar Sep 11 '25 18:09 Norsninja

This is the conclusion from the tests I made it do, but It has been whacked out today, so take it with a grain of salt.

CRITICAL DISCOVERY: Sequencing Bug Identified

CORRECTED TEST RESULTS:

Test Sequence Path Type Path Given Read Result Edit Result Error Message
FIRST absolute D:/clients/oakley/test1.txt ✅ Success ❌ FAIL "File has been unexpectedly modified"
AFTER REL absolute D:/clients/oakley/test1.txt ✅ Success ✅ SUCCESS None
FIRST absolute D:/clients/salem/test2.txt ✅ Success ❌ FAIL "File has been unexpectedly modified"
AFTER REL absolute D:/clients/salem/test2.txt ✅ Success ✅ SUCCESS None
FIRST absolute D:/clients/willdev/test3.txt ✅ Success ❌ FAIL "File has been unexpectedly modified"
AFTER REL absolute D:/clients/willdev/test3.txt ✅ Success ✅ SUCCESS None
FIRST absolute D:/clients/stateman/test4.txt ✅ Success ❌ FAIL "File has been unexpectedly modified"
AFTER REL absolute D:/clients/stateman/test4.txt ✅ Success ✅ SUCCESS None

ROOT CAUSE IDENTIFIED:

File Caching/State Bug: The Edit tool has a caching or file state tracking issue where:

  1. First absolute path edit on a file fails with "File has been unexpectedly modified"
  2. After ANY successful relative path edit on the same file, absolute path edits work perfectly
  3. This suggests the Edit tool maintains some kind of file state cache that gets properly initialized by relative path operations

BUG PATTERN:

  • ❌ Cold Start Absolute Edit: Always fails
  • ✅ Warmed Up Absolute Edit: Always works (after any successful relative edit)
  • ✅ Relative Edit: Always works regardless of state

WORKAROUND: Before editing with absolute paths, always perform a successful relative path edit first to "warm up" the file state cache.

trueshot avatar Sep 11 '25 19:09 trueshot

oooof first time ever I actually have to downgrade. just cannot edit anything.

kohowski avatar Sep 11 '25 21:09 kohowski

Version 1.0.112 seems to have fixed the issue for me. Thanks!

trueshot avatar Sep 12 '25 11:09 trueshot

Version 1.0.112 seems to have fixed the issue for me. Thanks!

No. it is not over. it happens randomly.

Adamcf123 avatar Sep 12 '25 22:09 Adamcf123

I believe this happens when claude tries to edit a file with an mtime in the future - for example, if you copied it from a box in a different timezone or a LLM generated a zip file for you with UTC timestamps but you are in a negative timezone. Workaround is to just touch all the files, or if you're crazy like me I made this hack: https://github.com/markatto/node-stability

markatto avatar Sep 12 '25 22:09 markatto

Yeah, it is still happening, but it is better. I am having some luck with this prompt:

Current Claude Code Bug Workaround "There's a file modification bug in Claude Code. The workaround is: always use complete absolute Windows paths with drive letters and backslashes for ALL file operations. Apply this rule going forward, not just for this file."

trueshot avatar Sep 13 '25 09:09 trueshot

The prompt provided by @trueshot is working properly.

SaidKSI avatar Sep 13 '25 19:09 SaidKSI

Thank you @trueshot !!

Gtm-dev-market avatar Sep 14 '25 07:09 Gtm-dev-market

In my opinion, this shouldn't be closed because this issue wasn't fixed on the CC side.

DeltaLaboratory avatar Sep 14 '25 08:09 DeltaLaboratory

I agree it should not be closed. It is absolutely broken.

trueshot avatar Sep 14 '25 09:09 trueshot

Still happening in 113, need urgent attention! I rolled back to 110.

Image

khrm355 avatar Sep 14 '25 09:09 khrm355

@Gtm-dev-market you mind keeping this open for everybody's benefit please? A prompt is not a fix.

kohowski avatar Sep 14 '25 14:09 kohowski

1.0.113 still has this issue.

ZyphrZero avatar Sep 15 '25 02:09 ZyphrZero