All payments made in the preview are in test mode. Read more
claudetokenoptimization.com

Optimize

Conversation Compaction and Memory: When Summaries Save Money

Long threads re-bill prior history every turn until something gives — a hard window limit, a FIFO trim, or a summary. Compaction replaces older context with a compact block so you can keep working; the summary itself is an extra sampling pass you must meter.

Figures last verified 2026-09-19

This page is part of the Optimize hub, which covers the whole topic end to end.

Last updated 19 September 2026. This page explains claude conversation compaction as an operational cost lever: what server-side compaction does on the Messages API, how compaction blocks and billing iterations work, when client-side summaries or a fresh thread with a carry-forward brief beat automatic compact, and how external memory differs from summarizing inside the window. Product headers, defaults, and metering evolve — confirm live behavior in Anthropic’s Compaction and Context windows docs. [VERIFY: 2026-09-19]

Not affiliated with Anthropic. Claude Token Optimization is an independent site and audit service. Claude® and related product names are trademarks of Anthropic PBC. Plan prices, model rates, beta headers, context-management behavior, and usage metering change; always confirm on Anthropic’s own docs. [VERIFY: 2026-09-19]

Searches for claude conversation compaction, context summarization cost, and “why did my long chat suddenly get expensive” usually want the same answer: every turn re-sends prior history (plus tools, docs, and thinking), so the bill grows until you drop, trim, or summarize. Compaction is the recommended server-side way to keep a long-running conversation or agentic workflow alive without shipping the entire raw transcript forever — but the summary pass itself is billed and rate-limited. [VERIFY: 2026-09-19]

This spoke sits under the Optimize hub. Pair it with the context window guide, prompt caching, tool-use costs, extended thinking, skills costs, document token costs, Claude Code tokens, and cut token usage. Soft CTA to a written review at the end — no dollar price on this page.

What conversation compaction is (and why summaries can save money)

Compaction replaces older conversation content with a concise summary so the active context stays smaller. Anthropic’s docs position server-side compaction as the primary strategy for long-running conversations and agentic workflows that approach context window limits: the API detects a trigger, generates a summary, emits a compaction block, and continues. On later requests you append that response (including the block); the API drops content before the compaction block and continues from the summary. [VERIFY: 2026-09-19]

Why that saves money: without compaction, each new user turn typically re-includes the full prior transcript as input. A 120k-token history billed again and again dwarfs the visible question. A tight summary might be a few thousand tokens instead of six figures of raw turns, tool dumps, and abandoned branches. You also fight context rot — accuracy and recall degrade as the window fills, so curating what stays in context is as important as how large the window is. [VERIFY: 2026-09-19]

Why summaries are not free: compaction is an extra sampling iteration. It counts toward rate limits and billing. The response usage.iterations array can include a compaction entry; top-level input_tokens / output_tokens may reflect only non-compaction iterations — sum across usage.iterations for total billed tokens when compaction is enabled. Re-applying a previous compaction block does not charge another compaction pass. [VERIFY: 2026-09-19]

How context grows (and why every turn re-bills history)

In the Messages API model, the context window is working memory for the current request: system prompt, tool definitions, every message (including tool results, images, documents), and the output Claude generates — including extended thinking where applicable. Each turn’s input is prior history plus the new user message; the assistant reply becomes input for the next turn. Chat UIs may also manage the window on a rolling first-in, first-out basis. [VERIFY: 2026-09-19]

That progressive accumulation is why long Claude Code / Cowork sessions and multi-hour API agents feel “fine” until capacity or quality collapses. Fat PDF uploads, MCP dumps, skill packs, and thinking blocks accelerate the climb — see document costs, MCP costs, and thinking costs. Compaction is one exit ramp; prevention (thinner results, caching, done-when loops) is usually cheaper than compacting every hour.

ApproachWhat it doesWhen it helpsWatch-outs
Server-side compactionAPI summarizes at a token trigger; emits a compaction block; drops prior content on later turnsLong single-thread chat or agent loops approaching the windowExtra sampling pass billed; lossy summary; must pass blocks back; same model for summary
New thread + carry-forward briefYou write a short state note and start freshTask boundary is clear; old transcript is mostly noiseManual discipline; easy to forget decisions, IDs, or next steps
External memory / artifactsDurable notes, tickets, or files outside the model windowFacts must survive many sessions; audit trail neededStill costs tokens when you re-load memory into context
Prompt cachingCache stable prefixes (system, tools, compaction blocks) across turnsRepeated large static context with changing tailsDoes not shrink unbounded history by itself — pairs with compact
Orienting split: compaction vs restart vs memory vs prompt cache

Server-side compaction (API): how it works

Enable compaction by sending the beta header compact-2026-01-12 and adding a compact_20260112 edit under context_management.edits on the Messages API request. Anthropic documents this as the recommended path when you do not want to maintain client-side summarization code. [VERIFY: 2026-09-19]

Trigger, block, and drop behavior

  • Default trigger: { "type": "input_tokens", "value": 150000 }. The minimum allowed trigger value is 50,000 tokens. Lower triggers compact sooner (smaller active context, more frequent summary passes); higher triggers delay the sampling cost but keep more raw history longer. [VERIFY: 2026-09-19]
  • What happens: when input tokens reach the threshold, the API summarizes, creates a compaction block, and continues the response with compacted context. On subsequent requests, append the assistant content (including the block). Content before the compaction block is dropped / ignored. [VERIFY: 2026-09-19]
  • Optional knobs: pause_after_compaction (pause so you can preserve recent messages verbatim after the block), and instructions (custom summarization prompt that replaces the default entirely). [VERIFY: 2026-09-19]
  • On-demand compact: a newer beta path can request a summary separately from conversation turns; confirm the current header and parameter names in Anthropic’s Compaction docs before coding against it. [VERIFY: 2026-09-19]

Billing and metering of the compaction iteration

Treat compaction like a hidden model call inside your request. Docs show an iterations array with a compaction entry (its own input/output tokens) followed by the main message iteration. Top-level usage fields match non-compaction work; sum all iterations for total tokens consumed and billed. Finance and observability stacks that only read top-level usage.input_tokens will under-count whenever compaction fires. [VERIFY: 2026-09-19]

Prompt caching + compaction

Compaction works with prompt caching. Cache the system prompt separately so long static instructions survive across compaction events. You can also put cache_control on compaction blocks so the summary itself can be a cacheable prefix for later turns. Compaction shrinks history; caching discounts what remains stable — use both. Details on prompt caching pricing and patterns. [VERIFY: 2026-09-19]

Sibling context edits (not the same as compaction)

Anthropic also documents context editing strategies such as clearing old tool results or thinking blocks without a full conversation summary. Those are surgical trims; compaction is a narrative replacement of older turns. Pick the lighter edit when the problem is one fat tool dump, not a 200-message saga. [VERIFY: 2026-09-19]

Known limitations (ops view)

  • Same model for summarization — there is no documented option to summarize with a cheaper model than the one on the request. [VERIFY: 2026-09-19]
  • Tools during summarize — with tools defined, the model may call a tool instead of writing a summary, yielding a compaction block with content: null. Custom instructions that forbid tool calls during summarize reduce that failure mode. [VERIFY: 2026-09-19]
  • Thinking / binding after compact — re-inserting older thinking blocks after a compaction can fail conversation checks on some models; prefer letting the API summarize cleanly or follow current thinking-binding guidance in the docs. [VERIFY: 2026-09-19]

Client, chat, and agent patterns

Not every surface exposes the Messages compaction beta. Operators still need the same economics:

  1. Manual summarization. Ask Claude for a structured state brief (goal, decisions, open questions, file paths, next step), then paste that into a new thread. Cheap when the task boundary is clear; lossy when you forget IDs or constraints.
  2. New thread + carry-forward brief. Same idea without waiting for a hard limit. Treat the brief as the only history that earns its place.
  3. Chat UI FIFO trim. Some chat products drop oldest turns when the window fills. That saves tokens but can delete the one constraint you needed — better to summarize deliberately than hope the trim was lucky. [VERIFY: 2026-09-19]
  4. Claude Code / Cowork session hygiene. Long agent sessions accumulate tool results, skill content, and MCP payloads. Compact or restart at milestone boundaries; keep Claude Code token habits (clear goals, Done-when, thin CLAUDE.md) so you compact less often.
  5. Skills re-attach after compact. Agent clients that re-load skill or plugin content after a compact can quietly put thousands of tokens back into the window — skill packs that looked cheap mid-session become permanent ballast again. Audit skill load with skills costs; treat “compact then skills flood back” as a first-class pattern when you measure with /context-style tools.

Memory vs compaction

Compaction is an in-window strategy: summarize so this conversation can continue. Memory (external notes, tickets, project files, agent memory tools, or your own store) is an out-of-window strategy: durable facts live somewhere else and you load only what the next step needs.

Use memory when decisions must survive days, handoffs, or many sessions — architecture choices, customer constraints, runbooks. Use compaction when the problem is one long session approaching the window and you still need continuity inside that session. Best practice for agents: write observations and outcomes to artifacts; summarize tool results instead of re-pasting huge payloads; compact the chat when the transcript is mostly scaffolding. Loading an entire memory dump every turn recreates the problem compaction solved.

When compaction hurts

  • Lossy summaries. Critical constraints, error strings, or numeric thresholds disappear; the model invents confident wrong continuity. Prefer custom instructions that force IDs, decisions, and open risks into the summary — or preserve the last few turns with pause_after_compaction. [VERIFY: 2026-09-19]
  • Wrong trigger. Triggering at 50k on a chatty tool agent can mean constant compaction passes. Triggering only at default 150k can mean long stretches of expensive full-history billing and worse rot before the first summary. Tune to your median useful context, not the maximum window. [VERIFY: 2026-09-19]
  • Paying for compaction too often. If fat tool results force a compact every few turns, fix the tool tax first (tool-use, MCP) — summarization is a tax on top of a leak.
  • Forgetting to pass blocks back. Clients that strip unknown content types or rebuild message lists without the compaction block will either error or silently re-grow raw history. Treat the block as required state. [VERIFY: 2026-09-19]
  • Under-counting the bill. Observability that ignores usage.iterations will show “cheap” turns that actually paid for a 180k-token compaction pass. Fix meters before you declare victory. [VERIFY: 2026-09-19]

Practical checklist

  1. Measure window growth (API usage fields or client /context) before enabling compaction so you know the baseline.
  2. Prefer prevention: thinner tool results, page-range docs, bounded agent loops, and cached system prompts — see cut token usage.
  3. For API long-runners: enable compact-2026-01-12 / compact_20260112; start near the documented default trigger (150k) unless you have a measured reason to go lower (floor 50k). [VERIFY: 2026-09-19]
  4. Update cost tracking to sum usage.iterations, not only top-level tokens. [VERIFY: 2026-09-19]
  5. Cache system prompts and, where useful, compaction blocks with prompt caching. [VERIFY: 2026-09-19]
  6. After compact on skill-heavy agents, re-check whether skills / MCP reloaded the ballast you just paid to summarize away.
  7. At clean task boundaries, prefer a new thread + short brief over another compaction pass.
  8. Keep durable facts in external memory; keep the live window for active work.
  9. If long-thread spend stays opaque, paste for a written audit.

FAQ

Is compaction the same as prompt caching?

No. Caching discounts repeated identical prefixes; compaction replaces older content with a summary so the prefix is smaller. They stack well: compact to shrink, cache what remains stable. See prompt caching.

Does compaction work in claude.ai chat?

The documented Messages API compaction beta is an API / agent feature. Consumer chat products may trim or summarize differently (including FIFO). Confirm behavior in the product you actually use; do not assume the beta header applies to every UI. [VERIFY: 2026-09-19]

Will a cheaper model write the summary?

Not on the documented path — summarization uses the same model as the request. That is one reason trigger tuning and prevention matter: every compact pass is a full-price sampling iteration for that model. [VERIFY: 2026-09-19]

How does this relate to context editing?

Context editing can clear tool results or thinking blocks without rewriting the whole story. Compaction rewrites older history into a summary block. Use edits for surgical bloat; use compaction for long narrative growth. [VERIFY: 2026-09-19]

Next steps

  1. Map whether your pain is API long-runners (enable server compaction) or chat/agent sessions (briefs, restarts, skill/MCP hygiene).
  2. Fix fat inputs first — tools, docs, thinking — so compaction is rare.
  3. Wire metering to usage.iterations before you trust dashboards.
  4. Pair with context window, prompt caching, tool-use, skills, documents, Claude Code tokens, and cut token usage.
  5. If conversation and agent spend still will not explain itself, request a written token audit.

Compaction is leverage when a long thread has earned continuity — and a recurring tax when you use it to paper over tool dumps and skill ballast. Manage claude conversation compaction with the same Measure → Attribute → Reduce → Monitor loop as every other optimize spoke: keep the window honest, pay for summaries only when they replace expensive history, and park durable facts outside the model. For the wider lever set, return to the Optimize hub.

Keep reading