Context Compaction Across Agent Harnesses: Why Summarization Is the Wrong Model A technical analysis of eight production agent harnesses — Claude Code, Codex, Antigravity CLI (formerly Gemini CLI), OpenCode, Pi, OMP, OpenHands and LangChain Deep Agents — argues that context compaction should be treated as a state-rebuilding pipeline rather than an LLM summarization step, since summarization alone can drop negative constraints, rejected hypotheses and project rules. The analysis separates agent state into three tiers: the durable record kept on disk (SQLite, JSONL session trees or append-only event streams), the working context sent to the model on each turn, and the continuation state holding objectives, constraints, accepted decisions and test results. It catalogs nine context-reduction techniques — truncation, observation clearing, deduplication, externalization, semantic summarization, tail retention, native provider compaction, context reconstruction and context isolation — and notes that when an agent fails after compaction, developers should check whether the harness wiped constraints, lost rejected attempts, skipped reloading rules or invalidated the prompt cache before blaming the compression ratio. On this page Context Compaction Across Agent Harnesses: Why Summarization Is the Wrong Model When agents forget after compaction, blame lost state over token ratios. How eight production harnesses manage context and keep long runs alive. Most developers treat context compaction as a summarization algorithm. When the agent nears its token limit, the harness calls an LLM, asks for a summary of past turns, and pastes that summary into the next prompt. The team sees a 70% drop in tokens and moves on. Then the agent enters an infinite loop. It modifies a file it was forbidden to touch. It tests a broken hypothesis it already discarded thirty minutes earlier. It hallucinates an API route because the original schema was wiped from the transcript. That mental model is wrong. Treat compaction as a pipeline that manages context and rebuilds state. The summary prompt is one step in it. When an agent fails after compaction, check four things before you blame the compression ratio. Did the harness wipe negative constraints? Lose the record of rejected hypotheses? Skip reloading project rules? Invalidate the prompt cache? I looked at eight harnesses: Claude Code https://code.claude.com , Codex https://github.com/openai/codex , Antigravity CLI https://antigravity.google/docs/cli/ formerly Gemini CLI , OpenCode https://opencode.ai , Pi https://pi.dev , OMP https://omp.sh , OpenHands https://docs.openhands.dev , and LangChain Deep Agents https://docs.langchain.com/oss/python/deepagents/context-engineering . Three Tiers of State A reliable agent system keeps three layers of state apart: 1. The Durable Record: The complete event log: every user message, tool call, file snapshot, and error trace. The harness keeps it on disk in SQLite, a JSONL session tree, or an append-only event stream. 2. The Working Context: The tokens the harness sends to the LLM on turn N. The model window and your budget cap its size. 3. The Continuation State: The structured task data the agent needs to resume: objectives, negative constraints, accepted decisions, rejected attempts, and test results. Compaction rewrites the working context and leaves the durable record on disk. When a developer says “the agent forgot the conversation,” the working context lost it. Storage still has it. OpenHands https://docs.openhands.dev/sdk/arch/condenser builds a new model-facing view and keeps the event stream. OMP https://omp.sh/docs/session-tree keeps the full conversation tree on disk. LangChain Deep Agents https://docs.langchain.com/oss/python/deepagents/context-engineering writes summarized history to the thread filesystem, where the agent can search it. Nine Context Reduction Techniques Harnesses mix nine techniques: | Technique | Operation | Primary Trade-off | |---|---|---| | Truncation | Drop older turns without saving meaning | Fast and cheap, but destroys task history | | Observation Clearing | Strip raw tool outputs; keep tool calls | Retains intent; loses specific test data | | Deduplication | Remove superseded file reads or searches | Saves space; requires tracking staleness | | Externalization | Replace raw text with a disk/URI pointer | Preserves access; requires explicit retrieval | | Semantic Summarization | Condense dialogue into an LLM narrative | Compact; lossy and prone to hallucination | | Tail Retention | Keep the last N tokens or turns verbatim | Protects immediate flow; limits space freed | | Native Provider Compaction | Delegate state reduction to the provider | Low client overhead; vendor lock-in | | Context Reconstruction | Reload instructions, plans, and files post-summary | Restores truth; refills the context window | | Context Isolation | Run heavy exploration in subagents | Keeps parent clean; adds IPC orchestration | How Each Harness Handles a Full Window Each harness trades token savings against execution safety and implementation effort: | Harness | Core Mechanism | What Survives Verbatim | Recovery Mechanism | |---|---|---|---| | Claude Code | Output clearing + summary + reconstruction | Root rules, memory, plan, up to 5 files | Direct disk re-reads | | Codex | 20k token user-message budget + local summary | User messages up to 20k tokens | None older tool outputs lost | | Antigravity CLI | Checkpoint compression fires at 70% of the window | Latest 30% of history | /rewind checkpoints and /resume sessions | | OpenCode | Local summaries default or native provider | Token-budgeted recent tail 15k in V2 | Provider checkpoint or disk log | | Pi | Reserve headroom trigger + protected recent tail | Last 20,000 tokens unsummarized | Extensions or branch rewinds | | OMP | Fallback chain remote → snapcompact → handoff → shake → soft | Method-specific recent tail | artifact:// URIs and image recall | | OpenHands | Append-only event log + Condenser pipeline | Head prefix and recent tail | Durable event stream replay | | Deep Agents | Tool offloading to filesystem + 85% limit trigger | Last 10% of window tokens | Thread filesystem file reads | Claude Code: The Context Reconstruction Pipeline Claude Code https://code.claude.com/docs/en/how-claude-code-works.md rebuilds more state after compaction than any other harness I looked at. It runs five stages: What Survives in Claude Code Claude Code’s context window documentation https://code.claude.com/docs/en/context-window.md lists what survives: - Root CLAUDE.md and global rules: Re-read from disk on every compaction pass. - Auto memory: Re-injected from ~/.claude/projects/