Try Bifrost Enterprise free for 14 days. Request access

How to Reduce Claude Code Token Costs

How to Reduce Claude Code Token Costs

TL;DR

  • Anthropic's cost documentation reports that Claude Code costs an average of about $13 per developer per active day and $150 to $250 per developer per month, so reducing Claude Code token costs is a per-seat spend problem, not a rounding error.
  • Token cost scales with context size: a long session, unused MCP tool definitions, and cache misses all reprocess the full conversation on every request.
  • Prompt caching charges repeated context at roughly 10% of the base input rate, and Anthropic reports up to 90% cost reduction on cacheable prompts.
  • Routing each task to the cheapest capable model, filtering MCP tools, and running Code Mode through an AI gateway can cut token consumption by 50% to 92% at scale.
  • Bifrost, the open-source AI gateway from Maxim AI, centralizes model routing, semantic caching, an MCP gateway, and per-team budgets so Claude Code spend is measured and capped in one place.

Across enterprise deployments, Claude Code costs an average of about $13 per developer per active day and $150 to $250 per developer per month, according to Anthropic's cost-management documentation. Reducing Claude Code token costs starts with understanding that token consumption scales with context size, and every request carries the full conversation. Bifrost, an open-source AI gateway built by Maxim AI, sits between Claude Code and your model providers so routing, caching, MCP tool access, and spend limits are controlled centrally. This guide covers the full picture: context management, model routing, MCP Code Mode, semantic caching, and per-team budgets.

Where Claude Code token costs actually come from

Claude Code token costs are driven by context size. Claude Code sends the entire conversation with every request, and each tool call sends another request carrying that batch of results. Long sessions, large MCP tool definitions, cache misses, and running Opus for simple tasks are the four largest cost drivers.

The Bifrost gateway gives you a single control point in front of every one of these drivers. Before optimizing, it helps to name each source of spend and its fix. The table below maps the common cost drivers to their remedies, most of which are covered in the sections that follow.

Cost driver Why it inflates token usage Where to fix it
Long, uncleared sessions The full conversation is re-sent on every request Context management, /clear, compaction
Unused MCP tool definitions Tool schemas sit in context on every turn MCP tool filtering, Code Mode
Cache misses after a break The full context is reprocessed at the uncached rate Prompt caching, 1-hour cache lifetime
Opus as the default model Every request is billed at premium input and output rates Per-task model routing through a gateway
Repeated similar queries Identical work is billed again each time Semantic caching

For a deeper architectural view of how a gateway addresses each of these, the Claude Code gateway guide on routing, governance, and cost control walks through the full model. Each remaining section takes one driver and shows the concrete change that lowers it.

Track Claude Code token usage before you optimize

Measure Claude Code token usage before changing anything, because you cannot reduce a cost you are not tracking. Claude Code's built-in /usage and /context commands show per-session token counts and what is consuming the context window, and an AI gateway adds per-user, per-model, and per-key spend across your whole team in one dashboard.

The Bifrost AI gateway records every request that passes through it, so Claude Code token usage becomes visible per developer, per model, and per virtual key rather than sitting in individual local sessions. This turns anecdotal "our AI bill went up" conversations into a per-team number you can act on. For a gateway built specifically around this reporting, see the guide to the best AI gateway to monitor Claude Code token usage. Bifrost exposes these metrics through native observability integrations including Prometheus, OpenTelemetry, and Datadog, so the data lands in the stack you already run.

Keep the Claude Code context window small

The Claude Code context window is the single largest lever on token cost, because token usage scales directly with how much context Claude processes on each request. Clearing between unrelated tasks, writing specific prompts, and moving standing instructions out of always-loaded files are the highest-impact habits for keeping per-message cost down.

Three practices matter most for the Claude Code context window:

  • Clear between tasks. Use /clear when switching to unrelated work so stale context is not re-sent on every subsequent message.
  • Write specific prompts. A request like "add input validation to the login function in auth.ts" reads a handful of files; "improve this codebase" triggers broad, expensive scanning.
  • Move instructions to skills. A large CLAUDE.md loads into context at session start and stays there even during unrelated work; on-demand skills load only when invoked.

A gateway does not shrink the context window for you, but the Bifrost platform makes the cost of a bloated context visible per session so teams can see which workflows carry the most tokens. Pair that visibility with the routing and caching tactics below, and the Claude Code integration docs show how to point Claude Code at the gateway with a single base-URL change.

Use prompt caching to cut repeated-context costs

Prompt caching stores a prefix of your prompt, such as the system prompt and stable conversation history, and bills subsequent reads of that prefix at a fraction of the base input rate. Anthropic reports up to 90% cost reduction and up to 85% latency reduction on cacheable prompts, and Claude Code applies prompt caching automatically to repeated content.

Cache reads are priced at roughly 10% of the base input token rate, per Anthropic's prompt caching documentation, while a cache write costs about 1.25x. The economics favor caching whenever the same context is reused within the cache lifetime. Two behaviors erode this benefit:

  • Cache misses. The first request after a break longer than the cache lifetime reprocesses the full context at the uncached rate.
  • Short cache windows. The lifetime drops to five minutes on some plans; keeping the one-hour window where available preserves the cache across short pauses.

Bifrost, the AI gateway, complements provider-side prompt caching with its own semantic caching layer, covered below, so repeated and near-repeated work is served without a second model call. Anthropic's own announcement of prompt caching details the savings on long, stable prompts.

Route each task to the cheapest capable model

Model selection is the largest controllable factor in Claude Code cost after context size. Sonnet handles most coding tasks at a fraction of Opus pricing, and Haiku is cheaper still for simple subagent work. Routing each task to the cheapest model that can complete it, rather than defaulting everything to Opus, directly lowers Claude Code token costs.

Doing this by hand means every developer remembering to run /model. Doing it centrally means the open-source Bifrost gateway applies routing rules across the team, directing traffic to specific models and providers and failing over automatically when one is unavailable. Bifrost reaches 1000+ models through a single OpenAI-compatible API, so switching the model behind a request is a routing decision, not a code change. At 5,000 requests per second the gateway adds only 11 microseconds of overhead per request, so centralized routing does not become its own latency tax. The table below compares the main tactics and their reported savings.

Tactic Primary mechanism Reported impact
Per-task model routing Cheaper model per request Large share of the Opus-to-Sonnet price gap
MCP tool filtering Fewer tool schemas in context Lower per-turn context cost
Code Mode Python orchestration of tools ~50% fewer tokens, ~40% lower latency
Semantic caching Reuse of similar responses Cost and latency avoided on cache hits
MCP gateway at scale Combined controls above Up to 92% lower token costs

The Claude Code gateway explainer covers how routing, governance, and cost control fit together across a fleet of developers.

Cut MCP tool overhead with an MCP gateway

An MCP gateway is a control layer that centralizes discovery, authentication, and access policy for every MCP server a coding agent can reach. MCP tool definitions consume context on every turn, so filtering which tools are exposed and how they are called is one of the most direct ways to reduce Claude Code token costs at scale.

The Bifrost platform functions as an MCP gateway that connects to external tool servers and controls exactly which tools reach each client. Per-virtual-key MCP tool filtering keeps unused tool schemas out of context on every turn.

The MCP Gateway resource hub collects the patterns for doing this across teams. The dedicated write-up on how to reduce Claude Code token costs by up to 90% with the Bifrost MCP gateway quantifies the effect on real workloads, and the MCP gateway deep dive on access control and cost governance reports up to 92% lower token costs at scale.

Run Code Mode instead of classic MCP tool calls

Code Mode has the model write a short Python program that orchestrates several tools in one step, rather than emitting a separate tool call and consuming a separate response for each. This collapses many round trips into one, cutting both token consumption and latency for multi-tool agent workflows.

Through the Bifrost AI gateway, Code Mode reduces token usage by roughly 50% and latency by roughly 40% compared with classic per-call tool execution, because intermediate tool results stay inside the executed code instead of passing back through the model's context.

The comparison of classic MCP versus Code Mode for saving token costs at scale explains when each approach wins. For the mechanics, see the walkthrough on how to reduce MCP tool-call token costs by 50% with Code Mode and the analysis of how code execution with MCP cuts agent token costs by 90% on tool-heavy tasks.

Add semantic caching for repeated queries

Semantic caching stores responses and serves them for later queries that are semantically similar, not just byte-for-byte identical. Where prompt caching reduces the cost of re-sending the same context, semantic caching avoids the model call entirely when a close-enough answer already exists, which matters for teams running many similar prompts.

The open-source Bifrost gateway applies semantic caching based on similarity scoring, so a repeated or lightly reworded question returns a cached response instead of billing a fresh completion. This is most effective for repetitive review, summarization, and lookup workloads where the same intent recurs across a team. Combined with per-task routing and MCP tool filtering, semantic caching is one of the layers that lets a gateway compound savings rather than applying a single one-time cut to Claude Code token costs.

Set per-team budgets and cap Claude Code cost

Budgets and rate limits turn Claude Code cost from an after-the-fact surprise into an enforced ceiling. Virtual keys let you assign per-developer, per-team, and per-customer spend limits and rate limits, so no single session or automation can run up an unbounded bill before anyone notices.

The Bifrost gateway uses virtual keys as the primary governance entity, with hierarchical budgets and rate limits enforced at request time.

When a team hits its cap, requests are blocked until the window resets or the limit is raised, which prevents the runaway spend that long uncleared sessions and left-on automations can cause. The governance resource hub collects these controls, and the per-team cost governance overview documents how limits map to teams and customers, giving platform teams both the number and the brake.

Frequently Asked Questions

What is the biggest driver of Claude Code token costs?

Context size is the biggest driver. Claude Code sends the full conversation with every request, so long uncleared sessions, large MCP tool definitions, and cache misses all reprocess a large context repeatedly. Clearing between tasks, filtering MCP tools, and keeping prompt caching warm address the largest share of Claude Code token costs before any model change.

How much does Claude Code cost per developer?

Anthropic's cost documentation reports an average of about $13 per developer per active day and $150 to $250 per developer per month across enterprise deployments, with costs staying below $30 per active day for 90% of users. Actual spend varies with model choice, codebase size, and whether developers run multiple instances or automations.

Does prompt caching actually reduce cost?

Yes. Prompt caching bills reads of a cached prefix at roughly 10% of the base input rate, and Anthropic reports up to 90% cost reduction on cacheable prompts. The savings apply when the same context is reused within the cache lifetime, so cache misses after a long break and short cache windows are the main things that erode the benefit.

What is an MCP gateway and how does it lower cost?

An MCP gateway is a control layer that centralizes discovery, authentication, and access policy for the MCP servers a coding agent can reach. It lowers cost by filtering which tool definitions enter context on each turn and by enabling Code Mode, which orchestrates multiple tools in one executed program instead of many separate tool calls that each consume context.

How does model routing reduce Claude Code cost?

Routing sends each task to the cheapest model that can complete it. Sonnet handles most coding work at a fraction of Opus pricing, and Haiku is cheaper for simple subagent tasks. Applying routing centrally through a gateway means the policy is enforced for every developer automatically, rather than depending on each person to switch models by hand.

Can I cap how much a team spends on Claude Code?

Yes. Virtual keys with hierarchical budgets and rate limits enforce per-developer, per-team, and per-customer ceilings at request time. When a key reaches its budget, further requests are blocked until the window resets or the limit is raised, which prevents runaway spend from long sessions or unattended automations.

Start reducing Claude Code token costs with Bifrost

Reducing Claude Code token costs is a layered problem: keep the context window small, cache repeated context, route each task to the cheapest capable model, filter MCP tools and run Code Mode, and cap spend with per-team budgets. Handling these in one place, rather than per developer, is what makes the savings hold as a team grows. The Bifrost AI gateway unifies routing, semantic caching, MCP tool control, and governance behind a single OpenAI-compatible endpoint that Claude Code points at with one base-URL change. To see how centralized routing and budgets lower your Claude Code cost, book a demo with the Bifrost team.