Reduce Claude Code Token Usage: 10 Tips With Costs
Reduce Claude Code token usage with 10 tips: /clear, /compact, warm prompt cache, model choice, lean CLAUDE.md, subagents. Each tip shows tokens and dollars.
GoiAPI · · 17 min read
Ask AI and more

To reduce Claude Code token usage, start with three habits: run /clear when you switch to unrelated work, keep the prompt cache warm (don't switch models mid-session and don't leave a long session idle for more than five minutes), and use a small model for small jobs. In our calculation at GoiAPI's December 5, 2026 prices, the same 30-request Opus 5.5 session costs about $0.80 with wasteful habits and about $0.20 with lean ones, and the lean version on Haiku 5.5 costs about $0.012. Below, each tip comes with its token and dollar effect, so you can fix the expensive habits first.
Prices, commands and Claude Code docs were checked on December 5, 2026, when the latest Claude Code release on npm was 2.1.337. Measured numbers come from our own runs on December 3, 2026 with Claude Code 2.1.325. Everything else is arithmetic on listed prices, and the assumptions are stated each time.
Why Claude Code burns through tokens
The model remembers nothing between calls. Every time you send a message, and every time Claude uses a tool (reads a file, runs a command), Claude Code sends the whole context again: system prompt, tool definitions, CLAUDE.md, every earlier message and tool result, and then the new part (Claude Code prompt caching docs, checked December 5, 2026). That has three effects:
- Even the smallest turn is heavy. We ran
claude -pwith a one-line "what is 2+2?" question in an empty folder, on Claude Haiku 5.5 through api.goiapi.com, on December 3, 2026. Claude Code reported 10,679 input tokens, 15,574 cache-write tokens and 3 output tokens: about $0.00092 by our calculation. The same tokens on Opus 5.5 would be about $0.018. - Context only grows. Every file read and every log printed stays in the conversation and is sent again with each later request, until you run
/clearor/compact. - One prompt is many requests. If Claude calls five tools to answer you, that is five requests, each carrying the full history.
What keeps the bill sane is prompt caching: the unchanged start of each request is read back from cache at a much lower rate. GoiAPI's Claude prices on December 5, 2026, per 1 million tokens (pricing):
| Model | Input | Cache write | Cache read | Output |
|---|---|---|---|---|
| Claude Opus 5.5 | $0.442 | $0.8775 | $0.0221 | $2.21 |
| Claude Haiku 5.5 | $0.0221 | $0.043875 | $0.00221 | $0.1105 |
Two ratios explain most of this guide: on Opus, a cache write costs about 40 times a cache read, and output costs 5 times input. If the token types are new to you, see what AI API tokens are and what 1M tokens costs. For Anthropic's own per-token rates and the long-context tiers, see our Claude API pricing guide.
Measure before you cut: /usage, /context and request history
Don't guess. Three places show real numbers:
| Tool | What it shows | Watch out for |
|---|---|---|
/context | What fills the context (system prompt, CLAUDE.md, MCP tools, skills, conversation) and how many tokens each takes | Run it once in a fresh session to see your baseline before you type anything |
/usage (alias /cost) | Session tokens by model, plus, since v2.1.251, a Prompt cache (main) line with the share of input served from cache and the number of misses | The "Estimated cost" is computed locally at Anthropic list prices. It is not what GoiAPI charges |
| GoiAPI dashboard, Request history | Every request: model, input, output and cache tokens, actual cost | This is where you see what was really deducted |
According to Claude Code's cost docs (checked December 5, 2026), the Prompt cache (main) line is built from the cache fields in API responses, so it works through any gateway. A high read share is good. If cache writes stay high turn after turn, something keeps breaking your cache (see tip 3).
What one session costs: a worked example
To see which habits matter, we built an assumed session (not a measurement): 30 Opus 5.5 requests doing the same work in two styles.
- Lean: 30,000 uncached input tokens, 120,000 cache-write tokens (new content each turn), 1.5 million cache-read tokens (about 50,000 per request) and 24,000 output tokens in total.
- Wasteful: the same work, plus 100,000 tokens of leftover context from an earlier task carried through all 30 requests; 3 cache misses (an idle break, a model switch) that each rewrite 150,000 tokens; a 40,000-token log file read straight into the conversation after request 10 (it stays for the remaining 20 requests); and high effort that raises output to 60,000 tokens.
| Style | Cache write | Cache read | Output | Opus 5.5 | Haiku 5.5 |
|---|---|---|---|---|---|
| Lean | 120,000 | 1,500,000 | 24,000 | ≈ $0.205 | ≈ $0.012 |
| Wasteful | 610,000 | 5,300,000 | 60,000 | ≈ $0.798 | ≈ $0.046 |
Cost = tokens × price ÷ 1,000,000, at the prices above, before the small per-request minimum charge. The wasteful style costs almost 4 times as much for the same work. The biggest gap is not cache reads: it is the 490,000 extra cache-write tokens (about $0.43), followed by 3.8 million extra cache-read tokens (about $0.084) and the extra output (about $0.080), roughly level.
Small numbers per session add up across a working month. For daily and monthly estimates at light, moderate and heavy use, and how they compare with Pro, Max and Ultra, see Claude Code Max vs API: which costs less. To plug in your own token counts, use the cost calculator.
10 ways to reduce Claude Code token usage
1. Run /clear between unrelated tasks
/clear starts a new conversation with empty context (aliases /reset and /new), so the old context stops riding along on every request. Claude Code's cost docs note that when you want a fresh start rather than continuity, /clear costs nothing.
The money: carrying 100,000 tokens of stale context through 30 Opus requests is 3 million cache-read tokens, about $0.066 (Haiku: $0.0066). That is the cheap case, with every request hitting the cache. If you step away for more than five minutes mid-task, those 100,000 tokens get written to the cache again: about $0.088 for one miss on Opus.
To come back to the old task later, run /rename before /clear, then /resume it when needed. Resuming a session that has gone cold usually rewrites the whole conversation to the cache.
2. Compact at the right moment, and rewind instead of compacting after a wrong turn
/compact replaces the conversation history with a summary. You can tell it what to keep: /compact Keep the code changes and test results. Or add a section to CLAUDE.md:
# Compact instructions
When you are using compact, please focus on test output and code changesBut /compact costs tokens too. It sends a request that reads the whole history to summarize it, and the next request writes a new, shorter context to the cache. Our calculation for Opus 5.5, assuming a 150,000-token conversation, a 5,000-token summary and 30,000 tokens of context afterwards:
| Step | Cache still warm | Cache gone cold (idle over 5 minutes) |
|---|---|---|
| Summary request (read 150,000, write 5,000 output) | ≈ $0.0144 | ≈ $0.077 (the 150,000 tokens bill as plain input) |
| Re-cache the 30,000-token context after compaction | ≈ $0.026 | ≈ $0.026 |
| Saving on every later request (120,000 fewer tokens read) | ≈ $0.0027 | ≈ $0.0027 |
With a warm cache, /compact takes about 15 more requests to pay for itself. It wins clearly in two cases: right before a break (after the break, the old 150,000 tokens would cost about $0.13 to re-cache, against about $0.026 for the compacted context) and in long sessions. If the next task is unrelated, /clear is cheaper than /compact.
If Claude just went down the wrong path, don't compact: use /rewind (or press Esc twice) to go back to an earlier turn. Per the prompt caching docs, rewinding truncates to a prefix that is already cached, so the next request reads the cache instead of writing a new one.
On models with a native 1M-token context, recent Claude Code versions auto-compact near 400,000 tokens by default. To compact earlier, run /autocompact 200k (it applies to the current model; set autoCompactWindow in settings for every model) (model configuration docs, checked December 5, 2026). If you are already hitting the context limit, see Claude Code "prompt is too long": how to fix it.
3. Keep the prompt cache warm
The cache only hits when the start of a request is identical to the last one. Per the prompt caching docs (checked December 5, 2026), these actions make the next request miss part or all of the cache:
- Switching models with
/modelmid-session (each model has its own cache). - Changing effort mid-session on most models. On Opus 5.5 and Haiku 5.5 with an API key the docs say the cache is kept, provided a gateway forwards the paired beta header; we have not verified this through GoiAPI.
- Turning fast mode on or off.
- Connecting or removing an MCP server when its tools load upfront, or toggling a plugin that ships MCP servers.
/compact(on purpose, see tip 2) and upgrading Claude Code.- Going idle longer than the cache lifetime. With an API key, the default for the main conversation is five minutes.
What one miss costs on Opus 5.5 at GoiAPI prices (calculation):
| Context size | Read from cache | Rewrite to cache | Difference |
|---|---|---|---|
| 50,000 tokens | ≈ $0.0011 | ≈ $0.044 | about 40x |
| 150,000 tokens | ≈ $0.0033 | ≈ $0.132 | about 40x |
| 400,000 tokens | ≈ $0.0088 | ≈ $0.351 | about 40x |
What to do: pick your model and effort at the start of a session and leave them; work in focused bursts; /compact or /clear before a long break. Claude Code also offers a one-hour cache (CLAUDE_CODE_PROMPT_CACHE_TTL=1h), but its docs say that through a gateway set with ANTHROPIC_BASE_URL, the gateway must forward the anthropic-beta header unchanged. We have not tested the one-hour cache through GoiAPI, so we don't recommend relying on it yet.
Caching does work through GoiAPI. On December 3, 2026 we sent the same long, cache-marked system prompt to Haiku 5.5 twice, two seconds apart. The first request wrote 12,669 tokens to the cache and the second read all 12,669 back. For that block alone, that is about $0.00056 to write and $0.000028 to read (token counts measured, costs calculated). The Claude Code turn at the top of this guide also wrote 15,574 tokens to the cache on its very first request.
4. Match the model to the task
This is the biggest lever. For the same lean session above, Opus 5.5 costs about $0.205 and Haiku 5.5 about $0.012, roughly 17 times less. GoiAPI's Claude lineup is Opus 5.5 and Haiku 5.5. Claude Sonnet is not available.
- Haiku 5.5: small fixes where you know the location, renames, tests that follow an existing pattern, reading logs, explaining code.
- Opus 5.5: planning, bugs with an unknown cause, multi-file changes, architecture decisions.
A model switch breaks the cache (tip 3). At 150,000 tokens of context, switching to Haiku costs only about $0.0066 in cache writes, but switching back to Opus costs about $0.13. Instead of flipping back and forth, start a separate session for small jobs, or hand them to a Haiku subagent (tip 8).
To run Claude Code through GoiAPI, follow the Claude Code integration guide and add two lines so the opus and haiku aliases resolve to models GoiAPI serves:
export ANTHROPIC_BASE_URL="https://api.goiapi.com"
export ANTHROPIC_AUTH_TOKEN="sk-..."
export ANTHROPIC_MODEL="claude-haiku-5-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-5-5"
claudeThe ANTHROPIC_DEFAULT_*_MODEL variables are documented in the model configuration docs. We ran the first three lines with Haiku 5.5 on December 3, 2026; the full five-line setup has not been tested end to end. The Claude Code API key guide covers Windows and VS Code. To use GPT, DeepSeek or GLM models inside Claude Code, see Claude Code Router.
5. Lower the effort level for simple work
Thinking tokens are billed as output, and Opus 5.5 output is $2.21 per million tokens, or about $0.0022 per 1,000 tokens. Per Claude Code's docs, Opus 5.5 and Haiku 5.5 default to medium effort, and thinking can't be switched off on the 5.5 models; lower it with /effort low or the CLAUDE_CODE_EFFORT_LEVEL=low environment variable.
The money: in the example session, high effort added 36,000 output tokens, about $0.080 on Opus (Haiku: about $0.004). Set effort at the start of the session; changing it mid-session can break the cache depending on the model and how you connect.
6. Keep CLAUDE.md lean
CLAUDE.md loads at the start of every session. Claude Code's docs recommend keeping each CLAUDE.md under 200 lines and moving instructions that only matter for part of the codebase into path-scoped rules (paths:) or skills, which load only when used (memory docs, checked December 5, 2026). Note that @path imports help organize a long file but don't reduce its token cost: imported files still load in full.
An honest number: on pay-per-token billing with a warm cache, 3,500 extra tokens in CLAUDE.md cost about $0.00008 per Opus request (about $0.077 per 1,000 requests), plus about $0.003 each time the cache is rebuilt. The main reasons to trim CLAUDE.md are context room and better instruction-following; the money is secondary. One line worth adding: your test command with a quiet reporter, such as npx vitest run <file> --reporter=dot, so test runs don't dump pages of output into the conversation.
7. Limit file reads and long command output
Everything Claude reads stays in context. Our calculation for Opus 5.5: a 40,000-token log file read into the conversation costs about $0.035 to cache, then about $0.0009 on every later request; over 20 requests that is about $0.053. Filter it first with grep down to the 500 relevant tokens: about $0.0007.
- Write specific prompts. "Add input validation to the login function in auth.ts" instead of "improve this codebase", so Claude doesn't scan the whole project.
- Attach files with
@.@src/auth.tsputs the file in directly and skips a search step. - Cap command output. By default Claude Code reads back up to 30,000 characters of a command's output (
BASH_MAX_OUTPUT_LENGTH) and saves longer output to a file. Use quiet flags (--quiet,--reporter=dot) or a hook that filters output, like the example in the cost docs that keeps only the last 100 lines of test output.
8. Send noisy work to a subagent on a smaller model
A subagent has its own context. It reads files, runs tests and scans logs there, and only a summary comes back to your main conversation. Our calculation, assuming one codebase exploration that reads 60,000 tokens and a main conversation that continues for 20 more requests:
| Approach | Estimated cost |
|---|---|
| Read directly in the main Opus 5.5 conversation (cached, then re-read 20 times) | ≈ $0.079 |
| Haiku 5.5 subagent reads 60,000 tokens and returns a 2,000-token summary | ≈ $0.0053 ($0.0026 in the subagent + $0.0026 for the summary in the Opus conversation) |
That leaves out the subagent's own system prompt. Create .claude/agents/log-reader.md in your project:
---
name: log-reader
description: Reads logs and test output and summarizes the failures. Use when output is long.
tools: Read, Grep, Glob, Bash
model: claude-haiku-5-5
---
Read the log or test output you are given. Return only the main errors with file and line, in at most 20 lines.The model field accepts an alias (haiku) or a full model ID (subagent docs, checked December 5, 2026); through GoiAPI, use the full ID claude-haiku-5-5. The built-in Explore subagent runs on your main conversation's model. To put every subagent on Haiku, set CLAUDE_CODE_SUBAGENT_MODEL=claude-haiku-5-5 and CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 (Claude Code 2.1.257 or later). We have not run this subagent file through GoiAPI end to end. Also keep in mind that subagents spend tokens of their own, so don't create one for a job that only needs a single file read.
9. Use plan mode before big changes
Press Shift+Tab to cycle into plan mode, or type /plan fix the auth bug. Claude reads the code and proposes an approach for you to approve before it edits anything. This doesn't shrink any single request. It prevents the most expensive pattern of all, building the wrong thing and redoing it, on a model where output costs 5 times input. Per the prompt caching docs, entering and leaving plan mode keeps the cache. If Claude heads the wrong way anyway, press Esc to stop it at once, then /rewind.
10. Turn off unused MCP servers and background work
- MCP servers: run
/mcpand disable servers you're not using. Claude Code's cost docs say CLI tools such asghandawsare still more context-efficient than MCP servers. - Background turns:
/loopand session-scoped scheduled tasks send your full context every time they fire, even while you're away, so run them in a separate fresh session. Prompt suggestions also send a short request (mostly cache reads) after each response; turn them off under Prompt suggestions in/configor withCLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false. - Agent teams: the docs say agent teams use about 7 times the tokens of a standard session when teammates run in plan mode. Only turn them on when you need them.
Which tips to do first
Ranked by the dollar effect in the calculations above, for Opus 5.5:
| Tip | Effect in our examples | Effort |
|---|---|---|
| Match the model to the task | Lean session: $0.205 down to $0.012 | Low |
| Keep the cache warm | Each miss at 150,000 tokens: about $0.132 instead of $0.0033 | Low |
| Lower effort | About $0.080 per 36,000 output tokens | Low |
| Haiku subagent for noisy work | About $0.079 down to $0.0053 per exploration | Medium |
| /clear between tasks | About $0.066 per 30 requests, more on a cache miss | Low |
| Filter output, attach the right files | About $0.053 down to $0.0007 for one log file | Medium |
| /compact at the right moment | Pays off after about 15 requests, clearly before a break | Low |
| Lean CLAUDE.md | About $0.00008 per request; the gain is mostly quality | Medium |
On a Pro, Max or Ultra plan, these habits stretch your limits rather than cut a bill. If you have already hit a cap, see Claude Code usage limit reached: what to do next. And if you are deciding which model to give coding work in the first place, our DeepSeek vs Claude for coding comparison covers the trade-offs.
FAQ
Does /compact save tokens?
Yes, but not every time. /compact spends a request reading the whole conversation, and the next request re-caches the new context. In our 150,000-token Opus 5.5 example, with a warm cache it takes about 15 more requests to pay off; right before a long break it pays off immediately. If your next task is unrelated, use /clear instead.
What is the difference between /compact and /clear?
/clear wipes the context and starts a new conversation at no token cost. /compact keeps continuity through a summary and costs one request to produce it. Use /clear when you switch tasks and /compact when you are continuing the same task but the context has grown too long.
Which model costs the least to run in Claude Code?
On GoiAPI, Claude Haiku 5.5 costs about 1/20 of Opus 5.5 for input, output and cache writes, and about 1/10 for cache reads ($0.0221 vs $0.442 per million input tokens). Use Haiku for clear, repetitive work and keep Opus for planning and hard bugs. Non-Claude models (GPT, DeepSeek, GLM) can run in Claude Code through Claude Code Router, but each model tokenizes text differently, so per-token prices don't compare directly.
Is Codex CLI cheaper on tokens than Claude Code?
We haven't measured both tools on the same task, so we have no comparison to give. Cost depends on the model you pick and how much context each tool sends. On GoiAPI prices for December 5, 2026, GPT-6.1 Sol is $0.13 input and $0.78 output per million tokens: below Opus 5.5 and above Haiku 5.5. To set Codex up with your own key, see Codex CLI with a custom provider.
Why doesn't the cost in /usage match what I was charged?
Claude Code computes "Estimated cost" locally from token counts at Anthropic's list prices. Through GoiAPI, you are charged at GoiAPI's prices, which you can see on the Request history page. The token counts should match; the dollar figures won't.
Measure your own sessions
The quickest way to know which tips matter for you is to look at real numbers. Create a GoiAPI account, top up a small amount with USDT (TRC20 or BEP20) or Binance Pay, with no credit card needed, create an API key and set a daily spending limit on it. Then work through a few sessions and open Request history. Top-ups are final and non-refundable (see the refund policy), so add only what you plan to use. Limits and balance explains how balance holds based on max_tokens work and when a low balance returns a 402 error.
GoiAPI sells API access to the models mentioned in this article.


