Claude Code managed
Automatic near limit, or manual /compact [focus].
Requests, key snippets, root memory, and reloaded startup context.
Older tool outputs first, then older conversation history by summarization.
Context Compaction
A public-docs based comparison of Claude Code, Pi, and pu when long agent sessions approach the model context limit.
Automatic near limit, or manual /compact [focus].
Requests, key snippets, root memory, and reloaded startup context.
Older tool outputs first, then older conversation history by summarization.
contextTokens > contextWindow - reserveTokens, manual compact, and branch changes.
Recent token tail, summary entries, and read/modified file tracking.
Older turns and abandoned branches into structured summaries.
history bytes > AGENT_CONTEXT_LIMIT - AGENT_RESERVE, manual compact, or context-limit retry.
First message, compacted memory card, recent byte tail, and valid tool pairs.
Older middle history, oversized entries, and invalid orphan tool records.
| Agent | Compaction Method | Tool Call Handling | Main Tradeoff |
|---|---|---|---|
| Claude Code | Managed context compaction. Tool outputs are cleared before conversation summarization. | Older tool outputs can be removed from active context while the conversation summary remains. | Convenient and automatic, but important instructions should live in memory files rather than only in chat. |
| Pi | Token-aware and turn-aware compaction with structured CompactionEntry records and branch summaries. |
Uses a structured session model, so old tool-heavy turns can be summarized while recent turns remain intact. | Precise and extensible, but depends on Pi's richer runtime and session model. |
| pu | Shell-only byte/char heuristic. Summarizes the older middle and keeps a recent raw transcript tail. | Preserves valid provider tool-call/result pairs. Stubs huge records and drops orphan OpenAI or dangling Anthropic pairs. | Small and portable, but approximate and not real token accounting. |