Skip to content

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

Closed

Description

@Gtm-dev-market

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Activity

  1. github-actions commented on Sep 11, 2025

    @github-actions

    Found 3 possible duplicate issues:

    1. Edit and MultiEdit tools fail with persistent 'File has been modified since read' errors #3513
    2. [BUG] Excessive "file modified" notifications causing edit failures #5981
    3. [BUG] Edit/MultiEdit Tools Return False EPERM Errors #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

  2. ksoftkorea-creator commented on Sep 11, 2025

    @ksoftkorea-creator

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

  3. Gtm-dev-market commented on Sep 11, 2025

    @Gtm-dev-market
    Author

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

  4. Gtm-dev-market commented on Sep 11, 2025

    @Gtm-dev-market
    Author

    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....

  5. Norsninja commented on Sep 11, 2025

    @Norsninja

    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"
  6. trueshot commented on Sep 11, 2025

    @trueshot
    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
  7. Norsninja commented on Sep 11, 2025

    @Norsninja

    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"
  8. trueshot commented on Sep 11, 2025

    @trueshot

    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.

  9. kohowski commented on Sep 11, 2025

    @kohowski

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

  10. trueshot commented on Sep 12, 2025

    @trueshot

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

  11. Adamcf123 commented on Sep 12, 2025

    @Adamcf123

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

    No. it is not over. it happens randomly.

  12. 33 remaining items

  13. pkp24 commented on Sep 26, 2025

    @pkp24

    Why was this closed? It's still not fixed and more and more people are duplicating this bug report. I've started to have to use claude to find a problem and cursor or codex to solve it.

    Image

    I saw elsewhere that someone said using this prompt will fix it, I haven't gotten a chance to test it yet though. "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."

  14. JosiahSiegel commented on Sep 26, 2025

    @JosiahSiegel

    I place this workaround in CLAUDE.md and it has worked so far:

    ## CRITICAL: File Editing on Windows
    
    ### ⚠ïļ MANDATORY: Always Use Backslashes on Windows for File Paths
    
    **When using Edit or MultiEdit tools on Windows, you MUST use backslashes (`\`) in file paths, NOT forward slashes (`/`).**
    
    #### ❌ WRONG - Will cause errors:
    ```
    Edit(file_path: "D:/repos/project/file.tsx", ...)
    MultiEdit(file_path: "D:/repos/project/file.tsx", ...)
    ```
    
    #### ✅ CORRECT - Always works:
    ```
    Edit(file_path: "D:\repos\project\file.tsx", ...)
    MultiEdit(file_path: "D:\repos\project\file.tsx", ...)
    ```
  15. trueshot commented on Sep 26, 2025

    @trueshot

    My experience is strange. Sometimes it doesn't seem to have problems, sometimes it can't seem to do anything with files. Generally, it seems to be getting better, but sometimes it just doesn't work well at all.

  16. YiHuangDB commented on Sep 28, 2025

    @YiHuangDB

    do not use claude code, then you dont have this issue anymore. Yes I am joking, cause this bug annoys me so much

  17. EllieTellie commented on Sep 29, 2025

    @EllieTellie

    I place this workaround in CLAUDE.md and it has worked so far:

    CRITICAL: File Editing on Windows

    ⚠ïļ MANDATORY: Always Use Backslashes on Windows for File Paths

    When using Edit or MultiEdit tools on Windows, you MUST use backslashes (\) in file paths, NOT forward slashes (/).

    ❌ WRONG - Will cause errors:

    Edit(file_path: "D:/repos/project/file.tsx", ...)
    MultiEdit(file_path: "D:/repos/project/file.tsx", ...)
    

    ✅ CORRECT - Always works:

    Edit(file_path: "D:\repos\project\file.tsx", ...)
    MultiEdit(file_path: "D:\repos\project\file.tsx", ...)
    

    I never experienced this before today, but often it would use update (edit/multi edit) and then insta fail before trying a new approach. Today it really seems to want to keep using update and then getting stuck in a loop. The first edit will succeed. The second edit will fail forever typically. Added this to test and yes the workaround works a treat, but honestly wish it didn't need to be there.

  18. 1uv0cean commented on Sep 30, 2025

    @1uv0cean

    Why we should enter that prompt manually on CLAUDE.md?
    I can't understand why this issue was closed.

  19. kohowski commented on Oct 1, 2025

    @kohowski

    @anthropics @dicksontsai hey, sure thing there's a lot on your plate. But look at this one non-esoteric thing people struggle with please..

    #7935 #7920 #7918 #7883

  20. trueshot commented on Oct 1, 2025

    @trueshot

    Did you try updating to claude Code 2 "claude update" I haven't had problems since.

    spoke too soon.
    Update(c:\buffalo\d\clients\gological\js\components\universalnavbar.js)
    âŽŋ  Error: File has been unexpectedly modified. Read it again before attempting to write it.

  21. Dragod commented on Oct 3, 2025

    @Dragod

    this thing is still plauging me. It is not acceptable on a 200$ per month.

    Image
  22. hi-fox commented on Oct 5, 2025

    @hi-fox

    why has this been closed when it is still occurring?

  23. thenickb commented on Oct 5, 2025

    @thenickb

    I get this constantly on a Max plan.

  24. dancingmadkefka commented on Oct 6, 2025

    @dancingmadkefka

    Getting this issue as well. Don't usually use CC but did today and ya it just fails every edit first time. Windows/Bash

  25. Christilut commented on Oct 6, 2025

    @Christilut

    Had the same issue since it upgraded to 2.0.8, editing almost impossible. Downgraded to 2.0.5 and disabled auto update for now.

    Windows terminal / git bash

  26. github-actions commented on Oct 14, 2025

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  27. locked as resolved and limited conversation to collaborators on Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:windowsIssue specifically occurs on Windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions