Skip to content

[BUG] False "File has been unexpectedly modified" errors caused by stale background shell tracking #13392

@kevinjbradshaw

Description

@kevinjbradshaw

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 and Write tools fail with "File has been unexpectedly modified" even when the file is provably unchanged. This appears to
be caused by stale background shell state that incorrectly persists after shells have completed.

Steps to Reproduce:

  1. Start Firebase emulators in background: firebase emulators:start with run_in_background: true
  2. Kill the emulator processes (taskkill or Ctrl+C)
  3. Attempt to edit any file with the Edit tool

Observed Behavior:

  • KillShell returns status: completed or status: killed for all background shells
  • System reminders continue to appear claiming shells are status: running with "new output available"
  • Edit tool fails with "File has been unexpectedly modified"
  • Write tool fails with "File has not been read yet" even immediately after Read
  • File hash (md5sum) confirms file is unchanged
  • File timestamp confirms file is unchanged

Expected Behavior:

  • Shell status should be consistent between KillShell responses and system reminders
  • File modification detection should use actual file state, not be affected by unrelated shell tracking
  • Edit/Write should succeed when file is unchanged

Environment:

  • Platform: Windows (win32)
  • Working directory on V: drive (possibly mapped/virtual drive)
  • Multiple background shells were spawned during session

Evidence:

KillShell says completed:

Shell ee9b0a is not running, so cannot be killed (status: completed)

But system reminder says running:

Background Bash ee9b0a (command: ...) (status: running) Has new output available

File hash unchanged:

a29eb961536944249c6ec4d795eab161 (before)
a29eb961536944249c6ec4d795eab161 (after 2 second delay)

Workaround:

Start a new conversation to clear the corrupted shell tracking state.

What Should Happen?

File should be editable

Error Messages/Logs

Steps to Reproduce

Just try editing a file.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

not sure

Claude Code Version

2.0.60 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:toolsbugSomething isn't workingduplicateThis issue or pull request already existshas 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