Every Agent Harness re-sends the entire transcript on every turn (see “The Memory Illusion” in Agent Harness). This produces two pressures that grow with session length:

  • Cost — input tokens scale roughly quadratically; turn N pays for turns 1…N−1.
  • Capacity — the model has a hard context window (e.g. 200k tokens for Claude Sonnet 4.5). Long enough sessions will hit the ceiling.

This page maps the full design space of strategies a harness can use to handle the capacity problem, and explains why auto-compaction — the most popular one — is also the most dangerous.

The architectural why

Anthropic frames the underlying constraint in Effective context engineering for AI agents: context is a finite attention budget. Two reasons. First, context rot (Chroma research) — recall accuracy degrades as token count grows. Second, transformers compute n² pairwise attention, so the longer the context, the thinner the budget per pair, and training distributions skew shorter so models have less practice with very long contexts. Capacity is the hard ceiling; attention is the soft one that bites first.

The Six Strategies

#StrategyWhat it doesLossy?Who decides?
1Auto-compactionLLM-summarizes older turns into one synthetic message that replaces themYes (summary)Harness, automatically
2Hard abortRefuse the call when transcript would exceed the window; force user interventionN/AHarness, automatically
3Branch / forkStart a new session from a chosen point; old line preserved as a siblingNo (for the new branch)User
4File-as-stateAgent writes plan/findings/decisions to disk; fresh sessions re-read those filesNo (files are exact)User + agent
5Selective pruningDelete specific messages from the transcript without summarizingLossy only on dropped itemsUser (or harness with rules)
6Rewind / rollbackResume from an earlier turn, discard the tailDiscards the tailUser

These are not mutually exclusive. A serious workflow uses 3, 4, and 6 together: branch when you want to explore a side path, externalize state to files when work needs to outlive a session, rewind when the agent went off the rails. Compaction (1) is the fallback when none of those were used in time.

Why Auto-Compaction Is Uniquely Dangerous

Compaction looks like the obvious answer — “just summarize the old stuff” — but every property that makes it convenient also makes it hazardous. Four distinct failure modes, each rooted in earlier principles in this vault.

A. The summarizer is the same fallible model that produced the mess

Compaction is itself an LLM call. The model that misread auth.py on turn 3 is the same model deciding what’s “important enough to keep” when compacting turns 1–15. Bad beliefs in the transcript get encoded into the summary as fact, stripped of the surrounding evidence that would have let anyone (including the model on a later turn) notice the error.

Warning

Compaction launders mistakes into assertions.
Before: “I read auth.py and saw import flask.” (a tool result you can re-examine.)
After: “auth.py uses Flask.” (a claim with no underlying evidence in context.)

B. The user is out of the loop

Auto-compaction typically fires on a token threshold, mid-session, possibly mid-tool-loop. The user wasn’t asked. The transcript they thought they had is silently replaced. They notice only when the agent later “forgets” something it clearly knew minutes ago — and by then the original turns are gone unless the harness archived them.

This is the single biggest divergence between maximal harnesses (Claude Code Internals) — which lean on auto-compaction as a convenience — and minimal ones (Pi (Coding Agent)) — which expose /tree, --fork, --resume, and file-as-state precisely so compaction is rarely needed.

C. Compaction interacts catastrophically with booboo compounding

From Agent Harness: every turn’s input is the previous turn’s output, so early errors propagate. Add compaction and the propagation becomes irreversible:

  1. Turn 3: model misreads a file.
  2. Turns 4–15: subsequent reasoning quietly builds on the misreading.
  3. Turn 16: compaction fires. Misread + flawed reasoning collapse into a summary that asserts both as fact.
  4. Turns 17+: the original tool result that would have let you catch the error no longer exists in context. The booboo has been promoted from evidence to canon.

Branching, file-as-state, and rewind don’t have this property because they don’t rewrite history — they either preserve it (branch), externalize specific facts (files), or honestly discard a tail (rewind).

Mitigation: high-recall before high-precision compaction

Anthropic’s tuning advice for teams that must implement compaction (from Effective context engineering for AI agents):

  1. Maximize recall first — run your compaction prompt over complex agent traces and verify it captures every relevant fact (architectural decisions, unresolved bugs, in-flight implementation details). Err on keeping too much.
  2. Then improve precision — iterate to remove superfluous content (redundant tool outputs, chatter, paths the agent abandoned).
  3. Lightest touch first — clearing tool results (not the full message) once their findings are summarized is the safest form of compaction. Now shipped as a feature on the Claude Developer Platform.

This still doesn’t fix failure modes A–C above (the summarizer is fallible, the user is out of the loop, mistakes propagate) — it only narrows the loss surface. The structural fix remains: branch + file-as-state + rewind.

D. Compaction defeats the observability principle

From Agent Harness’s reactive-executor section: “if the model is driving and you can’t see the steering wheel, you’ve lost the loop.” The transcript is the steering wheel. Compaction throws part of it away.

  • Replay degraded — you can’t reconstruct what the agent saw.
  • Debugging degraded — “why did it do that?” may have no answer in the surviving messages.
  • Trust degraded — the version of history the model now reasons from differs from the one you witnessed.

This is the deepest reason a minimal harness treats compaction with suspicion: it trades a per-turn cost problem for an observability problem, and observability is the property a minimal harness refuses to compromise.

Why Pi Prefers Branch + File-as-State + Rewind

Pi exposes all six strategies but biases hard toward 3, 4, and 6:

Pi featureStrategyWhat it solves
/tree, --forkBranchSide quests don’t pollute the main line; bring fixes back via summary
PLAN.md, TODO.md, the read toolFile-as-stateLong-horizon memory lives on disk, not in the transcript
--resume <turn>RewindThe agent went off the rails at turn N? Reset to turn N−1, no laundered booboos
Per-turn cost + token displayAwarenessYou can see the meter and intervene before compaction is needed

Compaction is available in Pi but treated as a last resort. The design bet: a user who can see the cost will branch and externalize before the window fills, which is a lossless solution to a problem auto-compaction can only solve lossily.

Multi-Agent Long-Horizon Patterns (Anthropic Research System)

Anthropic’s production multi-agent research system runs conversations that span hundreds of turns. Their patterns are a concrete extension of the strategies above:

  • Memory-as-state-on-write. Before context fills, summarize completed work phases and write essential information to external memory. Plans, intermediate findings, and decisions are written as the work happens, not at the end. The lead agent’s plan is saved to memory immediately because if the context exceeds 200K tokens it gets truncated.
  • Subagent handoffs with clean contexts. When context limits approach, spawn a fresh subagent with a clean context window. Continuity is preserved through deliberate handoff (memory + plan reference), not through transcript carry-over.
  • Filesystem artifacts to bypass the orchestrator. Subagents write structured outputs (code, reports, visualizations) directly to a filesystem and return only a reference to the lead agent. Reduces token overhead and prevents information loss in the “game of telephone” through the coordinator.

The structural insight: in a multi-agent system, fresh subagents are themselves a context-management strategy — every spawn is a free reset of the context window, paid for in coordination complexity.

The Underlying Principle

Key

Context-window pressure is not just a cost or capacity problem — it is a question of who edits history and whether the user can see them do it.
Auto-compaction has the LLM silently rewrite its own past. Branching, file-as-state, and rewind keep the user in the loop and keep history honest. Choose harnesses (and workflows within them) that preserve the transcript as a witness, not a draft.

Open Questions

  • Is there a “safe compaction” design — e.g. compact only tool results older than N turns while preserving assistant/user text verbatim? Would that defuse failure mode A? (Anthropic’s tool result clearing feature is one answer.)
  • Should harnesses archive the pre-compaction transcript by default so rewind remains possible after compaction? (Some do; many don’t advertise it.)
  • How does prompt caching change the cost calculus? If old turns are cached cheaply, the pressure to compact drops — but the capacity ceiling is unchanged.