# Context compaction

Canonical page: https://www.theglitch.ai/ai-glossary/context-compaction

Condensing earlier turns, tool logs and file reads inside a running agent session into a compact state summary so work can continue without hitting context limits or degrading accuracy.

[Context compaction, common card \#260 in The Glitch AI glossary: Condensing earlier turns, tool logs and file reads inside a running agent session into a compact state summary so work can continue without hitting context limits or degrading accuracy.](https://www.theglitch.ai/images/cards/glossary/context-compaction.png?v=8d86fc439bbe1152)

GLS 260 · common

Also called: Compaction, Context summarization.

For: Builders

## Why it matters

Long coding and research sessions fill a context window fast with noisy tool output. Compacting early keeps latency lower, trims token spend and reduces context rot.

## In practice

After 45 tool calls debugging a payment webhook, the harness replaces raw 60-KB stack traces with a 600-token structured summary listing files changed, hypotheses disproved, failing test name and next step. The agent keeps working in a fresh budget without re-reading the entire repo.

## Watch for

Lossy summaries quietly drop edge cases, exact file paths or failed experiments, causing the agent to repeat dead ends. Keep critical invariants and failing assertions outside the summary in a structured file or checklist.

## How it compares

- [Agent checkpointing](https://www.theglitch.ai/ai-glossary/agent-checkpointing): Checkpointing persists durable step state to disk or a database for crash recovery and resume; compaction shrinks in-flight conversation tokens so the model stays sharp.

- [Context rot](https://www.theglitch.ai/ai-glossary/context-rot): Context rot is the accuracy drop as a session fills with stale or irrelevant text; compaction is one of the main techniques used to prevent it.

## Related terms

[Context engineering](https://www.theglitch.ai/ai-glossary/context-engineering) · [Context rot](https://www.theglitch.ai/ai-glossary/context-rot) · [Agent checkpointing](https://www.theglitch.ai/ai-glossary/agent-checkpointing) · [Agent memory](https://www.theglitch.ai/ai-glossary/agent-memory)

## Try it here

[Context engineering is the real job](https://www.theglitch.ai/learn/context-engineering) · [Claude Code, the operator’s way](https://www.theglitch.ai/learn/claude-code)

## Sources

- [Anthropic · Compaction overview (Claude Platform Docs)](https://docs.anthropic.com/en/docs/build-with-claude/compaction)

- [Anthropic · Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)

Use in an AI agent: connect MCP at https://www.theglitch.ai/mcp and call get\_glossary\_term with context-compaction, or read the [Markdown edition](https://www.theglitch.ai/ai-glossary/context-compaction.md).

Definition updated 2026-11-28.

[The Ultimate AI Glossary (2027): every term](https://www.theglitch.ai/ai-glossary)

---

Site: [The Glitch](https://www.theglitch.ai) · [About Rabin](https://www.theglitch.ai/about) · [Agent guide](https://www.theglitch.ai/agent.md)
