Claude Code token usage: why it burns tokens and how to cut the bill
If you've watched your Claude Code usage climb faster than expected, it's not a bug. It's how agentic coding tools work: every turn resends the conversation so far, plus your system prompt, tool definitions, and whatever files are in context. Understanding that mechanic is the first step to controlling the bill.
Why one turn isn't one request's worth of tokens
A chat app sends a short message and gets a short reply. Claude Code isn't that. Each turn in an agentic session typically includes:
- The full conversation history so far
- Tool/function definitions (file read, file write, bash, etc.)
- Any file contents you've pulled into context
- Your new instruction
None of that gets summarized automatically mid-session. The model needs the full context to reason about your codebase, so the client resends it. That's why a single turn in an agent session can look like 100,000+ cache-read tokens plus a few thousand fresh tokens, even for a small ask like "fix this test."
What cache reads actually save you
Prompt caching is what makes this affordable at all. Instead of paying full input price every time the same context gets resent, a cache hit is billed at a much lower cache-read rate. For claude-sonnet-5 on apillms, input is $0.274 per 1M tokens, but cache reads are $0.046 per 1M tokens.
Using the calculator for a realistic agent turn (100,000 cache-read tokens + 5,000 fresh input + 1,000 output), one turn on claude-sonnet-5 costs $0.026, and 1,000 turns cost $26.23. Without caching, that same turn would be pricing the full 100,000 tokens at the input rate instead of the cache rate — which is the whole reason caching matters for agentic workflows. See how prompt caching works for the mechanics.
The catch: caching only helps for tokens that repeat unchanged between turns. Every new file you open, every tool result, every line you add to the conversation is fresh input, billed at full rate. Long sessions accumulate fresh input steadily even with caching doing its job.
Where the token count actually goes up
A few common patterns inflate context fast:
- Reading large files into context. Pulling a 2,000-line file to fix one function means that whole file rides along on every subsequent turn until you clear it.
- Long back-and-forth debugging. Each exchange appends to history. Ten turns of "try this, no that didn't work" adds up.
- Tool output. Verbose bash output, stack traces, and search results all become part of the context that gets resent.
- Multiple files open at once. Context isn't just the conversation, it's everything the agent has touched.
None of this is wasteful in the sense of being wrong to do. It's the tradeoff for letting the model see enough to actually help. But it means session length and file scope are the two levers you control directly.
/clear and /compact: what they're for
Claude Code gives you two commands to manage context growth:
/clear
Wipes the conversation history and starts fresh. Use this when you're switching tasks entirely — moving from "fix this bug" to "write tests for a different module." There's no reason to carry the old debugging session into unrelated work.
/compact
Summarizes the existing conversation into a shorter form instead of dropping it entirely. Use this when you're still working on the same task but the history has gotten long. You keep the gist without paying to resend every intermediate step verbatim.
A practical habit: run /compact when you notice a task is taking many turns, and run /clear the moment you're done with one task and starting an unrelated one. Neither costs you anything to run, and both reduce what gets resent on the next turn.
Model choice matters more than most token-saving tricks
Context management helps, but which model you point Claude Code at has a bigger effect on the bill. Using the same calculator assumptions (100,000 cache-read + 5,000 fresh input + 1,000 output per turn), 1,000 turns cost:
| Model | Input | Cache read | 1,000 turns |
|---|---|---|---|
| claude-opus-5-5 | $0.639 | $0.106 | $41.07 |
| claude-sonnet-5 | $0.274 | $0.046 | $26.23 |
| gpt-5.5 | $0.532 | $0.03 | $13.45 |
| deepseek-v4-flash | $0.047 | $0.027 | $5.88 |
Opus is the strongest reasoning tier but the most expensive per turn. Sonnet is the usual default for day-to-day coding. If you're doing high-volume, lower-stakes work — boilerplate generation, simple refactors, repetitive edits — routing some of it to a cheaper model can matter more than any context trick. See which model fits which coding task for more on that tradeoff.
Setting up Claude Code to point at apillms
Claude Code talks to an Anthropic-compatible endpoint. apillms exposes one at https://apillms.com (no /v1), so switching the base URL is the only change needed:
export ANTHROPIC_BASE_URL=https://apillms.com
export ANTHROPIC_API_KEY=your_apillms_key
Full walkthrough, including where to grab a key, is in the Claude Code setup guide or the integration page. Failed requests aren't charged, and credits don't expire, so there's no downside to testing a session before committing to a workflow change.
Practical takeaway
Claude Code's token cost comes from resending context every turn, not from any single expensive call. Prompt caching absorbs most of the repeated cost, but fresh input from new files, long debugging threads, and verbose tool output still adds up. Use /clear between unrelated tasks, /compact during long ones, and pick your model tier based on the actual difficulty of the task rather than defaulting to the strongest one for everything. Check current per-model pricing on the pricing page or compare providers side by side on the comparison page before deciding where to route your traffic.
Try apillms
One API key for Claude, GPT, Grok, DeepSeek and Kimi. OpenAI- and Anthropic-compatible, prompt caching included, pay-as-you-go from $5 with PayPal or card. Credits never expire.
FAQ
Why does Claude Code use so many more tokens than a regular chat message?
Agentic sessions resend the full conversation history, tool definitions, and any file contents in context on every turn, whereas a chat message is just the new question and answer.
Does prompt caching eliminate the extra cost?
No. It lowers the price of tokens that repeat unchanged between turns, but new files, new conversation turns, and tool output are still billed as fresh input.
When should I use /clear versus /compact?
Use /clear when you're switching to an unrelated task and don't need the old history. Use /compact when you're still on the same task but the conversation has gotten long and you want a shorter summary instead of the full history.
Does switching models require changing my Claude Code setup?
No, you can point Claude Code at any model available through the same Anthropic-compatible endpoint by changing the model name in your config; the base URL and key stay the same.