Skip to content

Read the token breakdown before you cut

Read a request's token breakdown alongside a quality symptom, identify what fills the context, and pick the change that removes it without losing what the task needs.

Scenario

A contract-review agent gets slower and less accurate as a session goes on. The engineering manager's request: "We need a bigger context window."

The architect pulls one late request apart first. Four fifths of it is about contracts the agent finished an hour ago: their search results and the turns around them. A bigger window would hold more of them, and the answers would get worse, not better.

Explanation

Everything counts. The context window holds the system prompt, every message (tool results, images and documents included), the tool definitions, and the output Claude generates, thinking included. Each response reports its use in usage.

Read all three input fields. With prompt caching, input is split across input_tokens, cache_read_input_tokens and cache_creation_input_tokens, and all three count toward the window. input_tokens covers only what comes after the last cache breakpoint, so a small input_tokens doesn't mean a small request. Caching changes what you pay for tokens, not whether they take up space.

More is not better. As token count grows, accuracy and recall degrade: the docs call it context rot. Anthropic's context-engineering guidance aims for the smallest set of high-signal tokens that gets the outcome.

Match the change to what fills the context:

What fills it The change
Definitions of tools the task rarely uses Tool search with deferred loading
A data table pasted in to compute over Upload it and let code execution query it
Results of tool calls from finished steps Context editing (tool result clearing), or compaction at a task boundary
History from earlier tasks in a long session Compaction at a task boundary
Documents unrelated to this question Retrieval: load only the relevant ones, just in time
Raw tool output where only a few rows matter Programmatic tool calling, so only the filtered result enters
Oversized images Resize them to what the task needs

Placement is not a cut. For long inputs, put the documents at the top and the question at the end. It changes quality, not tokens.

Two cautions. First, don't cut what the task needs: decisions, IDs and open questions must survive any summary. Second, the levers interact with the cache. In Anthropic's measurements on an earlier model, context editing raised the cost of a short run, while compaction and a hand-written prune saved money on a long one. On current models, rewriting old tool results yourself breaks preserved thinking, so the docs point to the server-side levers instead. Judge each change by its net effect on cost and quality.

Worked example

The contract-review agent, one request late in a session, before and after.

Part Before After
Tool definitions (5 tools) 4,000 4,000
System prompt and review checklist 6,000 6,000
Summary of finished contracts none 3,000
History of earlier contracts 38,000 none
Search results from earlier contracts 92,000 none
Current contract and its search results 24,000 24,000
Total 164,000 37,000

Symptom: findings from a finished contract appear in the current review. Diagnosis: 80% of the request is about contracts that are already done. Change: at each contract boundary, compact the session into a summary that keeps each contract's ID, decision and open issues. The agent still knows what it decided, without rereading what it read.