CertSafari
    Anthropic Claude Certified Architect – Professional (CCAR-P)· Lessons

    Domain 2 · Lesson 10/38

    Context Window Budgeting: What Counts and How to Measure It

    Optimize context windows and manage token usage

    10 min read
    2.6% of exam
    4 sources
    Published 4 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Say which parts of a request count toward Claude's context window, including thinking and tool definitions
    • Explain how previous-turn thinking blocks are kept or stripped depending on the model, and how they are billed
    • Estimate a request's size in advance with the token counting endpoint, and read the usage fields of a response
    • Name the models that receive automatic context-awareness budget tags

    Key concept

    Context rot — The context window is the model's working memory for one request. It has a hard size limit, but it also gets worse as it fills: the more tokens in it, the less reliably the model recalls what is there. Managing tokens is about keeping the right content in context, not just staying under the limit.

    1.What fills the context window

    The context window is all the text Claude can refer to while it writes a response, and that includes the response itself. It is not the training data. The docs call it the model's "working memory". In a standard API conversation, every turn piles up: each request carries the full history plus the new user message, and Claude's reply becomes part of the input for the next turn.

    The budget covers more than the visible messages. The system prompt counts. Every message counts, including tool results, images and documents. Your tool definitions count too, which matters for agents that register dozens of tools. On the output side, everything Claude generates for the turn counts, including its extended thinking. So you budget for all of it together: system prompt + tool definitions + history + new input + output.

    Context window sizes by model group (from the context windows doc)
    Model groupContext windowImages or PDF pages per request
    Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, Claude Sonnet 4.6 and the other 1M models listed1M tokens by default: no beta header, standard pricing; up to 128k output tokens (max_tokens)Up to 600
    Other Claude models, including Claude Sonnet 4.5200k tokensUp to 100

    The token limit is not the only ceiling. If a request carries many images or large documents, you can reach the request size limits before you reach the token limit.

    Checkpoint 1 of 7· Check yourself

    Part of your prompt is served from the prompt cache as a cached prefix. How does that cached prefix count toward the context window?

    Prompt caching deserves a short note here because it is easy to misread. Cached prefixes still occupy the context window: caching changes what you pay for those tokens, not whether they count.

    There are two ways to turn caching on. With automatic caching, you add a single cache_control field at the top level of the request. The system applies the cache breakpoint to the last cacheable block and moves it forward as the conversation grows, so everything up to and including that block is cached. With explicit cache breakpoints, you place cache_control directly on individual content blocks for fine-grained control over exactly what gets cached.

    Checkpoint 2 of 7· Exam question

    A team is building a customer support agent that sends a 6,000-token static system prompt containing product policies and tone guidelines, followed by a short per-request user message that always differs. Both latency and cost matter, and the team wants to maximize the prompt cache hit rate across thousands of daily requests. Where should they place the cache_control breakpoint?

    Sources12

    2.Thinking tokens across turns

    Extended thinking adds a budgeting detail of its own. Thinking tokens come out of your max_tokens, are billed as output tokens, and count toward rate limits. With adaptive thinking, Claude decides how much to think on each request, so thinking usage changes from one request to the next.

    What happens to old thinking blocks in later turns depends on the model. Newer models keep them in context by default. Older Opus and Sonnet models, and all Haiku models, have them stripped automatically. You can pass the blocks back unchanged and the API will drop them for you.

    How previous-turn thinking blocks are handled by default
    ModelsPrevious thinking blocksEffect on later requests
    Claude Opus 4.5 and later Opus, Claude Sonnet 4.6 and later Sonnet, Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Mythos PreviewKept by defaultCount toward the window and are billed as input tokens
    Earlier Opus and Sonnet models, all Haiku modelsStripped automatically by the APIFree up room for conversation content

    Billing follows the same split. Thinking is billed once as output when it is generated. On models that keep it, those blocks then appear in later requests as history and are billed as input. Thinking block clearing lets you override the default either way.

    Tool use adds one rule you cannot skip. When you send a tool result back, you must include the full, unmodified thinking block that came with the tool request, signature included. This is the only case where returning thinking is required. If the block has been edited, the API returns an error.

    Checkpoint 3 of 7· Check yourself

    In a multi-turn conversation on Claude Haiku 4.5 with thinking on, your client sends every earlier assistant turn back, thinking blocks included. What happens to those earlier thinking blocks?

    Checkpoint 4 of 7· Put it in order

    Put the turns of a thinking + tool use exchange in order

    1. 1.Claude outputs a thinking block, a text response and a tool use request
    2. 2.You send the tool_result back with the unmodified thinking block
    3. 3.A new user turn arrives and Claude generates a new thinking block
    4. 4.Claude responds with text only, with no new thinking

    Sources1

    3.Measuring tokens before and after a request

    After a request, check the response's usage field, which reports what the request consumed. If you use prompt caching, input is reported in three counters: input_tokens, cache_read_input_tokens and cache_creation_input_tokens. All three count toward the window, so add them together to get the real context size.

    Before a request, use the token counting endpoint. It takes the same inputs as message creation (system prompts, tools, images, PDFs) and returns the total input tokens. The docs list three uses: managing rate limits and costs, making model routing decisions, and fitting prompts to a target length.

    Checkpoint 5 of 7· Fill the gap

    Which method completes this pre-flight token estimate?

    client = anthropic.Anthropic()
    
    response = client.messages. ? (
        model="claude-opus-5-5",
        system="You are a scientist",
        messages=[{"role": "user", "content": "Hello, Claude"}],
    )
    
    print(response.json())

    Know where the endpoint stops. It returns invalid_request_error for server tools such as web search, for the MCP connector, and for image or document blocks given by URL or file source. Send images and PDFs as base64 if you want them counted. It is free to use but rate-limited by usage tier. It also gives an estimate without any caching logic, so cache_control in a count request has no effect.

    Counts depend on the tokenizer. Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5 and Claude Mythos 5 use the tokenizer introduced with Claude Opus 4.7. The same prompt counts about 30 percent higher on these models than on models before Opus 4.7, and the exact increase depends on the content.

    Some models also track their own budget. Claude Sonnet 5, Claude Sonnet 4.6, Claude Sonnet 4.5 and Claude Haiku 4.5 have context awareness: the API adds their total budget to the system prompt and sends an update after each tool call. Claude Opus 4.7 and later Opus models, Claude Sonnet 5.5, Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5 and Claude Mythos 5 don't get these tags. Watch the near-identical names: Sonnet 5 is context-aware, but Sonnet 5.5 is not. For the models without tags, task budgets (beta) let you set a budget explicitly.

    The update the API adds after each tool call on models with context awareness. You never send this yourself.xml
    <system_warning>Token usage: 35000/200000; 165000 remaining</system_warning>

    Checkpoint 6 of 7· Check yourself

    You run one agent on Claude Sonnet 5 and another on Claude Sonnet 5.5. Which statement about injected token-budget tags is correct?

    Checkpoint 7 of 7· Check yourself

    You plan to move a production prompt from an older model to Claude Fable 5.1 and need to know how its token count will change. What does the documentation recommend?

    Sources13

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.A 1M-token window means you should send as much context as fits.Why is that wrong?

      Context has diminishing returns. Irrelevant content lowers the model's focus, so choosing what goes in still matters on large-window models.

      Covered in What fills the context window

    2. 2.If you add cache_control to a token counting request, the count reflects cache hits.Why is that wrong?

      Token counting ignores caching logic. Caching only happens when a message is actually created.

      Covered in Measuring tokens before and after a request

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “the system prompt, every message in messages (including tool results, images, and documents), and your tool definitions.”
      ↩︎ What fills the context window
      “The output Claude generates for the turn, including its extended thinking, counts too.”
      ↩︎ What fills the context window
      “If you send many images or large documents, you might reach request size limits before the token limit.”
      ↩︎ What fills the context window
      “Cached prompt prefixes still occupy the context window: prompt caching changes what you pay for those tokens, not whether they count.”
      ↩︎ What fills the context window
      “Thinking tokens are a subset of your max_tokens parameter, are billed as output tokens, and count toward rate limits.”
      ↩︎ Thinking tokens across turns
      “the API automatically strips previous thinking blocks from the conversation history when you pass them back”
      ↩︎ Thinking tokens across turns
      “You must return the thinking block with the corresponding tool results. This is the only case where you have to return thinking blocks.”
      ↩︎ Thinking tokens across turns
      “the input count is split across input_tokens, cache_read_input_tokens, and cache_creation_input_tokens, and all three count toward the window.”
      ↩︎ Measuring tokens before and after a request
      “Context awareness is automatic: there is nothing for you to enable”
      ↩︎ Measuring tokens before and after a request
      “Claude Sonnet 5.5, Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, and Claude Mythos 5 don't receive these injected tags.”
      ↩︎ Measuring tokens before and after a request
      “As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
      ↩︎ Key concept
      “As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
      ↩︎ Prediction
      “You do not need to strip the thinking blocks yourself: if you pass them back, the Claude API strips them automatically.”
      ↩︎ Checkpoint
      “Because there is a new user turn outside the tool use cycle, Claude generates a new thinking block and continues from there.”
      ↩︎ Checkpoint
    2. 2.
      “The system automatically applies the cache breakpoint to the last cacheable block and moves it forward as conversations grow.”
      ↩︎ What fills the context window
      “Place cache_control directly on individual content blocks for fine-grained control over exactly what gets cached.”
      ↩︎ What fills the context window
    3. 3.
      “Token counting is free to use but subject to requests per minute rate limits based on your usage tier.”
      ↩︎ Measuring tokens before and after a request
      “roughly 30 percent higher than on models before Claude Opus 4.7 (the exact increase depends on the content)”
      ↩︎ Measuring tokens before and after a request
      “No, token counting provides an estimate without using caching logic.”
      ↩︎ Exam trap 2
      “count the same request twice, once with your current model and once with the model you plan to move to”
      ↩︎ Checkpoint

    Also cited

    Continue to page 2 of 2

    Managing Long Conversations: Compaction, Context Editing and Cache Trade-offs

    Spotted a mistake, or was something unclear? Tell us.