Read-state is lost across auto-compaction → `File has not been read yet` on files already read
Type: bug
Environment
- Claude Code version: 2.1.220
- OS: macOS 26.5.2 (Darwin 25.5.0)
- Platform: Claude subscription
- Model: claude-opus-5 / claude-opus-4-8
What happened
Edit and Write fail with:
<tool_use_error>File has not been read yet. Read it first before writing to it.</tool_use_error>
on files the session had already read — the read simply happened before an auto-compaction. The guard itself is correct and valuable (it has never once let through a write to an unread file in our data). The problem is that its bookkeeping does not survive compaction, so a long session pays a redundant Read for every file it touches after each compact.
Measured in this transcript store: the error appears in 340 of 5 096 transcript files. Over one 26-day window it occurred 155 times across ~2 006 transcripts (0.077/transcript), down from 231 across ~1 084 transcripts (0.213/transcript) in the previous window — so it is improving, but it is still the most common recoverable tool error we see after the one in draft 1.
Expected
Either of:
- Read-state is carried across compaction for files the session has already read and that have not changed on disk (mtime/size check at write time), or
- The guard offers an automatic fallback for small files: re-read transparently instead of erroring, at least below some size threshold.
Repro
- Start a session in a large project; read a file.
- Work until auto-compaction fires (or force it).
Editthat same file without re-reading it.- Observe
File has not been read yeteven though the file is unchanged and was read in this same session.
Impact
One wasted round trip per file per compaction. In long-running agentic sessions with several compactions this is a steady, invisible tax; it also causes the model to re-read large files it already summarized, which pushes the context back up and makes the next compaction arrive sooner.