Skip to content

[BUG] Edit tool fails with "File has been unexpectedly modified" when file hasn't changed (Windows) #17684

Closed as duplicate

Description

@GeniuSKilleR95

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?

Description:

The Edit tool consistently fails with the error "File has been unexpectedly modified. Read it again before attempting to write it." even when:

  • No editors are open
  • No dev servers or file watchers running
  • No manual edits being made
  • File timestamp remains unchanged between Read and Edit calls

The issue accumulates over a session and temporarily resolves after restarting the PC.

Environment:

  • OS: Windows 11
  • Claude Code version: Latest (installed via npm)
  • Node.js version: 18+
  • Working directory: C:\Users[username]
  • Target files: D:\Work[project] (different drive)

Observed Behavior:


● Read(D:\Work\project\src\file.ts)
⎿  Error reading file

● # Read succeeds
Read file D:/Work/project/src/file.ts

# Immediate Edit fails
Edit tool error: "File has been unexpectedly modified. Read it again before attempting to write it."

# Verify file wasn't modified
$ stat file.ts | grep Modify
Modify: 2026-01-12 04:04:01.268346800 -0800  # Timestamp unchanged

Verification that file is stable:
# File timestamp doesn't change on its own
$ stat file.ts | grep Modify
Modify: 2026-01-12 04:04:01.268346800 -0800

$ sleep 5

$ stat file.ts | grep Modify
Modify: 2026-01-12 04:04:01.268346800 -0800  # Same

Additional observations:
- Happens on ALL files after the bug starts occurring (tested .ts, .tsx, .json files)
- sed commands via Bash tool work fine as a workaround
- The Write tool (full file replacement) may also work
- Cross-drive scenario: Working directory on C:, files on D: drive
- Restarting PC temporarily fixes the issue
- Issue returns after ~30-60 minutes of usage

Expected Behavior:
Edit tool should succeed when the file hasn't been modified between Read and Edit calls.

Workarounds:
- Use sed via Bash tool for edits
- Restart Claude Code / PC
- Provide full file content for manual pasting

Possible Causes:
- File hash/checksum tracking getting corrupted over time
- Windows NTFS timestamp precision issues
- Cross-drive path handling issues
- Memory/state leak in file tracking

### What Should Happen?

Edit tool should succeed when the file hasn't been modified between Read and Edit calls.

### Error Messages/Logs

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

Steps to Reproduce

  1. Use Claude Code for an extended session (30+ minutes)
  2. Read a file using the Read tool
  3. Immediately attempt to Edit the same file
  4. Error occurs even with no external modifications

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.5 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

IntelliJ IDEA terminal

Additional Information

tried it also on powershell terminal same thing

Activity

  1. github-actions commented on Jan 12, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Edit Tool False Positive "File has been unexpectedly modified" on Windows #12695
    2. Edit/Write tools fail with 'File has been unexpectedly modified' on Windows (MINGW) #12805
    3. Edit tool returns "File has been unexpectedly modified" when file is NOT modified #12462

    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. github-actions commented on Jan 16, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #12695.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  3. github-actions commented on Jan 24, 2026

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

  4. locked as resolved and limited conversation to collaborators on Jan 24, 2026
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

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions