liveBook · Manning

Compaction

As explained in Vibe Engineering

Automatic context compaction is the automatic summarization of an AI conversation's accumulated history to reduce retained context.

A long AI coding session can run out of context or keep reprocessing stale history. Compaction reduces retained context by summarizing the conversation, but the summary is lossy: an instruction given once at the start may disappear even when it prevents bugs. section 3.5.2 section 9.5.2

In Claude Code, context management clears older tool outputs first and summarizes the conversation if needed. The summary favors recency, relevance, and frequency; requests and key code snippets may survive while detailed early instructions are compressed away. A typical compaction frees 60–70% of context, but that space comes at the cost of detail. section 3.5.2

Protect important context before the summary becomes the only record:

  • Put persistent project rules in a project memory file such as CLAUDE.md or AGENTS.md rather than relying on an early conversation message. CLAUDE.md is re-read at session start. section 3.5.2
  • Append decisions, findings, and reasoning to a durable artifact at workflow boundaries, including when leaving plan mode or completing a todo. Write before compaction and at session end as a backstop, not a substitute for timely notes. section 5.6.5
  • Treat late summaries cautiously. A note reconstructed at session end can omit abandoned approaches, and an agent rereading its own notes in the same session can reinforce an earlier mistake. section 5.6.5

Managing a growing session

A session that moves from a bug fix through feature discussion, refactoring, and several attempts can accumulate 150,000 tokens, much of it irrelevant. In Claude Code, use /compact to summarize the history; the cited recommendation is to compact at 70–80% context usage rather than wait for auto-compaction at 85% or more. Starting a new session for a distinct task is another option. section 9.5.2

How Vibe Engineering covers it

How deep it goes
Explains when summarization occurs, what may be lost, and how to checkpoint information, without specifying the summarization algorithm.
Examples
Uses an append-only Findings.md and a ninety-minute compact-or-restart team rule to illustrate checkpoints.
What you can do after
Operate/configure Claude Code compaction with /compact and protect critical guidance through project files and timely notes.
How it connects
Connects context engineering with project memory files, session management, and durable records of decisions.

Also explained in

Compare how 10 books explain compaction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vibe Engineering. The section links point to the parts of the book it draws on.