← Insights

How to Reduce Claude Code Token Usage: What to Cut First

Clear finished work first, check the window with /context, then compact or shorten output. Trim startup context and measure what each change saves.

13 min read
How to Reduce Claude Code Token Usage: What to Cut First

Work out the order before you cut anything. Each request sends the conversation so far again, so start with one question: is the next task related to the last one? If it is not, run /clear. It starts a blank conversation and keeps the project memory, and the old conversation stays, so /resume brings it back. If the same task continues, run /context first to see what the window holds and how much room each part takes. Only then decide whether /compact should shorten the history or the commands should print less. Startup context and model choice come after that.

When /usage gives only the session total, a source-level view shows what one request is made of. cost-xray, one of Tigerless Labs' open-source projects, captures the local API traffic from Claude Code and Codex from the install onward. It takes each request's total from the provider's own usage figure, then estimates how much of that total the system prompt, the history and the tool results each take. The total matches what the provider counted, but the split between sources is an estimate. Dollar figures are estimated at API list rates, not your bill, and a subscription is paid as a plan, so check your account's usage page for what you actually pay. For how it fits with the pricing question, Claude Code pricing: plans, API billing and which one fits explains which bill applies to which plan, and see what Claude Code sends to the API and what it costs walks through one request in detail. The Cost X-Ray launch note covers the same tool from the project side.

Why does a long Claude Code session cost more with every message?

Claude Code does not bill your newest message alone. Each request re-sends the conversation so far, along with CLAUDE.md, the output of commands it ran and the files it has already read. Take a session where Claude read a 2,000-line file early on and then ran a test that printed 400 lines. Every later request carries both, until compaction or a clear removes them, even after the task has moved on to something else. Anthropic's Claude Code cost guide states the rule directly: token costs scale with how much context Claude processes. Prompt caching makes the repeated part cheaper, which is why the bill climbs gradually.

ContextWhen it enters the sessionHow it is billedWhat cuts it
The conversation so farWith each message and answerSent again while the content remains in the active context/clear between tasks, /compact mid-task
Command and tool outputWhen the command runsSent again while the content remains in the active contextQuiet flags, an output-filtering hook
CLAUDE.mdAt session startRe-read on every requestKeep it short, move workflows into skills
MCP tool definitionsAt session startNames re-read until a tool is used/mcp to disable, a CLI where one exists

What /context shows

/context answers one question: what is in the context window right now, and how much room each part takes. It groups the content by category and suggests optimizations. Run it in a fresh session to see what loads before you type. It does not total what you have spent. Compaction replaces the conversation with a summary, and old tool results can be cleared from the window, so run /context again after either one to see what changed.

What /usage shows

/usage answers a different question: how many tokens this session has used so far, by model, split into input, output, cache reads and cache writes. It counts what was spent, not what is in the window. Its Session block resets when /clear starts a new conversation, so a reading taken after /clear starts from zero. On a Pro, Max, Ultra, Team or Enterprise plan, the plan usage bars and the breakdown matter more. The breakdown attributes recent usage to skills, subagents, plugins and MCP servers, over the last 24 hours or the last 7 days, which you switch with d and w. These figures are computed from local session history on this machine, so work done on another device or on claude.ai is not counted. Each recommendation row shows the share of usage that a change applies to. That share is not the saving.

A Prompt cache line in the same block shows the share of input served from cache, the misses, and whether the cache is warm or cold. How long the cache lasts depends on the account. On a subscription, within plan usage, the main conversation gets a one-hour lifetime. On an API key, or once usage credits are drawn, the default is five minutes (cache lifetime).

How to reduce Claude Code token usage?

Start with the session, the largest lever and the cheapest to pull. The sequence below is the one most sessions need.

  1. Run /clear when the next task has nothing to do with this one, and pass a name such as /clear login-fix to label the session you are leaving.
  2. Run /resume to pick that session again when you need it.
  3. On the same task, run /context first to see how full the window is before you change anything.
  4. If the window is still heavy and the task continues, run /compact with a focus, for example /compact keep the API changes and the test commands.
  5. In a fresh session, run /context to see what loads before your first prompt, then run /mcp and disable every server you are not using.

/clear matters most between tasks. A session that has moved through three unrelated problems pays for all three on every new message. /compact suits the middle of one task. It replaces the conversation with a summary, and the focus you give it decides what the summary keeps. Compact at a natural break, such as after a test passes and before the next file, so the summary carries a finished state.

Keep CLAUDE.md short

CLAUDE.md is loaded into every turn. The Claude Help Center suggests keeping it under roughly 200 lines, and adding a note only when Claude has been corrected on the same thing twice. Instructions for a specialized workflow belong in a skill. At startup Claude receives a listing of the skills it can discover, with every skill's name and, where the listing has room, its description. The listing's budget is about 1% of the model's context window, and when it overflows, the descriptions of the least-used skills are dropped first. A regular skill's full instructions load only when it is invoked, so a PR-review routine costs little in a session about database work. Are Claude Code skills worth using? explains when that trade pays off. For facts that should outlast a session, how to give Claude Code memory across sessions compares the options.

Prefer a CLI to an MCP server where one exists

Each connected MCP server adds tool definitions. The docs note that tools such as gh, aws, gcloud and sentry-cli are more context-efficient than an MCP server, because a CLI adds no per-tool listing and Claude can run it directly. Where a CLI does the job, use it. Where a server is the only route, turn it off with /mcp in sessions that do not need it, then run /context again to see the difference. Plugins can bring their own servers and skills, so check what each one adds to every request before you keep it. Open-source Claude Code plugins worth installing lists a few with that in mind.

Does switching models save tokens?

Compare three numbers for the same task: the price per token of each model, the tokens the task actually used, and the number of turns it took.

Take a worked case. Model A finishes a task in six turns. Model B needs twelve turns for the same work, with the same tokens per turn and the same mix of input, output and cached tokens. The two cost the same only when Model B's price per token is half of Model A's. A lower price alone does not settle the choice.

Switch models at the start of a session or right after /clear. Each model has its own cache, so a switch in the middle of a conversation makes the next turn re-read everything at full price. Extended thinking is the other dial. Thinking tokens are billed as output, and /effort lowers them on a simple task. Opus 5.5, Sonnet 5.5 and Haiku 5.5 always use extended thinking, so on those models the effort level is the lever (extended thinking settings). Codex has the same trade-off, and Codex Effort explains it.

How do I check whether a change saved tokens?

Keep the project, model, task and acceptance test the same in every run, and change one variable per run: /clear before starting, one item trimmed from CLAUDE.md, a lower /effort, or a quieter test command. Record the following each time.

At the start of the run, note what /context lists in a fresh session, so you know what loaded before the first prompt. At the end, run it again to see what the window holds now. From /usage, note the Session figures by model for input, output, cache reads and cache writes at the start and at the end, and take the difference. Read the Prompt cache (main) line for the share of input served from cache, the misses and whether the cache is warm or cold. Count the turns until the task passed its acceptance test.

For runs that pass the same acceptance test, compare the total tokens used to complete the task. A lower total means the task used fewer tokens. Report the number of turns separately. Write the acceptance test down before the first run, so a change cannot pass by quietly lowering the bar. Report the readings you measured, not the ones you expected.

Test /clear with two copies of one session

To test /clear fairly, start both copies from the same project state and the same conversation history. Reset the project to one commit before each run, and use the same model and effort level in both. Build the shared history first, then make a second copy of the conversation with /branch. Before you start either copy, check that it shows the same history as the other.

Copy A keeps its history and carries on. Copy B runs /clear, which starts a blank conversation. Right after that action, record each copy's /usage starting reading. Then give both the same task on the same model, and check each result against the same acceptance test.

When each copy has finished, read /usage again. Take each copy's increment from its own starting reading, by model, for input, output, cache reads and cache writes, and count its turns. Compare the increments, not the raw totals, since the copies started from different readings.

For copies that pass the same acceptance test, compare the total tokens each one used to complete the task, taken from its own increment. A lower total for the cleared copy means the task used fewer tokens. Report the number of turns for each copy separately. The saving rate is for you to fill in from your own runs.

How can a short prompt already use tens of thousands of tokens?

Start with what is loaded, not with the test. If a short prompt fills the window faster than it should, check the startup context, the history and the tool output, in that order, and look at test output only after those.

A GitHub report shows the first case. In issue #84490, a Windows desktop user reported that a new session showed 51,700 to 56,900 context tokens after a single "hello", and that turning off the MCP connectors cut only about 9 percent. That is one user's reading of the window in one app version. The issue was closed as stale without a confirmed cause, so check /context on your own install rather than treating the number as a known figure.

Test output is the second case, and it works differently. Command output is added to the conversation like a file Claude read. It stays in the window until compaction or a clear removes it, and every later request carries it until then. A valid Bash result comes back inline up to roughly 30,000 characters. Beyond that, Claude gets a file path and a preview of up to 2,000 characters. A result that counts as a failure comes back inline up to roughly 10,000 characters, as a head-and-tail excerpt with no file path. Output below the limit is not cut, so a runner that prints one line per passing test can fill the window quietly.

Two habits help. Ask for test runs to be quiet, or to show failures only. For pytest, -q keeps the run quiet and --tb=line prints one line per failure. Other runners have their own failures-only options, so check the one you use. The docs' PreToolUse hook example runs before each shell command and keeps the last 100 lines of npm test, pytest or go test output. A failure printed early can fall outside those 100 lines, so the tail is not a failures filter.

When the output is large but the verdict is small, run the command in a subagent, since only its answer returns to the main session.

When is cutting tokens the wrong fix?

Three cases. First, the task is hard. A lower effort level or a smaller model saves tokens on routine work, but on a difficult debugging session it can cost more turns, and the docs recommend Opus for that kind of reasoning. Count turns as well as tokens per request. A session that needs twice the turns can cost more even when each turn is cheaper, so compare the whole task, not one message.

Second, you still need the history. /clear starts a new conversation, so a decision that is still in play should go into a /compact focus or into a file before you leave the session. The old conversation stays available through /resume, but the new one does not carry its history.

Third, the background is the cost. A /loop or other session-scoped scheduled task fires as a full turn in its session and carries the whole conversation each time. A session idle past the cache lifetime re-reads everything on its next turn, and the lifetime is one hour on a subscription within plan usage but five minutes on an API key or once usage credits are drawn. /usage lists the heaviest loops that ran recently, and stopping an idle loop often saves more than any prompt change.

cost-xray does not change this either. It observes what the agent sends and what it costs, and it does not cut spend by itself. Use it to see what to trim, then trim it with the steps above.

Conclusion

Claude Code's token bill comes down to what stays in the context and for how many requests. The biggest cut is the one that removes tokens from every later request, not from a single message. Clear finished work, keep startup context short, quiet the noisy output, and use the model that fits the task. Then check the result with /context and /usage, and count turns as well as tokens.

The best way to reduce Claude Code token usage is the one that takes a token out of every request that follows, so trim startup context before you tune individual prompts.

Free next step: open a fresh Claude Code session, run /context, and count what loads before you type. Remove one item from that list, then compare /usage at the end of the day.

FAQ

Does /clear reduce Claude Code token usage?

Yes, between unrelated tasks. /clear starts a blank conversation, so the next task pays only for its own context. The old conversation stays available through /resume, and /clear labels the session you are leaving so it is easy to find.

Does switching to Sonnet save tokens in Claude Code?

It can, but measure it. Compare the price per token, the tokens the task actually used and the number of turns it took. The Claude Code docs recommend Sonnet as the default for most coding work. Switch at the start of a session or right after /clear, because a switch in the middle of a conversation re-reads everything at full price.

Is /compact cheaper than starting a new session?

It depends on the task. /compact keeps a summary of the work so far, so it suits a task that is still going. A new session is cheaper when the next task has nothing to do with the last one, because it carries no history at all.

How do I see what Claude Code sends to the API?

/context lists what is in the context window and how much room each part takes, and /usage totals the session's tokens by model. To split one request's cost by source, cost-xray at tigerless.ai/labs/cost-xray takes the total from the provider's own usage figure and estimates how the system prompt, the history and the tool results share it. The total matches the provider's count, the split is an estimate, and dollar figures use API list prices, not your subscription bill.

Does lowering the thinking effort cut token costs?

On simple tasks, yes: thinking tokens are billed as output, so a lower /effort level costs less. On hard tasks it can cost more turns, and the docs recommend Opus for complex reasoning. Per Claude Code's cost guide, Opus 5.5, Sonnet 5.5 and Haiku 5.5 always use extended thinking, so on those models the effort level is the dial.

Share this article

Keep reading