How to Cut Claude Token Costs: Prompt Caching, Subagents, and Context Engineering
Claude bills per token, and agentic work multiplies tokens. Every turn re-sends the whole conversation, so a ten-step task reprocesses the same context ten times, and the bill grows with the square of how long a session runs. Whether you pay through the API or burn through a Claude subscription's usage limits, the mechanics are the same, and so are the fixes.
The price spread across models is what makes those fixes worth learning. Per Anthropic's pricing, Haiku 4.5 runs $1 per million input tokens and $5 per million output, Sonnet 5 $3 / $15, Opus 4.8 $5 / $25, and Fable 5, the most capable model, $10 / $50. That is a 10x range for input and output alike. Every technique below works on any of these models; the more expensive the model, the more it saves.
We originally wrote this guide when Fable 5 briefly left the Claude subscription and every Fable token was about to land on an API bill. Fable is part of the subscription again, but nothing about the token math changed: a session that wastes context wastes it at whichever rate your model charges.
Where the money goes
Output tokens carry the higher unit price ($50 per million on Fable 5, $25 on Opus 4.8) against $10 and $5 for input. But an agentic loop feeds in far more than it generates: the whole conversation is re-sent on every turn. In our token benchmark, each documentation query ran 80,000 to 140,000 tokens, only one to three thousand of them output. Both dimensions cost money, so the levers below split in two.
To cut input tokens:
- Start a fresh session for unrelated work, so old context stops being re-sent.
- Keep prompt caching intact, so the re-sent prefix bills at a tenth of the price.
- Trim the transcript so stale content stops riding along.
- Hand the agent ready-made context instead of making it explore: skills for your own knowledge, Context7 for library docs.
To cut both input and output:
- Match effort to the task; it governs thinking, output, and tool-call spend.
- Tier your models, so only the work that needs the top tier runs on the top tier.
Model tiering with subagents: one model to think, cheap models to do
Most agentic work is a little hard reasoning wrapped in a lot of mechanical execution. Planning an approach or reviewing a diff for real bugs is where an expensive model earns its price; renaming symbols across forty files or running the test suite is not. Keep the strong model as the orchestrator and hand the bulk work to Sonnet 5 or Haiku 4.5 subagents. Each runs in its own context window, so the cheap model never touches the orchestrator's expensive context, and the orchestrator only sees the result. Delegate ten file edits and those loops run at Haiku's $1 / $5 instead of Opus's $5 / $25 or Fable's $10 / $50.
In Claude Code, two features do this for you.
- Subagents run on a model you choose: a small Markdown file under
.claude/agents/whosemodel:field takes a cheap alias likehaikuorsonnet. Ask Claude to create one and it delegates automatically. The built-in Explore agent is the read-only version, inheriting your main model capped at Opus; define your ownExplorewithmodel: haikuto go cheaper. - Workflows set the model and effort per stage: run a review's adversarial find stage on a cheap model and reserve the expensive one for the synthesis that needs judgment.
The intelligence lives in the orchestration. Put your strongest model there, and push everything else to the cheapest model that can do the job.
Match effort to the task
The effort parameter controls how much a model thinks and how many tool calls it makes, and Anthropic treats it as the main lever for cost control on adaptive-thinking models (Opus 4.6 and later, Sonnet 5, Fable 5). At max and xhigh, a model can deliberate well past what a routine task needs.
So do not default to the ceiling. Anthropic notes that lower effort on its newest models still performs well and often beats the xhigh output of prior models: reserve xhigh for genuinely hard work, keep high for intelligence-sensitive tasks, and drop to low or medium for routine steps. Dropping a level on a task that already works costs you nothing. Set it with /effort in Claude Code, or output_config on the API.
Keep prompt caching intact
Prompt caching turns repeated context into reads that cost about a tenth of the base input price. Since the whole prefix is re-sent every turn, this is the single biggest discount an agent session gets, on any model.
Claude Code sets it up for you, so the job is mostly not breaking it. The cache keys off a stable prefix (tools, then system prompt, then conversation); change something early and everything after is re-read at full price. The easy way to trigger that is changing the tool set mid-task:
- Adding or removing an MCP server changes the tools and invalidates the whole cache. Set servers up before you start, not partway through.
- Toggling web search does the same, since it alters the prefix.
- Switching models resets the cache too; caches are per model.
For the tier-by-tier detail, including SDK and direct-API use, see Anthropic's what invalidates the cache reference.
Context engineering: trim what keeps getting re-read
Cheaper than re-reading a token is not adding it at all. When you switch to unrelated work, start a fresh session instead of continuing; in Claude Code that is /clear, which drops the old task's context entirely.
Within one long task, two features keep it lean:
- Compaction summarizes old history near the context limit. Claude Code runs it automatically and on
/compact. - Context editing clears stale tool results and thinking blocks. It is an API/SDK control.
Write skills instead of making the agent explore
A well-written skill is a dense, ready-made guide: your project's architecture, its conventions, or a multi-step procedure, written once. The agent reads it on demand instead of grepping through source files or searching the web to reconstruct the same thing, and the full text only enters context when the task calls for it. That trades a long, exploratory trail of tool calls for a single focused read.
Write your own, or pull one from a directory like skills.sh, which installs into your agent in a single command:
npx skills add upstash/skillsCut input tokens at the source with Context7
Skills cover your own knowledge; library documentation is the other big source of bloat. Reach for it with general web search and the agent pulls back whole pages (navigation, marketing copy, unrelated sections) and dumps them into context, where the model re-reads them every turn at full input price.
Context7 injects version-aware docs as focused slices instead. We benchmarked it against Claude Code's web search across five query categories (repo): it cut fresh input tokens by about 99%, which fed through to a 34.56% cost reduction and 36.81% fewer total tokens.

Those numbers used Opus 4.7. On a more expensive model the saving is larger, since the trimmed context is re-read every turn at a higher rate.
Context7 runs as an MCP server. Add it to Claude Code or any MCP-capable agent and let the model pull docs through it instead of the open web.
Putting it together
A Claude agent that stays affordable usually looks like this:
- One strong model orchestrates; cheaper subagents (Sonnet 5, Haiku 4.5) do the bulk work in their own context windows.
- Effort is tuned per task, not pinned to
max. - Tools and system prompt stay frozen so prompt caching holds, and compaction plus context editing keep long runs lean.
- Skills and Context7 hand the agent ready-made context, so it reads instead of exploring.
None of this limits what the model can do. It aims your spend at the reasoning that actually needs the top tier, and runs everything else cheaper or keeps it out of context.
