How to Reduce Claude Code Token Usage: 8 Tactics

Key takeaways

  • Prompt caching saves 90% on repeated context after an initial 10× write cost, breaking even after 2–3 reuses within five-minute windows.
  • Claude 3.5 Haiku costs 96% less than Sonnet per token for simple tasks like linting and syntax fixes, though it cannot use prompt caching.
  • Output tokens cost 5× input tokens on Sonnet ($75 vs $15 per million), making diff-only responses and output length limits high-impact optimizations.
  • Anthropic’s batch API cuts costs 50% across all models in exchange for up to 24-hour processing time, ideal for bulk analysis and test generation.
  • Context pruning and model selection deliver immediate, predictable savings; streaming early-stop and function calling require workflow changes but can reduce output tokens 30–80%.

Claude’s coding assistance can burn through tokens faster than you expect. A single code review session with full repository context can consume 50,000 tokens or more, and at $15 per million input tokens on Claude 3.5 Sonnet, costs add up when you’re running dozens of requests daily. The fix is not using Claude less—it’s using it smarter.

Below are eight tactics that reduce token consumption without sacrificing the quality of Claude’s output. Each is mapped to the scenarios where it delivers the highest savings.

Token-reduction decision matrix

Tactic Best for Typical token savings Cost impact
Prompt caching Repeated code reviews, iterative debugging 90% on cached portions (10× write cost, then 90% off reads) High savings after 2–3 reuses
Model downgrade (Haiku) Simple syntax fixes, linting Same token count, 96% cheaper per token ($0.25 vs $3 per million input on Haiku vs Sonnet) Immediate 96% cost cut
Context pruning Large codebases, multi-file generation 40–70% fewer input tokens Proportional cost drop
Output length limits Code snippets, targeted refactoring 30–50% fewer output tokens Output tokens cost 3× input on Sonnet ($15 vs $75 per million)
Diff-only responses Code modification, incremental changes 60–80% fewer output tokens Large savings on output-heavy tasks
Streaming with early stop Exploratory queries, prototyping Variable, 10–40% when you stop mid-response Pay only for tokens generated before stop
Function calling over prose Structured data extraction, API integration 20–40% fewer output tokens Eliminates verbose explanations
Batching requests Bulk code analysis, test generation 50% cost reduction via batch API (Anthropic batch discount) Half-price input/output, 24-hour turnaround

Prompt caching: pay once, reuse many times

Who it’s for: Developers iterating on the same codebase or debugging the same module across multiple sessions.

Prompt caching lets you mark sections of your input—like a large code file or project documentation—so Claude stores them server-side. On subsequent requests, you pay 10× the normal write cost the first time, then 90% less on every read. According to Anthropic’s documentation, cached tokens cost $1.50 per million to write (vs $3 standard) but only $0.30 per million to read on Claude 3.5 Sonnet.

A 20,000-token repository context costs $60 to send normally over 20 requests. With caching, you pay $30 upfront, then $6 total for the next 19 reads—$36 vs $60.

The drawback: Caches expire after five minutes of inactivity. If your workflow has long gaps between requests, you lose the savings and pay the 10× write cost repeatedly.

Model downgrade: Haiku for simple tasks

Who it’s for: Syntax fixes, import sorting, basic linting, docstring generation.

Claude 3.5 Haiku costs $0.25 per million input tokens and $1.25 per million output tokens—96% and 98% cheaper than Sonnet. Token counts stay the same; you just pay far less per token. If a linting task consumes 5,000 input and 1,000 output tokens, Sonnet costs $0.09 and Haiku costs $0.002.

Haiku handles straightforward code tasks well. It struggles with complex architectural decisions or multi-step refactoring.

The drawback: Haiku cannot use prompt caching as of September 2026, so you lose that optimization lever. It also produces weaker reasoning on ambiguous requirements.

Context pruning: send only relevant files

Who it’s for: Code generation and review in projects with dozens or hundreds of files.

Sending an entire 50-file repository when Claude only needs three files wastes tokens. A 100,000-token dump costs $1.50 on Sonnet input; a pruned 30,000-token subset costs $0.45. Over 100 requests, that’s $150 vs $45.

Prune by identifying dependencies: if you’re modifying user_controller.rb, include the User model and related routes, but skip unrelated modules like payment processing or admin dashboards. Tools like ctags or language servers can map dependencies automatically.

The drawback: Aggressive pruning can strip context Claude needs to avoid breaking changes elsewhere. You’ll spend tokens on follow-up fixes.

Output length limits: cap token generation

Who it’s for: Targeted refactoring, code snippet generation, quick fixes.

Claude’s max_tokens parameter caps output length. If you need a 20-line function, set max_tokens to 200 instead of the default 4096. Output tokens cost $75 per million on Sonnet—five times input cost—so a 2,000-token response costs $0.15, while a 200-token response costs $0.015.

This works when the task scope is clear. Asking for “a function to parse JSON” with a 200-token cap is fine. Asking for “improve this module” with the same cap will get you an incomplete answer.

The drawback: If Claude hits the limit mid-sentence, you get truncated code that won’t compile. You’ll need a second request to finish, negating savings.

Diff-only responses: output changes, not whole files

Who it’s for: Incremental code modifications, bug fixes, small refactors.

Instead of asking Claude to return an entire modified file, request a unified diff or line-by-line changes. A 500-line file rewritten in full costs 2,000+ output tokens; a diff showing 30 changed lines costs 150 tokens. That’s $0.15 vs $0.01 per response on Sonnet output pricing.

Prompt example: “Show only the lines that need to change in unified diff format.” or “Return a JSON object with line numbers and replacement text.”

The drawback: Diffs require you to apply changes manually or script the merge, adding workflow friction. Full-file output is easier to copy-paste.

Streaming with early stop: halt when you have enough

Who it’s for: Exploratory coding, prototyping, brainstorming architecture.

Streaming responses let you read output as Claude generates it. If the first 500 tokens answer your question, you can cancel the request and avoid paying for the remaining 1,500 tokens. Anthropic’s API charges only for tokens generated before you close the stream.

This is practical when you’re testing ideas and don’t need a complete implementation—just enough to decide direction.

The drawback: You need code to handle streaming and a clear signal for when to stop. Without automation, you’re manually watching every response, which kills productivity.

Function calling over prose: structured output only

Who it’s for: Extracting structured data from code, generating API payloads, test case lists.

Claude’s function calling (tool use) returns JSON matching a schema you define, skipping the natural-language explanation. A prose response might be 800 tokens explaining and then listing five test cases; a function call returns the five cases in 200 tokens of JSON.

Example: instead of “List the functions in this file and describe each,” define a tool that returns [{"name": "...", "params": [...]}]. Claude populates it directly.

The drawback: You lose human-readable explanations. If you need to understand why Claude chose certain test cases, function calling won’t tell you.

Batching requests: half-price, slower turnaround

Who it’s for: Bulk code analysis, mass test generation, nightly refactoring jobs.

Anthropic’s batch API offers 50% off input and output tokens in exchange for up to 24-hour processing time. A job that would cost $10 in real-time API calls costs $5 as a batch. You submit a file of requests, Claude processes them overnight, and you retrieve results the next morning.

This suits tasks that don’t need instant feedback: analyzing 200 pull requests for style violations, generating unit tests for an entire module, scanning a codebase for deprecated patterns.

The drawback: You cannot interact mid-task. If Claude misunderstands one request in a 200-request batch, you won’t know until the batch completes.

What was compared

Token counts and pricing come from Anthropic’s published rate card as of September 2026 and the Claude API documentation on prompt caching, model pricing, and batch discounts. Percentage savings are calculated from those rates applied to representative task sizes: a 20,000-token repository context, a 500-line file modification, a 5,000-token code review prompt. No live API testing was conducted; figures reflect the pricing structure Anthropic publishes.

Who should skip all of these

If you’re running fewer than 50 Claude requests per month, optimization won’t recover enough cost to justify the workflow overhead. A $2 monthly bill that drops to $0.60 is not worth engineering custom pruning scripts or batch pipelines. Just use Sonnet normally and focus on shipping code.

If your employer has a flat-rate enterprise agreement with Anthropic, token optimization may be irrelevant—you’re not paying per token anyway. Check your contract first.

Frequently asked questions

How do I check my Claude code token usage?

In the Anthropic Console, navigate to Usage under your organization settings. It shows input and output tokens per day, broken down by model. API responses also include a usage object with input_tokens and output_tokens for each request, so you can log these in your application and track usage over time.

What counts as a token in Claude code?

Claude tokenizes text into subword units. Roughly, one token equals four characters or three-quarters of a word in English. Code tokenizes similarly: function is one token, getUserData is typically three. Whitespace, brackets, and operators each count. Anthropic provides a tokenizer tool in the API documentation to preview exact counts for your input.

Does caching reduce Claude token costs?

Yes, but only after the first use. You pay 10× the standard rate to write a cache block, then 90% less on every subsequent read within five minutes. If you reuse the same 20,000-token context five times, caching saves roughly 70% compared to sending it fresh each time. Single-use prompts see no benefit and cost more.

How much do Claude code tokens cost per model?

As of September 2026, Claude 3.5 Sonnet costs $3 per million input tokens and $15 per million output tokens. Claude 3.5 Haiku costs $0.25 input and $1.25 output per million. Opus pricing is $15 input and $75 output per million. Batch API requests receive 50% off these rates across all models, with up to 24-hour processing time.

Can I set a token limit in Claude code?

Yes, use the max_tokens parameter in your API request to cap output length. This prevents runaway generation and controls output costs. There is no parameter to limit input tokens—you must prune context manually before sending. If input exceeds the model’s context window (200,000 tokens for Sonnet), the API returns an error before charging you.

Photo by Daniil Komov on Pexels