OrchestriAI
All terms

Context Compaction

Replacing the older part of an AI agent's conversation with a written summary when its context window nears full, so a long session can keep going.

Long agent runs forgetting what they were told?

Free. Three short fields, and we reply by email within one business day.

Technical details checked 2026-10-29

Concept map

Follow the connections to see how the term fits into a broader automation system.

In one sentence

Replacing the older part of an AI agent's conversation with a written summary when its context window nears full, so a long session can keep going.

Context compaction is how an AI agent keeps working after its conversation grows too long for the model's context window. Near the limit, the tool asks a model to summarize the session so far, starts a fresh window with that summary plus the most recent messages, and continues. To the user it looks like one long session. To the model it is a new start with notes.

Why it matters

Long agent runs, such as a coding task that takes hours or a support agent working a queue, produce far more text than any window holds. Anthropic's engineering team calls compaction the first lever for keeping long runs coherent. Claude Code, OpenCode and other agent tools compact automatically, and most also let you trigger it by hand.

What gets lost

A summary is shorter than what it replaces, so something is always dropped. Anthropic warns that overly aggressive compaction can lose subtle details whose importance only shows up later. In practice the losses we see most are exact identifiers such as commit SHAs and URLs, rules the user stated once early on, the list of files that were changed, and work still running in the background. After a bad compaction, an agent may redo finished work or break a rule it was given.

Ways to make it safer

Keep important state outside the chat in a plan file, task list or notes the agent rereads, which Anthropic calls structured note-taking. Clear old tool results, which are rarely needed again, before summarizing the conversation itself. Use a fixed summary format with required sections, and fill in facts the system can read directly, such as git status or tool history, from the source instead of from the model's memory. After a compaction, ask the agent to restate its goal and next step before it continues.

Our take

We built an open-source OpenCode Smart Compaction plugin around those ideas. The model writes a checked six-section checkpoint, and the plugin adds exact identifiers, touched files, git state and running subagents. It is listed on our projects page with the rest of our tools.

Keep following the system

Free. Three fields. We reply within one business day.

Long agent runs forgetting what they were told?

We set up checkpoints and outside notes so constraints and progress survive each compaction.

You'll talk to Shariq. Replies come from shariq@orchestriai.com. Leave out passwords and patient records.

What happens next

  1. 1.You send one line about the task.
  2. 2.Shariq reads every message and replies by email within one business day.
  3. 3.If it fits, you get a written plan or a short call. Your choice.
  4. 4.If it does not fit, we tell you and point you to a better option.
“Shariq built our Open Dental to GoHighLevel sync and our AI routing system for new patient inquiries. Both projects were delivered fast, worked right away, and he was responsive whenever we needed adjustments. He understands dental practice workflows and doesn't overcomplicate things.”
Michael Ling, Owner, Smile Again Dental