What You Need to Know
The context window is everything that Claude sees in one request. The window is measured in tokens. Every token in the window is billed on every request where it appears. The window holds four things:
- the system prompt
- every message in the history, including tool results, images and documents
- the tool definitions
- the output that Claude generates, including thinking tokens (the tokens of Claude's built-in reasoning)
This lesson uses one made-up example throughout: an insurance company whose claims team uses a Claude assistant. The assistant's system prompt, policy-lookup tool, conversation and policy documents are all in the window. All of them are billed on every request.
Counting the Window
Two documented, free instruments count tokens. The usage field on every response reports what the request consumed. With caching, input tokens are of three kinds: plain, cache-read and cache-write. All three kinds count towards the window. The token counting API estimates a request before you send it. The API's count is inexact, and the API has its own rate limits. Estimate requests before you send them, and make this part of the design. For example, the insurance company counts its largest policy-document request before launch.
Overflow of the window is a hard failure, and it has two distinct cases. Oversized input is rejected outright. On current models, generation that reaches the limit stops early, with its own documented stop reason (the response field that says why generation stopped). You can detect both cases, so set alerts on them. Plan the token budget so that routine requests never approach either case.
Context Rot: Capacity Is Not a Strategy
Each model has a window size from a set of tiers, and output has its own limit. A bigger window gives more space, but it does not decide what that space holds. Anthropic's docs explain why: "As token count grows, accuracy and recall degrade, a phenomenon known as context rot. This makes curating what's in context just as important as how much space is available." Anthropic's engineering guidance calls context an attention budget. The goal of that guidance is the smallest possible set of high-signal tokens (tokens that carry information the task needs) that maximises the likelihood of the desired outcome.
So ask whether every token is worth including, not whether it fits. If the insurance company loads its whole policy library into a million-token window, this fails in three ways:
- context rot degrades answer quality
- the company pays for the full load on every request
- latency grows with input size
The Replay Bill
Each turn resends the whole history. Over 20 turns on one insurance claim, a 50k-token history is 50k input tokens twenty times. At high volume, careless context costs more than model choice and becomes the largest cost line. This makes context strategy a Domain 2 economics decision. Curation, caching and compaction each reduce a different part of this replay bill.
The Management Toolkit
- Curate first. Send the fields, not the file: send the policy fields that a question needs, not the whole policy record. Summarise verbose history and remove formatting noise. Anthropic's long-context guidance says to put longform documents, such as a policy document, at the top of the prompt, above the query. The cheapest optimisation is to leave out tokens that the task does not need.
- Retrieve instead of sending everything. When the source corpus is larger than a sensible context, retrieval brings only the relevant passages for each request. An example is the two policy documents that a question needs. Whether to choose retrieval is a Domain 2 cost-and-context judgement. How to design the RAG pipeline (the system that retrieves the passages) is Domain 3.
- Compact long conversations. Server-side compaction (beta, Claude 4.6-generation and later models) summarises earlier turns into a compaction block. The conversation can then continue past the window limit. A beta feature is not yet final. Compaction is Anthropic's recommended primary strategy for long-running conversations and agentic sessions, such as a full working day on claims. There are two kinds (checked 29 October 2026). With on-demand compaction, your application sends a request that asks for the summary. With threshold compaction, the API writes the summary when input tokens reach a trigger threshold. Anthropic's compaction docs say to use on-demand compaction wherever it is available.
- Edit agentic context. Context editing (beta) clears the oldest tool results (and optionally thinking blocks, the parts of a response that hold Claude's reasoning) server-side once a threshold is reached. It replaces them with placeholders. Use it where the full history adds nothing, such as policy lookups from hours earlier.
- Make smaller savings with structure. Tight output contracts make responses shorter. Minimal tool definitions make the fixed overhead smaller. So do deferred definitions, which load only when a request needs them.
Truncation looks like optimisation. Truncation cuts context to a fixed token count, whatever the task needs, and it loses quality silently. Curation selects by relevance. Truncation cuts by position. If you cut a long policy document to its opening, the later sections disappear unflagged. Optimisation must preserve the information that the task needs.
Caching Does Not Free Window Space
Anthropic's context docs state that cached prompt prefixes still occupy the context window. Caching changes what you pay for those tokens, not whether they count. The insurance company's cached policy documents cost less and take the same space. Caching is a cost-and-latency instrument (objective 2.5). Curation, compaction and context editing manage the window.
In the exam
The exam tests whether you treat the window as a budget that you actively manage or as capacity to fill. When cost and quality problems share one question, distinguish them. Some options offer "Enable caching" as the fix for window overflow or for a decline in quality late in the conversation. Such an option is a deliberate wrong answer. Truncation is also a deliberate wrong answer. A wrong option in the guide's own sample question cut a policy to its first 1,000 tokens.
Current window sizes, output limits and stop-reason identifiers are in the Domain 2 quick reference.
Exam Traps
Answering a cost or quality problem by moving to the bigger window and loading more
The window gives space. It does not choose the content. Context rot, per-request cost, and latency all worsen with load, so the bigger window amplifies the exact problem it was meant to solve.
Enabling prompt caching to make room when requests approach the window limit
Cached prefixes still occupy the window. Caching changes what those tokens cost, not whether they count. Free window space by curating context, compacting the conversation, or editing out stale content.
Cutting context to a fixed token count regardless of what the task needs
Blind truncation discards task-required information, a silent quality loss that looks like optimisation. Curation selects by relevance; truncation cuts by position.
Letting agentic sessions carry every stale tool result and thinking block forward indefinitely
Replayed content that the task no longer needs is billed every turn and degrades recall. Compaction and context editing exist precisely to reclaim that space while preserving working state.
Practice Scenario
A contract-analysis assistant holds multi-hour analyst conversations. By hour two, requests carry 150k tokens of history including dozens of large stale tool results from clause lookups; costs are 6x projection and answer quality on late-conversation questions is degrading. What should the architect do?
Build Exercise
Write a Context Budget for a Long-Running Workflow
What you'll learn
- How to break real request context into its component costs using the usage field
- How to check requests in advance with the token counting API
- How to compute the replay bill and find the dominant cost line
- How to match a management strategy to each context component
- How to set guardrails: token limits, compaction triggers, and overflow alerts
- Instrument one Claude call path: log the usage field per request and break input into system prompt, tool definitions, history, tool results, and per-request data
Why: You cannot budget what you have not counted. The component breakdown reveals which part is actually growing.
You should see: A per-request breakdown table with a token figure per component and a total matching the reported usage.
- Use the token counting API to estimate a representative request before you send it and compare the estimate with reported usage
Why: Estimating requests before you send them belongs in the design. The comparison teaches you how much margin to leave below the token limit.
You should see: Two numbers side by side and the percentage difference.
- Compute the replay bill: tokens carried per turn x turns per session x sessions per month x input price, and identify the dominant line
Why: Replayed history at volume is usually the dominant cost line, ahead of model choice. Making it explicit directs the fix.
You should see: A monthly figure per component, ranked, with one clearly dominant.
- Apply one strategy per line: curation for noise, retrieval for corpus content, compaction plus tool-result clearing for long sessions; state what each preserves and discards
Why: Each strategy reduces a different part of the bill, and each has a preservation trade-off that must be stated, not discovered.
You should see: A strategy per dominant line with one sentence on what is preserved and one on what is discarded.
- Define the guardrail: the per-request token limit, the trigger threshold for compaction, and the alert on stop_reason model_context_window_exceeded
Why: Without alerts, spending moves away from the budget unnoticed. The guardrail turns the budget into an operational control.
You should see: Three lines: token limit, trigger, alert destination.
Sources
- Context windows — Anthropic
- Token counting — Anthropic
- Compaction — Anthropic
- Context editing — Anthropic
- Effective context engineering for AI agents — Anthropic
- Claude Certified Architect Professional Exam Guide (v1.0) — Domain 2 — Anthropic