How Compaction Works in Pi · Earendil Engineering · earendil.com, August 13, 2026
Compaction breaks your prompt cache, and Earendil says so in the mechanism
A first-party account of when the Pi coding agent compacts and what it sends when it does. Pi checks for auto-compaction after a turn ends, against a configurable token budget whose current default is 20 thousand tokens, "roughly 5 to 20 turns." It may also compact mid-turn if it hits a context overflow error. Compaction runs as a standalone request that carries none of the existing history, with its own system prompt telling the model "you are a context summarization assistant" and a user message asking for "a structured summary of this conversation branch for context when returning later," with sections for goal, progress and key decisions. Because the request is standalone, it can be routed to a different, cheaper model. The post links the exact prompt construction at pinned line ranges in the Pi repository, so the claims about what Pi sends can be checked against the source.
On caching, the post states: "This caching requires an exact prefix match, so compacting a session will break the prompt cache." The retained turns hold the same tokens, but they now follow a different prefix, so everything after the first changed token has to be recomputed.
Why it matters: Compaction is usually argued about as a quality problem, meaning what the summary loses. This puts a price on it instead, and locates the price precisely: not the size of the edit, but the size of everything behind it. Combined with item 1, a badly timed compaction is about to cost more than it did last week.