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

Resolved 💬 3 comments Opened Dec 8, 2025 by kevinjbradshaw Closed Dec 10, 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?

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_

View original on GitHub ↗

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