What You Need to Know
The context window is everything Claude sees in one request, counted in tokens. Every token in it is billed on every request it appears in. The window holds four things:
- the system prompt
- every message in the history, including tool results, images and documents
- the tool definitions
- the output being generated, thinking tokens included
Take a pharmacy whose counter staff use a Claude assistant. Its system prompt, stock-lookup tool, conversation and leaflet pages are all in the window, 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 splits into plain, cache-read and cache-write tokens, and all three count toward the window. The token counting API estimates a request before you send it. Its count is inexact, and it has its own rate limits. Pre-flight estimation belongs in the design: the pharmacy counts its largest leaflet request before launch.
Overflow is a hard failure with two distinct cases. Oversized input is rejected outright. On current models, generation that reaches the limit stops early with its own documented stop reason. Both are detectable, so alert on them. Budget so routine requests never come near either.
Context Rot: Capacity Is Not a Strategy
Window sizes are tiered by model, and output has its own ceiling. A bigger window is capacity, not a strategy. 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. Its goal is the smallest possible set of high-signal tokens that maximises the likelihood of the desired outcome.
So ask whether every token earns its place, not whether it fits. Loading the pharmacy's whole leaflet library into a million-token window fails three ways:
- rot degrades answer quality
- every request pays for the full load
- latency grows with input size
The Replay Bill
Each turn resends the whole history. Over 20 turns at the pharmacy counter, a 50k-token history is 50k input tokens twenty times. At volume, careless context becomes the dominant cost line, ahead of model choice. That makes context strategy a Domain 2 economics decision. Curation, caching and compaction each attack a different part of the replay bill.
The Management Toolkit
- Curate first. Send the fields, not the file: the stock fields a question needs, not the whole stock list. Summarise verbose history and strip formatting noise. Put longform documents, such as a leaflet, at the top of the prompt, above the query, per Anthropic's long-context guidance. The cheapest optimisation is the token that never enters the request.
- Retrieve instead of stuffing. When the source corpus exceeds sensible context, retrieval brings only the relevant passages for each request, such as the two leaflets a question needs. Choosing retrieval is a Domain 2 cost-and-context judgement; designing the RAG pipeline is Domain 3.
- Compact long conversations. Server-side compaction (beta, Claude 4.6-generation and later models) summarises earlier turns into a compaction block when input tokens reach a trigger threshold. The conversation can then continue past the window limit. It is Anthropic's recommended primary strategy for long-running conversations and agentic sessions, such as a full shift at the counter.
- Edit agentic context. Context editing (beta) clears the oldest tool results (and optionally thinking blocks) server-side once a threshold is reached. It replaces them with placeholders. Use it where the full history adds nothing, such as stock lookups from hours earlier.
- Trim the margins with structure. Tight output contracts shrink responses. Lean, deferred tool definitions shrink fixed overhead.
Truncation passes for optimisation. It cuts context to a fixed token count, whatever the task needs, and loses quality silently. Curation selects by signal; truncation cuts by position. Cut a long leaflet to its opening and the later sections vanish unflagged. Optimisation must preserve task-required information.
Caching Is Not Window Relief
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 pharmacy's cached leaflets cost less and take the same space. Caching is a cost-and-latency instrument (objective 2.5); the window belongs to curation, compaction and editing.
In the exam
The exam tests whether you treat the window as a budget under active management or as capacity to be filled. When cost and quality problems share one stem, tell them apart. "Enable caching" offered as the fix for window overflow or late-conversation quality decline is a planted wrong answer. So is truncation: the guide's own sample distractor cut a policy to its first 1,000 tokens.
Current window sizes, output ceilings 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 is capacity, not curation. 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 the bill, not the fit — overflow and rot are untouched. This is the most reliably planted wrong answer in window stems.
Cutting context to a fixed token count regardless of what the task needs
Blind truncation discards task-required information — silent quality loss dressed as optimisation. Curation selects by signal; truncation cuts by position.
Letting agentic sessions carry every stale tool result and thinking block forward indefinitely
Replayed dead weight 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 pre-flight requests 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: ceilings, 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 slice 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 pre-flight a representative request and compare the estimate with reported usage
Why: Pre-flight estimation belongs in the design. The comparison teaches you how much slack to build into the ceiling.
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 attacks 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 ceiling, the trigger threshold for compaction, and the alert on stop_reason model_context_window_exceeded
Why: Budgets without alarms drift. The guardrail turns the budget into an operational control.
You should see: Three lines: ceiling, 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