Simeon Akinrinola logo
← Back to blog

2026-10-03 · Artificial Intelligence

Understanding Why Claude Spends So Much of Your Tokens, from Scratch.

All prices are Opus 5.5 API list prices, and the numbers are illustrations. If you're on a subscription, read the dollars as how fast a task uses up your limit.

When Claude Code or another coding agent uses hundreds of thousands of tokens on what looks like a simple task, it can be confusing.

"Why did it use so many tokens?"

The answer starts with understanding what is actually happening between you, the agent, and the model.

There are 3 identities in every conversation with Claude

You type the prompt.

  1. The agent (like Claude Code) is the program that acts on behalf of the LLM. It opens files, edits them, runs commands, and keeps the full record of the conversation.

  2. The LLM is the model. It ONLY reads input and writes output. It can't act.

  3. When the LLM needs to read a file, it writes a request and the agent takes the content of the file to it.

Turns and what they mean

One turn is simply:

  • You send your prompt.

The LLM thinks and decides it needs to do something, or it responds immediately.

If it needed to do something, for example read a file, it writes out a request and the agent runs it. FULL STOP.

That is, an input and the LLM's output (whether it's a request or a direct answer), and it ends the turn.

The LLM does not receive the result of the request it made in that same turn.

In the next turn, the LLM gets the conversation again, alongside the output from the tool the agent called for it.

Anthropic's tool-use flow works this way: Claude produces a tool request, the application runs the tool, and the tool result is sent back to Claude in a subsequent request.

This is important because every time that happens, there is another model request.

A Complete Example: "Fix a bug", turn by turn

Let's say you tell Claude Code:

"Fix this bug."

It doesn't magically know which file to change. It has to investigate.

So it might look like this:

Turn 1:

INPUT | LLM receives your input (plus the agent's own instructions and tool list).

OUTPUT | Thinks and decides it needs to see the folder structure and read the specific file. Makes tool requests (read folder structure, read file).

END.

Turn 2:

INPUT | Agent runs the tools (read folder structure, read file). Gets tool output. Adds it to the conversation. Sends everything back to the LLM again.

OUTPUT | LLM thinks. Decides it has enough context. Decides it needs to edit the file. Writes a tool request (edit file).

END.

Turn 3:

INPUT | Agent runs the tool (edit file). Gets tool output (success). Adds it to the conversation. Sends everything back to the LLM again.

OUTPUT | LLM thinks. Decides it needs to know if the fix worked. Writes a tool request (run tests).

END.

Turn 4:

INPUT | Agent runs the tool (run tests). Gets tool output (2 tests failed). Adds it to the conversation. Sends everything back to the LLM again.

OUTPUT | LLM thinks. Decides the fix isn't complete and it needs to edit again. Writes a tool request (edit file).

END.

Turn 5:

INPUT | Agent runs the tool (edit file). Gets tool output (success). Adds it to the conversation. Sends everything back to the LLM again.

OUTPUT | LLM thinks. Decides it needs to run the tests again. Writes a tool request (run tests).

END.

Turn 6:

INPUT | Agent runs the tool (run tests). Gets tool output (passed). Adds it to the conversation. Sends everything back to the LLM again.

OUTPUT | LLM thinks. Decides the bug is fixed. Writes a final answer to you.

That is 6 turns for what you experienced as: "Fix a bug."

And this is where the token usage starts becoming interesting.

Three kinds of tokens, three prices

New input: Text the LLM reads and that is processed at the normal input price. $4 per million.

Repeated/cached input: text from the prompt prefix that has already been cached and is reused on a later request. $0.20 per million.

Output: everything the LLM writes, including thinking and tool requests. $20 per million.

There is also a cache-write cost.

For Opus 5.5:

5-minute cache write: $5 per million

1-hour cache write: $8 per million

I will explain the cache-write cost later in this post, do not think too much about it for now.

The cache-read price is much cheaper than normal input.

That's the whole point of prompt caching.

3 types of tokens

In our "Fix a bug" example, let's assume we spent:

1st turn:

INPUT | your prompt + the agent's instructions and tool list = 20k tokens (all new) ~ $0.080

OUTPUT | thinking + tool requests = 1k tokens ~ $0.020

TOTAL = 21k ~ $0.100

2nd turn:

INPUT | everything from turn 1 (20k, repeated) + turn 1's output and tool results (10k, new) = 30k ~ $0.044

OUTPUT | thinking + tool request = 2k tokens ~ $0.040

TOTAL = 32k ~ $0.084

3rd turn:

INPUT | everything from turn 2 (30k, repeated) + turn 2's output and tool result (3k, new) = 33k ~ $0.018

OUTPUT | thinking + tool request = 1k tokens ~ $0.020

TOTAL = 34k ~ $0.038

4th turn:

INPUT | everything from turn 3 (33k, repeated) + turn 3's output and tool results (4k, new) = 37k ~ $0.023

OUTPUT | thinking + tool request = 2k tokens ~ $0.040

TOTAL = 39k ~ $0.063

5th turn:

INPUT | everything from turn 4 (37k, repeated) + turn 4's tool result (3k, new) = 40k ~ $0.019

OUTPUT | thinking + tool request = 1k tokens ~ $0.020

TOTAL = 41k ~ $0.039

6th turn:

INPUT | everything from turn 5 (40k, repeated) + turn 5's tool result (2k, new) = 42k ~ $0.016

OUTPUT | thinking + final answer = 1k ~ $0.020

TOTAL = 43k ~ $0.036

So:

Input read = 202k tokens

New input = 42k

Repeated/cached input = 160k

Output = 8k

Total tokens processed by LLM = 210k

And the approximate cost is:

42k new input × $4/M = $0.168

160k cached input × $0.20/M = $0.032

8k output × $20/M = $0.160

TOTAL = $0.360

That is a big total of 210k tokens ~ $0.36 for the task.

Of the 202k tokens the LLM read, only 42k were new (~$0.17).

The other 160k were repeated (~$0.03).

The 8k it wrote cost ~$0.16.

To keep it simple, these numbers leave out the cache-write cost.

And because the individual turn costs above are rounded, they won't add perfectly to the exact total. The exact calculation gives approximately $0.36.

Output is the smallest line in tokens, yet it costs almost as much as all the new input put together

In our example:

42k new input = ~$0.17

160k cached input = ~$0.03

8k output = ~$0.16

The model wrote only 8k tokens, but those 8k tokens cost almost as much as the 42k new input tokens.

Without the repeated-text discount, the same task costs about $0.97:

202k input × $4/M = ~$0.808

8k output × $20/M = ~$0.160

TOTAL = ~$0.968

That's why caching matters so much.

Thinking is output too

Before every tool call or answer, the model may spend tokens thinking, and those thinking tokens are billed as output tokens, even when your screen shows only a short summary.

On Claude Opus 5.5, adaptive thinking is always on. You can control the thinking depth with the effort setting. Anthropic bills thinking tokens as output tokens.

There is another detail that matters.

On models where previous thinking is preserved in the conversation, that previous thinking can be sent back as input on later turns.

When that happens, those tokens are input tokens.

And if they are inside the cached prefix, they can be read from cache.

That depends on the model and configuration, so I'll cover that in another post.

How the discount works, and what breaks it

Anthropic's system can cache already-processed parts of the prompt so they don't have to be processed again at the full input price.

The important word is cache.

For the API, prompt caching has to be enabled.

Anthropic's current API supports automatic caching as well as explicit cache breakpoints. The cached prefix can include tools, system instructions, and messages, in that order, up to the cache breakpoint.

On the next turn, if the beginning of the request still matches the cached prefix, Claude can reuse that cached content instead of processing it again at the normal input price.

Three things to know:

It matches from the start.

The cache is based on a prefix.

The first difference in that prefix is where the cached portion stops.

Everything after that is not getting the same cache-read treatment.

This is why keeping stable instructions and tool definitions at the beginning of the request matters.

It expires.

The default cache lifetime is 5 minutes.

Anthropic also offers a 1-hour cache duration at a higher cache-write price.

Using the cache refreshes its lifetime, but the lifetime is measured from the start of the request, not the end of the response. So if the model takes a long time to generate its response, some of that cache lifetime is already being used.

Rebuilding costs extra.

For Opus 5.5, a 5-minute cache write costs $5 per million tokens instead of the normal $4 per million.

That's about 25% more.

The 1-hour cache write costs $8 per million.

But reading from cache costs only $0.20 per million.

So a cache hit is dramatically cheaper than processing the same text normally.

So what breaks it?

Pausing long enough for the cache to expire can cause a cache miss.

Changing something earlier in the cached prefix can cause the cached portion after that point to stop matching.

Changing the agent's tools can affect the cached prefix.

Changing other request settings can also affect what can be reused.

The exact behavior depends on the request structure, but the basic idea is simple:

If the beginning of the cached prefix changes, the cached content after that change can't simply be reused as before.

Anthropic specifically documents tool definitions and other request configuration as things that can affect cache reuse.

Let's go back to our 40k example.

At turn 6 of our task, if the 40k repeated tokens are read from cache:

40k × $0.20/M = $0.008

That's less than one cent.

If the cache is gone and those same 40k tokens have to be processed as normal input:

40k × $4/M = $0.16

That's 20 times more for the same 40k tokens.

And if those 40k tokens are being written into a new 5-minute cache:

40k × $5/M = $0.20

That's not the same thing as normal input pricing. The cache write has its own price.

So the three numbers are:

Cache read → $0.008

Normal input → $0.16

5-minute cache write → $0.20

A steady session, where the cached prefix stays the same and new content is added at the end, can keep getting cache hits.

What decides your bill?

Turns.

Each turn can send the conversation history back to the model.

How much of that reading is repeated.

Repeated cached text costs 5% as much as normal input on Opus 5.5.

How much new context is being added.

New input is charged at the normal input price.

How much the LLM writes.

Output, including thinking, is the priciest token.

How much of the prompt can actually be cached.

Only the matching cached prefix gets the cache-read price.

How long you leave between turns.

A long enough pause can cause the cache to expire.

Which model.

It sets the price of every token.

The important part

The number you see as "tokens used" doesn't tell you the whole story.

A 200k-token agentic task does not necessarily mean you paid the normal input price for 200k tokens.

In our example, the LLM read 202k tokens, but only 42k were new.

The other 160k were repeated and, under our caching assumptions, read from cache at a much lower price.

At the same time, the 8k tokens the model wrote cost almost as much as all 42k new input tokens.

So when you're trying to understand why Claude Code or another agentic system is using so many tokens, don't just look at the number.

Look at:

How many turns happened.

How much context was repeated.

How much of that context was actually cached.

How much the model thought and wrote.

And what model you're using.

That's what is actually happening underneath the "Fix a bug" experience.

How to reduce the costs will be explained in the next post.

Yours Truly,

Simeon.

Understanding Why Claude Spends So Much of Your Tokens, from Scratch. | Simeon Akinrinola