Build1 publisher2 min readPublished
A smaller model rewrites the middle of a Claude Code session at about 160K tokens
A dev.to walkthrough of Claude Code compaction says the system prompt and the last 10 to 15 turns survive while the messages between them are summarized and deleted without an error. Constraints you need later belong in a file.
The Engineer · Build desk
What happened
- A dev.to walkthrough says Claude Code auto-compacts at about 160K tokens, 80 percent of the 200K window, summarizing the middle of the conversation into prose and discarding the original messages without warning.
- Retention is positional: the system prompt and configuration directives survive untouched, the most recent 10 to 15 turns survive intact, and everything between them goes to the summarizer.
- The post says a smaller model writes the summary than the one running the conversation, so distinctions the main model understood may not survive the pass.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- cost The output compiles, and a human has to re-verify it at code review against requirements the agent no longer holds in its buffer.
- constraint Once the middle is gone, the session cannot tell anyone why an approach was abandoned, so the same dead end is available to be tried a second time at full cost.
- decision Every long session becomes a choice between compacting early on your own retention rules and letting the summarizer pick what to keep.
Plan around the retained tail. A rule typed at turn 12 of a 90-turn session is outside it, so the rule survives only if the summarizer chose to write it down.
Roughly 40,000 tokens sit between the compaction trigger and the window ceiling [15]. Compaction fires when the count crosses, and the agent continues from the reconstructed buffer of system prompt, summary and recent turns without signalling that anything happened [7].
The summary aims at outcomes: files modified, errors resolved, dependencies added [5]. The reasoning that produced them is not in scope, so a session where the agent tried four approaches before one worked compacts to "implemented authentication using JWT" with no record of the three rejected strategies or why they failed [6]. Nothing left in the buffer contradicts the agent if it proposes one of those three again. The post describes the resulting failure as syntactically correct code that violates a constraint the agent learned 50 messages earlier and forgot during compaction [9].
Branching sessions lose the most. Parallel exploration collapses into a single narrative, and the distinctions between the approaches go with it, while linear conversations where each exchange builds on the last summarize coherently [11].
The post recommends putting constraints, decisions and open tasks in persistent artifacts, because sessions that create explicit artifacts produce summaries that reference those artifacts [10]. A file path costs a handful of tokens in the summary. The bytes it points at were never in the conversation buffer, so no summarization pass can thin them.
These figures come from one runtime. For 160K to be your trigger you need the same 200K window and the same 80 percent threshold in the build you are running [1]. The three-phase description is not sourced to Anthropic documentation in the post, which states it was written with the assistance of AI under human supervision and review [14]. The retention rule transfers. If your runtime keeps the system prompt and the recent turns and rewrites everything between them, anything you need at turn 90 belongs on disk.
The post's other two levers are manual compaction, which it says gives control over what survives by forcing early summaries with explicit retention rules [12], and token discipline: concise system prompts, artifact-based state and pruning dead branches, which it says delays or eliminates compaction in most sessions [13].
What to watch
- Whether Anthropic documents the 80 percent trigger and the 10-to-15-turn retention tail. Documentation would move both figures off a single AI-assisted post.
- A change to the summarization model or the threshold in a Claude Code release. Either one would invalidate the 40,000-token headroom figure.
- Whether summaries reliably carry file paths forward: ask the agent to name its constraint file immediately after a compaction and see if it can.