# Context Compaction

> Summing up a long chat so it fits in the window again.

**Field:** Artificial Intelligence  
**Category:** LLMs  
**Also known as:** Conversation Compaction, Context Summarization

## Think of it like

It is like packing for a trip. You fold a big pile of clothes into one small bag.

## Definition

Context compaction is shrinking a long chat so it fits back in the model's context window. When the window is nearly full, the app asks the model to sum up what has happened so far. The summary takes the place of the old messages, and the chat goes on from there. Key facts, choices and open tasks stay, while long tool outputs and side talk are dropped. Some details are always lost, so key rules belong in a file the app loads again.

## Example

In Claude Code, typing /compact swaps the chat so far for a short summary. The task goes on with lots of free space.

## Why it matters

Long agent tasks fill the window fast. Compaction lets them keep going without starting over.

## Common mistake

Expecting every detail to stay. A summary drops things, so write key rules in a file.

## Three principles

- **Sum up the past.** Old turns become one note.
- **Free space.** Room for new work.
- **Some loss.** Details can drop out.

## Related terms

- [Context Window](https://learn.benibix.com/term/ai/context-window)
- [Context Rot](https://learn.benibix.com/term/ai/context-rot)
- [Auto-Compact](https://learn.benibix.com/term/ai/auto-compact)
- [Lost in the Middle](https://learn.benibix.com/term/ai/lost-in-the-middle)
- [Context Engineering](https://learn.benibix.com/term/ai/context-engineering)

## Taught in

- [The LLM Context Window](https://learn.benibix.com/learn/ai-llms/llm-context-window): LLMs, 4/15

![A context window nearly full of old messages and tool output. An arrow leads to the same window holding one short summary and lots of empty space.](https://learn.benibix.com/diagrams/ai9-context-compaction.svg)

---

Source: https://learn.benibix.com/term/ai/context-compaction
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
