What is compaction, and how does it differ from simply deleting old messages?
Compaction refers to automatically condensing a long conversation or task history into a compact summary that replaces the verbatim original content, freeing up space in the context window. This differs from simple deletion—deletion discards information outright, while compaction attempts to preserve the key conclusions, agreed-upon points, and unresolved questions, just in a more condensed form.
For the user, ideal compaction should be largely invisible—the conversation can continue, and the model still remembers the key directions discussed earlier, it's just no longer retaining every original sentence verbatim.
Why does compaction exist, and what problem does it solve?
Even as context windows keep growing, long-running tasks—multi-turn debugging, lengthy research collaboration, or an agent executing dozens of consecutive steps—can still fill up the window, or even without filling it, excessive content volume can trigger context rot, lowering the model's accuracy at extracting key points. Compaction exists to extend how long a conversation or task can keep running without interruption.
This matters especially for long-running agent applications: if the conversation had to restart entirely every time it approached the window limit, both user experience and task continuity would suffer. Automatic compaction lets the system handle this quietly in the background without disrupting the user's workflow.
How does compaction actually work in practice? What are common approaches?
Common implementations include: "rolling summarization"—once a conversation accumulates near a certain token threshold, the earliest segment gets condensed into a few sentences that replace the original text in context, with this summarized range continuing to advance as the conversation proceeds; "selective retention"—prioritizing content the user has explicitly flagged as important, or that the system identifies as a key decision point, while background information gets compressed first; and "tool output trimming"—the large volume of intermediate output an agent generates while executing a task (like code execution results or search results) is typically condensed into a conclusory summary once the task is done, without needing to retain the full raw output.
A shared challenge across these approaches is that the criteria for what to compress are hard to fully automate—if a summary drops a detail that turns out to be needed later, it creates a new problem rather than solving the original one.
What does compaction mean for me, and what should I watch for in practice?
If you're using Claude for long-running tasks—long-form collaborative writing, multi-step agent workflows—understanding that compaction exists helps you recognize when "the model seems to have forgotten an earlier detail" is a normal side effect of compaction rather than a model error. If you notice an important constraint established early on (like "this document can't use passive voice") getting ignored later in the conversation, it's likely that detail was summarized away during compaction—at that point, simply restating it directly is usually more efficient than trying to diagnose why.
For rules or constraints that are truly critical and can't afford to be dropped during compaction, a practical habit is to periodically restate them in the conversation, or keep them as a short standalone list you paste in repeatedly, rather than relying entirely on the system to judge what should be preserved.
Claude Code automatically triggers compaction during long, multi-step coding tasks once a conversation reaches a certain length, condensing the detailed process of completed steps (like line-by-line code change logs) into a conclusory statement such as "Completed: fixed null pointer error in login module, added unit tests"—letting subsequent steps continue without overflowing the context window.
Compaction's advantage is extending how long a task can keep running without interruption, avoiding frequent conversation restarts; the downside is that compression criteria can't be fully automated, and important details may get dropped during summarization—tasks demanding extreme precision (like verbatim legal document comparison) require extra vigilance and proactively restating key constraints.