Guide

Claude Code Token Cost: Why It Climbs and How to Cut It

2026-06-23 7

TL;DR: The single biggest driver of Claude Code token cost is that the whole conversation is re-sent on every turn. A long session pays for all prior context with each new message, so cost grows super-linearly with session length — not with the size of your last prompt. The fix is mechanical: keep context small (/compact or fresh sessions), pick the cheapest model that can do the job, and split huge outputs into parts.

If your bill surprised you, you almost certainly weren't billed for the question you just asked. You were billed for everything Claude Code has been carrying since you opened the session.

Why claude code token cost grows faster than you expect

Claude Code is stateless under the hood. Every time you hit enter, the client re-sends the entire conversation so far — your prompts, the model's replies, every file it read, every tool result — as the input for that turn. The model has no memory between calls; the transcript is the memory.

That has a brutal consequence for cost. Input tokens are billed per turn, so a token you sent on turn 1 gets re-billed on turn 2, turn 3, and every turn after. A session that has read a few large files and gone twenty messages deep is paying for that whole pile on every subsequent message, even if your new prompt is one line.

The shape to internalize:

What you think you pay for What you actually pay for
The message you just typed The entire transcript, re-sent each turn
Cost ∝ prompt length Cost ∝ (accumulated context × number of turns)
A short question is cheap A short question in a deep session is expensive

This is why people describe Claude Code as feeling cheap early and getting expensive later in the same task. Nothing changed about your prompts. The context they ride on got heavier.

The biggest lever: keep the context small

If cost scales with accumulated context, the highest-leverage move is to stop accumulating.

Use /compact when a session gets deep. Claude Code's /compact command summarizes the conversation so far into a much shorter form and continues from there. You keep the thread of what you were doing, but you drop the long tail of raw file dumps and intermediate tool output that you no longer need re-sent every turn. Run it once a task's exploration phase is done and you're into focused edits.

Start a fresh session at natural boundaries. When you finish one task and move to an unrelated one, don't keep typing into the same window. A new session starts the transcript empty. Carrying a finished task's context into the next one means re-billing it for no benefit — and it raises a second risk: very long contexts make the model more likely to lose the plot. We've written about that failure mode in the 400K hallucination handoff — long context is a cost problem and a quality problem.

Be deliberate about what you let into context. Pointing Claude Code at a huge directory or pasting a giant log means all of it gets re-sent on every following turn, not just the turn you pasted it. Narrow the scope: reference the specific files that matter.

The second lever: match the model to the work

The cost of a large context window compounds with model choice, because the same re-sent context is priced differently per model.

  • Default to a cheaper model and escalate deliberately. Start work on the cheapest model that's plausibly capable, and only move up to a stronger one when you actually hit something it can't handle. Reaching for the most powerful model by reflex means paying its rate on every re-sent turn.
  • Use Haiku for throwaway work. Quick edits, format fixes, one-off questions, scratch exploration — claude-haiku-4-5-20251001 is the right tool, and you're not re-billing premium context for disposable output.
  • Reserve the big models for where they earn it. claude-opus-4-8 and claude-sonnet-4-6 are worth their cost on hard reasoning and large-codebase work — just don't leave them mounted for trivia.

For a full breakdown of which plan and model fits which usage pattern, see our Claude Code pricing guide.

Switching models against an llmapi.pro key is just the model ID in your request. Claude Code points at the relay through the standard env vars:

export ANTHROPIC_BASE_URL=https://llmapi.pro
export ANTHROPIC_API_KEY=sk-relay-...
# then pick your model inside Claude Code, or via the request's model field

The advertised models and their windows come straight from GET /v1/models:

Model ID Context in Output cap
claude-opus-4-8 1M 128K
claude-opus-4-7 1M 128K
claude-sonnet-4-6 1M 128K
claude-haiku-4-5-20251001 200K 64K

1M context is available — but it isn't free

The 1M-token context window on the Opus and Sonnet models is genuinely useful for large-codebase work. The catch is exactly the mechanic above: a loaded 1M context is re-billed on every turn it stays loaded. The window is a ceiling on what you can send, not a budget that's free to fill.

The practical rule: load the big context when you need it, do the work that needs it, then /compact or start fresh before the long conversation that follows re-bills all of it dozens of times over.

Output is capped — ask for big results in parts

There's a second, smaller cost-and-correctness trap on the output side. Each response is capped — 128K tokens on the Opus and Sonnet models, 64K on Haiku. If you ask for an enormous single output, you can hit the cap and get a truncated answer that you then have to re-prompt to continue — which re-sends the whole context again to produce the rest.

Ask for large deliverables in parts. "Generate the first module, then I'll ask for the next" keeps each response inside the cap and gives you a checkpoint, rather than burning a full re-billed turn on a continuation.

A workflow that keeps the bill flat

Put together, the levers form a routine that experienced users settle into:

  1. Start cheap. New session, cheapest capable model. Most work never needs more.
  2. Scope tightly. Let only the files that matter into context.
  3. Compact at the seam. Once exploration is done and you're editing, run /compact so the focused phase doesn't re-pay for the noisy phase.
  4. Escalate on demand. Move to a stronger model only when you hit a wall, then move back.
  5. Reset between tasks. Finished one thing? New session. Don't drag dead context forward.
  6. Chunk big outputs. Stay under the per-response cap; checkpoint as you go.

None of this costs you capability. It costs you the habit of leaving everything loaded — which is the thing you were actually paying for.

If you want a relay that exposes these models on both the Anthropic and OpenAI protocols with transparent per-model pricing, you can get a key at /register and check current rates on the pricing page.

llmapi.pro is an independent, Claude-compatible API relay; we are not affiliated with Anthropic. Claude Code and Claude are used for identification only.

分享这篇文章

开始使用 LLM API

免费套餐可用。Claude Code 一行配置。

免费开始