pu.sh pu.sh

Context Compaction

What gets kept, summarized, or dropped?

A public-docs based comparison of Claude Code, Pi, and pu when long agent sessions approach the model context limit.

researched 2026-05-07 Claude Code docs Pi docs pu source and docs

Snapshot

Claude Code managed

Trigger

Automatic near limit, or manual /compact [focus].

Keeps

Requests, key snippets, root memory, and reloaded startup context.

Reduces

Older tool outputs first, then older conversation history by summarization.

Pi structured

Trigger

contextTokens > contextWindow - reserveTokens, manual compact, and branch changes.

Keeps

Recent token tail, summary entries, and read/modified file tracking.

Reduces

Older turns and abandoned branches into structured summaries.

pu portable

Trigger

history bytes > AGENT_CONTEXT_LIMIT - AGENT_RESERVE, manual compact, or context-limit retry.

Keeps

First message, compacted memory card, recent byte tail, and valid tool pairs.

Reduces

Older middle history, oversized entries, and invalid orphan tool records.

Discard Map

Claude Code
key requests and snippets
older history summarized
older tool output cleared first
Pi
recent token tail
older turns as CompactionEntry
branch summaries replace full branch history
pu
first message and recent tail
middle history memory card
orphan or dangling tool pairs dropped

Detailed Comparison

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.