Long-Run Control

Compaction, Tool Clearing, and Memory

How to choose between Claude compaction, tool-result clearing, and memory when long conversations or agents exceed useful context.

Updated 2026-07-06 10 min read Cite this page

"Compaction maintains conversational flow for tasks requiring extensive back-and-forth."

Source: Effective context engineering for AI agents, Anthropic Engineering.

The problem is not just hitting the limit

A conversation can fail before it reaches a hard context limit. Tool output can crowd out the task. Old assumptions can conflict with new decisions. The model can spend attention reconciling stale logs instead of solving the next step. Context management is about keeping the active state useful, not merely keeping the request under a number.

Use compaction when dialogue is the valuable state

Compaction takes a long conversation, summarizes the important state, and continues from that compressed representation. It is best when the important material is not one re-fetchable blob but the outcome of many turns: decisions, unresolved questions, constraints, implementation notes, and user preferences.

A good compaction summary preserves facts that are hard to reconstruct and discards raw material that can be retrieved again. The risk is over-summarizing. If a number, path, exception, or decision boundary will matter later, it belongs in the summary.

Use tool clearing when results are bulky and re-fetchable

Tool-result clearing is different from compaction. It targets old tool outputs, especially file reads, search results, logs, and API responses that can be loaded again. The current run keeps recent context and replaces older tool results with placeholders or summaries.

This works best when tools are deterministic or cheap enough to re-run. It is riskier when the raw output was volatile, expensive, or impossible to reproduce.

Use memory when knowledge must survive the session

Memory is for continuity across context windows and sessions. It should contain stable preferences, architecture facts, project conventions, durable decisions, and pointers to where richer evidence lives. It should not become a transcript archive.

Memory needs governance. Facts change. Preferences change. Security requirements may forbid storing some information. A useful memory system includes audit, editing, expiration, and source links.

A simple choice rule

If you need the story of the conversation, compact. If you need to remove large old artifacts that can be fetched again, clear tool results. If you need future sessions to remember stable state, write memory. In real agents, all three can coexist, but each should solve a different problem.

FAQ

Can compaction lose important context?

Yes. Overly aggressive summaries can drop subtle facts. Tune compaction prompts on real traces and preserve precise decisions, paths, IDs, and unresolved risks.

Is memory a replacement for compaction?

No. Memory persists selected knowledge across sessions. Compaction keeps a long current conversation usable.

Sources Used

  • Context engineering: memory, compaction, and tool clearing, Claude Cookbook. Accessed 2026-07-06. Cookbook comparison of server-side compaction, context editing, tool-result clearing, and memory.
  • Context windows, Claude Platform Docs. Accessed 2026-07-06. Official context-window behavior, token accumulation, extended thinking and tool-use accounting, and compaction guidance.
  • Effective context engineering for AI agents, Anthropic Engineering. Accessed 2026-07-06. Primary explanation of context engineering, context pollution, compaction, note-taking, and sub-agent architectures.

Cite this page

Suggested citation: Claude Context, "Compaction, Tool Clearing, and Memory," updated 2026-07-06, https://claudecontext-com.pages.dev/compaction/.

This page is an independent educational resource and is not affiliated with Anthropic.