Your context window is full. Now what?
Every long-running agent hits the same limit eventually. I've learned to treat it as a resource to manage, not a hard wall to crash into.
Performance degrades as history accumulates, well before you hit it. Chroma's Context Rot study tested 18 frontier LLMs and found that every model showed degradation as input grew, with sharp performance drops past certain length thresholds. Giving a model more information can actively make it perform worse, which is exactly why managing it deliberately matters.
The instinct when you first hit a context limit is to reach for one of two approaches. Truncating from the beginning loses the original task framing and early decisions, exactly what you want to preserve most. Letting it run until the model errors means silent quality degradation followed by a hard crash. Neither is good. Both are popular.
Rolling summarization
The idea is simple: when the context reaches a set threshold, drop the oldest messages, summarize what was dropped, and inject that summary into future requests. You want to trigger this ahead of the limit, not at it. A single turn can spike token usage fast when it triggers multiple tool executions. A defensive trim at 100% is worth adding as a fallback for cases where the window has already been exceeded.
For very long sessions, consider two tiers: a recent summary and a historical one that gets updated by combining the existing summary with newly dropped messages and re-summarizing. It handles extended conversations without losing fidelity over time. For most use cases, a single tier is enough. Start there.
In some cases, it's also worth clearing old tool results from context as you go. Once a tool call is deep in history, the raw output is mostly noise. The model has already used it. Anthropic's context engineering guide calls this one of the lightest-touch forms of compaction.
The agent handoff pattern
Rolling summarization and agent handoff are mechanically similar. Both summarize context and inject it going forward. The difference is what happens to the window itself. Rolling summarization keeps the same session, so the window is still partially occupied by the summary and recent turns. Agent handoff spawns a fresh instance with only the handoff document, so the window starts nearly empty.
That matters more than it sounds. Anthropic's Harness Design for Long-Running Application Development describes a phenomenon called "context anxiety," where models near their limit start wrapping up work prematurely or degrading in quality before hitting the hard stop. Starting fresh sidesteps that entirely. The handoff document captures what was accomplished, current state, what remains, and decisions made along the way.
RAG / just-in-time retrieval
Rather than loading everything upfront, retrieve only what's relevant at query time. Index whatever is too large to load whole (documentation, tickets, playbooks, user history, codebases) and pull only what matches the current task. The window stays lean because each turn fetches what it needs rather than carrying a fixed preload. How you structure context is how you structure behavior covers this pattern in depth.
Giving users control
For user-facing products, any of these pairs well with surfacing context state directly in the UI. Show users how full the window is and give them a way to compact and continue. Claude Code does this with /compact; Cursor with automatic summarization and @ mentions.
How the approaches compare
| Approach | Best for | Complexity |
|---|---|---|
| Rolling summarization | Background agents, chat continuity | Low |
| Agent handoff | Long agentic tasks with heavy tool use | Medium |
| RAG / just-in-time retrieval | Large codebase navigation | High |
| UI compaction | User-facing products | Low |
All of these approaches share the same premise: the context window is a resource, not a wall.
Context window limits aren't a scaling problem. They're a design problem. One you can actually solve.