What you will be able to do
- Explain why every API request must carry the full conversation history, and why a long history still loses accuracy through context rot
- Trim and clear verbose tool results before they crowd out relevant context
- Identify which details progressive summarization tends to lose, including figures, percentages, dates and customer-stated expectations
- Design a persistent case-facts layer, kept outside the summarized history, for single-issue and multi-issue sessions
- Specify the structured output, including metadata such as dates, source locations and method, that subagents must return so downstream synthesis stays accurate
Key concept
Context as a finite attention budget — Everything in the window competes for the model's attention. Recall gets worse as the window fills, so the job is to decide what deserves a place in context, not to fit in as much as possible.
1.Full history every turn, and what it costs
Every context-management decision starts from one fact: the model keeps no memory between requests. The Messages API is stateless. To keep a conversation coherent, your application sends the whole conversation every time, including earlier user turns, earlier assistant replies, and tool results. If you drop a turn, the model has never seen it. A customer who gave their order number in turn 2 will be asked for it again in turn 9.
message = anthropic.Anthropic().messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude"},
{"role": "assistant", "content": "Hello!"},
{"role": "user", "content": "Can you describe LLMs to me?"},
],
)"Complete" history means each request's input holds everything said so far plus the new user message. The context-windows documentation describes each turn as an input phase that contains all previous conversation history plus the current user message, followed by an output phase whose response becomes part of the input for the next turn. The history includes the assistant's own earlier replies and the tool results in messages, not only what the user typed. The practical rules follow from that. Append every new user message and every assistant response to the list you send next. Never trim turns silently to save tokens, because a missing turn can't be recovered by the model and the conversation stops being coherent. When you do need to shrink the history, use a deliberate mechanism such as compaction or context editing. Even with server-side context editing, your own application keeps the full, unmodified history and keeps sending it.
The history therefore grows with every turn, and all of it counts against the window: the system prompt, every message, every tool result and the tool definitions. A large window does not make this free. The context-windows documentation states that more context isn't automatically better, because accuracy and recall degrade as token count grows. Anthropic's context-engineering guidance calls this an "attention budget": every new token uses some of it. You can't fix the problem by dropping history, since coherence depends on it. You fix it by controlling what goes into the history. The rest of this page covers the places where that control matters most: tool output, summaries, the facts a case depends on, and what subagents hand back.
Checkpoint 1 of 8· Check yourself
A support agent on a 1M-token model starts giving vaguer answers late in long sessions, even though it is far below the token limit. What is the most likely explanation?
Context rot appears well before the window is full. Curating what goes into context matters as much as how much space is available.
“As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”Source: platform.claude.com
2.Tool results: the biggest source of waste
Tool results grow context faster than anything else, and they are often the least useful part of it. Suppose an order-lookup tool returns 40-odd fields per order, but a return request only needs five of them: order ID, status, amount, purchase date and return eligibility. (These numbers are an illustration, not from the docs.) Each lookup adds all 40 fields to the history, and because the history is re-sent on every request, those tokens are paid for on every later turn too. The docs state the general problem: accumulated tool results consume the window, and long-running agents can run out of context before the task is finished.
There are two places to cut. The first is before the result enters the history. Your own tool handler can map the raw response down to the fields that matter for the task before returning it. Programmatic tool calling does something similar for chains of calls: Claude writes one script that runs in a sandbox, and the intermediate results never enter the conversation history. The second is after a result has served its purpose. Context editing's tool result clearing removes the oldest results once a threshold is crossed. Each one is replaced with placeholder text, and the record of the tool call is kept, so the model knows it made the call and can call the tool again if it needs the data.
| Option | Default | What it controls |
|---|---|---|
| trigger | 100,000 input tokens | When clearing begins |
| keep | 3 tool uses | How many recent tool use/result pairs survive |
| clear_at_least | None | Minimum tokens cleared, so a cache break is worthwhile |
| exclude_tools | None | Tools whose results are never cleared |
| clear_tool_inputs | false | Whether the tool call parameters are cleared too |
Use exclude_tools to protect results you can't afford to lose. If one tool records the facts the whole case depends on, list it there and clearing will never touch it. Clearing also runs on the server, before the prompt reaches Claude. Your application should keep storing the full, unmodified history locally, as before.
Checkpoint 2 of 8· Fill the gap
Which strategy type turns on automatic clearing of old tool results?
response = client.beta.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
messages=[{"role": "user", "content": "Search for recent developments in AI"}],
tools=[{"type": "web_search_20250305", "name": "web_search"}],
betas=["context-management-2025-06-27"],
context_management={"edits": [{"type": " ? "}]},
)clear_tool_uses_20250919 is the tool-result clearing strategy. clear_thinking_20251015 clears thinking blocks, and the other two are tool types, not edit strategies.
Source: platform.claude.comCheckpoint 3 of 8· Check yourself
Your agent's account-lookup tool returns the facts every later turn relies on, and tool result clearing is enabled. How do you keep those results in context?
exclude_tools names tools whose results are never cleared. clear_tool_inputs clears more, not less, and raising keep defeats the purpose of clearing.
“List of tool names whose tool uses and results should never be cleared. Useful for preserving important context.”Source: platform.claude.com
3.What progressive summarization loses
Clearing removes tool output. Compaction goes further: it rewrites the whole conversation. When the history nears a threshold, Claude summarizes it and the summary replaces the history. Each later compaction summarizes a summary, which is why the loss is called progressive.
The cookbook says plainly that a compaction summary may drop specific numbers or exact phrasing. Four kinds of detail are most at risk. Numerical values such as amounts and quantities, percentages such as a discount or fee, and dates such as a promised deadline are exact by nature, so a vaguer paraphrase is simply wrong. Customer-stated expectations, such as what the customer said they would do if the issue isn't resolved, are easy to flatten into a neutral description. The examples here are illustrations, not from the docs. "$247.83 refund promised by 14 March, customer said they'd cancel otherwise" can become "customer requested a refund." "A 15% restocking fee was waived" can become "fees were discussed." "Customer expects a reply within two days" can become "customer wants a quick answer." Each version is plausible and each has lost the part the next agent action depends on. Because each compaction summarizes the previous summary, the loss compounds.
Anthropic's guidance warns that aggressive compaction can lose context whose importance only becomes apparent later. The default SDK summary prompt addresses part of this with a "Context to Preserve" section covering user preferences, domain-specific details, and promises made to the user. A custom summary prompt can go further and require exact figures, percentages, dates and the customer's own stated expectations to be copied verbatim. Still, any summary loses something by design, so the facts you can't afford to lose should not depend on the summary at all.
Checkpoint 4 of 8· Put it in order
Put the SDK's client-side compaction steps in order.
- 1.The conversation continues from the summary
- 2.The SDK replaces the entire message history with the summary
- 3.The SDK checks total token usage against the threshold after a response
- 4.A summary prompt is injected and Claude writes a summary in <summary> tags
Compaction is checked after each response. Once the threshold is exceeded, a summary is generated, it replaces the history, and work resumes from it.
“The SDK extracts the summary and replaces the entire message history with it.”Source: platform.claude.com
4.A case-facts layer outside the summary
The fix is to store transactional facts somewhere summarization can't reach. Pull amounts, dates, order numbers and statuses out as they come up, keep them in a structured "case facts" block, and include that block in every prompt separately from the summarized history. The sources don't use the term "case facts". What they describe is the same pattern under the name structured note-taking: the agent writes notes that persist outside the context window and are read back in later. The memory tool supports this with file-based storage that survives context resets.
Multi-issue sessions need one more step. If a customer raises two problems, a single running narrative merges them, and a later "the amount" could mean either one. Keep one structured record per issue, each with its own ID, amount and status, in its own context layer. That way every reference resolves to exactly one issue.
| Information | Where it lives | Why |
|---|---|---|
| Exact amounts, dates, IDs, statuses | Persistent case-facts block, one record per issue | Compaction may drop specific numbers |
| Conversational flow and decisions | Summarized or compacted history | Summaries keep goals and decisions |
| Raw tool payloads already processed | Cleared, or trimmed before entering history | Re-fetchable, and they use up attention |
Checkpoint 5 of 8· Exam question
A billing support agent has been summarizing a lengthy chat every few turns to keep the prompt short. After the third summarization pass, the running summary reads "the customer wants a refund soon and mentioned an order from last month," even though the original messages contained an exact order number, a refund amount of $214.88, and a customer-stated deadline of the 15th. Which practice best addresses this failure mode going forward?
Correct answer: A — Track the order number, exact refund amount, and stated deadline in a persistent case-facts block included in every prompt
- A. Correct — a persistent case-facts block keeps precise transactional details intact regardless of how many times the surrounding narrative gets condensed.
- B. More frequent summarization still compresses details each time and does nothing to stop numeric precision from being lost; it only changes how often the loss happens.
- C. Repeatedly asking the customer to restate facts already given creates a poor experience and does not fix the underlying context-management gap.
- D. A larger context window delays when compression is needed but does not prevent numeric detail loss once summarization does occur, and doesn't address the immediate failure already observed.
Checkpoint 6 of 8· Exam question
A research assistant aggregates outputs from five subagents (market sizing, competitor pricing, regulatory risk, customer sentiment, distribution channels) into one long combined document that is then passed to a synthesis step. The synthesis step's final memo omits the regulatory risk finding, which appeared in the third of five sections in the middle of the document. What is the best way to structure the aggregated input to prevent this in future runs?
Correct answer: A — Place a short key-findings summary at the top of the aggregated document, then present each detailed section beneath an explicit heading
- A. Correct — leading with a concise key-findings summary and using explicit section headers surfaces critical content regardless of where it originated, directly countering the middle-of-document drop-off.
- B. Reordering to favor a single finding only protects that one item and still leaves every other middle section vulnerable in different runs.
- C. Rereading does not reliably compensate for position effects and adds latency without a structural fix.
- D. Splitting the document without adding a summary or headers still leaves each half susceptible to internal middle-of-input drop-off.
Checkpoint 7 of 8· Match them up
Match each technique to what it does to context.
Tap a term, then the definition that fits it.
Compaction works on the whole transcript, clearing works only on tool results, and memory keeps information outside the window altogether. That is why exact facts belong in memory or a case-facts block.
“instructs Claude to summarize the conversation history, then replaces the full history with that summary”Source: platform.claude.com
5.Subagents: structured outputs with metadata
Subagents are another way to keep context small. A subagent runs in its own conversation, and the SDK documentation says its intermediate tool calls and results stay inside it while only its final message returns to the parent. That final message is therefore the only channel the coordinator has, so what it contains decides how accurate the downstream synthesis can be. Anthropic's context-engineering guidance says a subagent may use tens of thousands of tokens exploring but should return only a condensed, distilled summary of its work.
Two design rules follow. First, ask for structured findings, not verbose content or reasoning chains. The orchestration example in the docs tells its subagents to finish by calling a report_findings tool and to "Return findings, not narration." When the coordinator has a limited context budget, this keeps its window for synthesis. Second, require metadata with every finding. The multi-agent research post says each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries. Without that, subagents duplicate work, and its example shows why timeframe matters: one subagent explored the 2021 automotive chip crisis while others investigated current 2025 supply chains. The docs don't list required metadata fields, so treat the following as a design recommendation built on those principles. Have each finding carry its date or time period, its source location (URL, document or section), and the method or scope behind it, for example what was searched and what was excluded. With those fields the coordinator can reconcile two figures that differ because they come from different years, cite which source backs which claim, and spot gaps instead of averaging mismatched numbers.
If outputs are large, there is a second option. The research post describes subagents storing their work in an external system and passing lightweight references back to the coordinator. This avoids the information loss of a multi-stage "game of telephone" and the token cost of copying large outputs through the conversation history.
Checkpoint 8 of 8· Check yourself
A coordinator synthesizes findings from several research subagents and needs each one to report its figures with dates and sources. Where should that requirement be specified?
The subagent only has the task description it is given, so the output format, including any metadata fields, belongs there. Metadata missing from the returned findings can't be recovered by the coordinator afterward.
“Each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries.”Source: www.anthropic.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.With a 1M-token window you can keep every tool payload and transcript line, because more context always means better answers.Why is that wrong?
Recall and accuracy degrade as token count grows, so a bigger window only means more space that needs curating.
Covered in Full history every turn, and what it costs
2.A good compaction summary keeps exact refund amounts and promised dates, so a separate facts block is redundant.Why is that wrong?
Summaries keep decisions and the gist but may drop specific numbers and exact wording. Store those facts outside the summarized history.
Covered in What progressive summarization loses
3.Once server-side context editing clears old tool results, you should delete them from your local history too, to keep the two in sync.Why is that wrong?
Context editing runs on the server before the prompt reaches Claude. Your client keeps and sends the full, unmodified history.
Covered in Tool results: the biggest source of waste
4.A subagent should return its full tool output and reasoning chain so the coordinator can check everything itself.Why is that wrong?
The point of a subagent is to keep detailed exploration in its own context and return only a condensed result, which should be structured and carry the metadata the coordinator needs.
Covered in Subagents: structured outputs with metadata
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The Messages API is stateless, which means that you always send the full conversational history to the API.”
↩︎ Full history every turn, and what it costs - 2.
“Input phase: Contains all previous conversation history plus the current user message”
↩︎ Full history every turn, and what it costs“more context isn't automatically better”
↩︎ Full history every turn, and what it costs“As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
↩︎ Key concept“more context isn't automatically better”
↩︎ Exam trap 1“As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
↩︎ Checkpoint - 3.
“Every new token introduced depletes this budget by some amount”
↩︎ Full history every turn, and what it costs“overly aggressive compaction can result in the loss of subtle but critical context whose importance only becomes apparent later”
↩︎ What progressive summarization loses“the agent regularly writes notes persisted to memory outside of the context window”
↩︎ A case-facts layer outside the summary“returns only a condensed, distilled summary of its work (often 1,000-2,000 tokens)”
↩︎ Exam trap 4 - 4.
“Tool definitions and accumulated tool_result blocks consume your context window.”
↩︎ Tool results: the biggest source of waste“The intermediate results never enter the conversation history.”
↩︎ Tool results: the biggest source of waste - 5.
“The API replaces each cleared result with placeholder text indicating to Claude that it was removed.”
↩︎ Tool results: the biggest source of waste“Context to Preserve: User preferences, domain-specific details, and commitments made.”
↩︎ What progressive summarization loses“instructs Claude to summarize the conversation history, then replaces the full history with that summary”
↩︎ A case-facts layer outside the summary“Your client application maintains the full, unmodified conversation history.”
↩︎ Exam trap 3“List of tool names whose tool uses and results should never be cleared. Useful for preserving important context.”
↩︎ Checkpoint“The SDK extracts the summary and replaces the entire message history with it.”
↩︎ Checkpoint - 6.https://platform.claude.com/cookbook/tool-use-context-engineering-context-engineering-toolsSecondary source
“If the agent does need the data, it just calls the tool again.”
↩︎ Tool results: the biggest source of waste“The summary preserves key decisions and facts but may drop specific numbers or exact phrasing.”
↩︎ What progressive summarization loses“maintaining critical context that would otherwise be lost across dozens of tool calls or across context resets”
↩︎ A case-facts layer outside the summary“The summary preserves key decisions and facts but may drop specific numbers or exact phrasing.”
↩︎ Exam trap 2 - 7.https://code.claude.com/docs/en/agent-sdk/subagentsOfficial docs
“intermediate tool calls and results stay inside the subagent; only its final message returns to the parent”
↩︎ Subagents: structured outputs with metadata - 8.
“Return findings, not narration.”
↩︎ Subagents: structured outputs with metadata - 9.
“Each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries.”
↩︎ Subagents: structured outputs with metadata“one subagent explored the 2021 automotive chip crisis while 2 others duplicated work investigating current 2025 supply chains”
↩︎ Subagents: structured outputs with metadata“Subagents call tools to store their work in external systems, then pass lightweight references back to the coordinator.”
↩︎ Subagents: structured outputs with metadata