[BUG] File Edit/Write Fails After Context Compaction

Resolved 💬 2 comments Opened Feb 24, 2026 by sokajima Closed Feb 24, 2026

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?

After context compaction (session summarization), the Read/Edit/Write tools fail for files that were accessed before compaction, even though the Read tool appears to succeed.

## Environment

  • Platform: Windows 11
  • Claude Code Version: 2.1.1

## Steps to Reproduce

  1. Start a new Claude Code session
  2. Read and edit a file multiple times (File A)
  3. Continue the conversation until context compaction occurs
  4. After compaction, Read File A → Success
  5. Edit File A → ERROR "File has been unexpectedly modified"
  6. Read File A again, then Write → ERROR "File has not been read yet"

## Observed Behavior

| File Type | Read | Edit | Write |
|-----------|------|------|-------|
| Accessed before compaction | ✓ (appears to work) | ✗ Error | ✗ Error |
| Created with Write tool after compaction | ✓ | ✓ | ✓ |
| Never accessed before compaction | ✓ | ✓ | ✓ |

## Root Cause Analysis

After context compaction, the internal file state tracking appears corrupted. Read executes but does NOT register the file in internal state, causing Edit/Write to fail.

## Workaround

Start a new session instead of continuing from compaction.

What Should Happen?

After context compaction, Read/Edit/Write tools should work normally for all files, including files that were accessed before compaction.

Error Messages/Logs

Error 1 (Edit tool):
  "File has been unexpectedly modified. Read it again before attempting to write it."

  Error 2 (Write tool after Read):
  "File has not been read yet. Read it first before writing to it."

Steps to Reproduce

  1. Start a new Claude Code session
  2. Read and edit a file multiple times (File A) until context compaction occurs
  3. After compaction (session continues with summary), run: Read File A
  4. Read succeeds and displays file content
  5. Run: Edit File A (any change)
  6. ERROR: "File has been unexpectedly modified"
  7. Run: Read File A again
  8. Run: Write File A (same or modified content)
  9. ERROR: "File has not been read yet"

Note: Files created with Write tool AFTER compaction, or files never accessed before compaction, work correctly.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.1

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

Potentially related issues:

  • #18158 (context compaction related)
  • #16182 (file state tracking related)

The bug specifically affects files that were accessed (Read/Edit/Write) before context compaction occurred. Files created with Write tool after compaction, or files never accessed before compaction, work correctly.

View original on GitHub ↗

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