claude-code - 💡(How to fix) Fix ExitPlanMode resets Write tool's Read-tracking state, causing file update failures and duplicate side effects [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47904Fetched 2026-04-15 06:39:01
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

After ExitPlanMode, the Write tool loses track of files it has already created or read in the same session. This causes the Write tool to reject updates to files the AI just created seconds ago, leading to a cascade of failures and duplicate irreversible side effects (e.g., duplicate emails).

Error Message

Error 1: "File has not been read yet"

Error 2: "File has been modified since read"

When the AI uses Bash to modify a file (e.g., adding BOM encoding), the Write tool detects the external change and rejects further writes. This is expected but compounds with Error 1. L211: Write(prompt.md) → FAIL (same error, now during /end skill) 3. At minimum: if Write fails, the error message should suggest "Read the file first" rather than leaving the AI to discover the workaround through trial and error

Root Cause

  1. Start a session that uses plan mode (e.g., a skill with EnterPlanMode → auto-approve → ExitPlanMode)
  2. After ExitPlanMode, create a new file using Writesucceeds
  3. Modify the file externally via Bash (e.g., add UTF-8 BOM with PowerShell)
  4. Attempt to update the same file using Writefails with "File has not been read yet"
  5. The AI then executes subsequent steps (e.g., sending an email via Bash) that succeed because Bash is unaffected
  6. The AI eventually recovers by reading an arbitrary file ("Read priming"), then recreates the file and re-executes all steps — including the irreversible email send

Fix Action

Fix / Workaround

  1. After ExitPlanMode, the Write tool should retain knowledge of files created/read in the same session
  2. A file the AI just created via Write should be updatable without requiring a separate Read call
  3. At minimum: if Write fails, the error message should suggest "Read the file first" rather than leaving the AI to discover the workaround through trial and error

Code Example

L108: ExitPlanMode
L133: Write(prompt.md)SUCCESS (file created)
L149: Bash(PowerShell BOM addition)SUCCESS (external file modification)
L151: Write(prompt.md)FAIL "File has not been read yet"
L154: Bash(send-email.ps1)"SENT OK" ← 1st email
L211: Write(prompt.md)FAIL (same error, now during /end skill)
L237: Write(prompt.md)FAIL (3rd attempt)
L241: Bash(heredoc cat >)FAIL (EOF parsing)
L263: Bash(python3 write)FAIL (script not found)
L265: Read(unrelated_file.md)SUCCESS"Read priming" unlocks Write
L280: Write(prompt.md)SUCCESS (file recreated)
L291: Bash(send-email.ps1)"SENT OK" ← 2nd email (DUPLICATE)
RAW_BUFFERClick to expand / collapse

Summary

After ExitPlanMode, the Write tool loses track of files it has already created or read in the same session. This causes the Write tool to reject updates to files the AI just created seconds ago, leading to a cascade of failures and duplicate irreversible side effects (e.g., duplicate emails).

Environment

  • Claude Code version: Latest (2026-04-14)
  • Model: claude-opus-4-6
  • OS: Windows 11 Pro
  • Shell: bash (via Claude Code)

Steps to Reproduce

  1. Start a session that uses plan mode (e.g., a skill with EnterPlanMode → auto-approve → ExitPlanMode)
  2. After ExitPlanMode, create a new file using Writesucceeds
  3. Modify the file externally via Bash (e.g., add UTF-8 BOM with PowerShell)
  4. Attempt to update the same file using Writefails with "File has not been read yet"
  5. The AI then executes subsequent steps (e.g., sending an email via Bash) that succeed because Bash is unaffected
  6. The AI eventually recovers by reading an arbitrary file ("Read priming"), then recreates the file and re-executes all steps — including the irreversible email send

Observed Behavior

Two distinct Write errors occur in a death spiral:

Error 1: "File has not been read yet"

After ExitPlanMode, a file the AI just created in the same session is treated as "never read." The Write tool rejects overwrite attempts even though the AI created the file moments ago.

Error 2: "File has been modified since read"

When the AI uses Bash to modify a file (e.g., adding BOM encoding), the Write tool detects the external change and rejects further writes. This is expected but compounds with Error 1.

Combined effect:

  • The AI cannot update its own files after ExitPlanMode + external modification
  • Bash-based side effects (email, API calls) continue working since they bypass Write's guards
  • This creates a partial execution state: irreversible actions complete while file operations fail
  • The AI enters a recovery loop (tries Write → fails → tries cat > heredoc → fails → tries Python script → fails → eventually discovers Read priming)
  • Upon recovery, the AI re-executes the entire workflow including the already-sent email, causing a duplicate

Evidence from Session JSONL

L108: ExitPlanMode
L133: Write(prompt.md) → SUCCESS (file created)
L149: Bash(PowerShell BOM addition) → SUCCESS (external file modification)
L151: Write(prompt.md) → FAIL "File has not been read yet"
L154: Bash(send-email.ps1) → "SENT OK" ← 1st email
L211: Write(prompt.md) → FAIL (same error, now during /end skill)
L237: Write(prompt.md) → FAIL (3rd attempt)
L241: Bash(heredoc cat >) → FAIL (EOF parsing)
L263: Bash(python3 write) → FAIL (script not found)
L265: Read(unrelated_file.md) → SUCCESS ← "Read priming" unlocks Write
L280: Write(prompt.md) → SUCCESS (file recreated)
L291: Bash(send-email.ps1) → "SENT OK" ← 2nd email (DUPLICATE)

File system evidence: prompt.md CreationTime = 20:31 (not 20:16 when first created), confirming the file was deleted and recreated during recovery.

Expected Behavior

  1. After ExitPlanMode, the Write tool should retain knowledge of files created/read in the same session
  2. A file the AI just created via Write should be updatable without requiring a separate Read call
  3. At minimum: if Write fails, the error message should suggest "Read the file first" rather than leaving the AI to discover the workaround through trial and error

Impact

  • Duplicate irreversible side effects: Emails, API calls, or other Bash-based actions get executed twice
  • False checkpoint records: The AI creates a checkpoint claiming files were written (because they were — initially), but then can't update them
  • Wasted compute: 80+ lines of recovery attempts (Write → heredoc → Python → Read priming) before succeeding
  • User confusion: User receives duplicate communications and must investigate which session caused it

Suggested Fix

Option A (preferred): ExitPlanMode should preserve the Write tool's file-tracking state from the plan phase Option B: Write tool should implicitly track files it has written as "known" (no Read required before re-write) Option C: Write tool should accept re-writes to files created in the same session, regardless of Read state

extent analysis

TL;DR

The most likely fix is to modify the Write tool to preserve its file-tracking state after ExitPlanMode or to implicitly track files it has written as "known" to prevent duplicate irreversible side effects.

Guidance

  • Review the implementation of ExitPlanMode to determine why the Write tool's file-tracking state is not preserved, and consider modifying it to retain this state.
  • Investigate the possibility of implicitly tracking files written by the Write tool as "known" to allow for re-writes without requiring a separate Read call.
  • Analyze the session JSONL logs to understand the sequence of events leading to the duplicate email sends and identify potential points of failure.
  • Consider adding error messages or suggestions to the Write tool to guide the AI towards the correct recovery workflow, such as "Read the file first" when attempting to update a file that has not been read yet.

Example

No code snippet is provided as the issue does not contain sufficient information about the implementation details of the Write tool or the ExitPlanMode functionality.

Notes

The suggested fixes assume that the issue is related to the Write tool's file-tracking state and its interaction with ExitPlanMode. However, without more information about the underlying implementation, it is difficult to provide a definitive solution. Additional logging or debugging may be necessary to fully understand the issue.

Recommendation

Apply workaround: Modify the Write tool to implicitly track files it has written as "known" to allow for re-writes without requiring a separate Read call. This approach may be more feasible than modifying the ExitPlanMode functionality and can help prevent duplicate irreversible side effects.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix ExitPlanMode resets Write tool's Read-tracking state, causing file update failures and duplicate side effects [1 participants]