← Back to blog

4 Ways to Track Claude Code Token Usage and Costs (2026)

Synrouter Team4 min read
claude-codetoken-usagecost-trackingapi-pricingtutorial

The Anthropic bill arrives 3 weeks after you incur it. By then, the debugging session that burned $40 in a single afternoon is a distant memory — and the team member who ran it has moved on to a different project.

We learned this the hard way. A developer on our team racked up $180 in Claude Code API costs over two days. Nobody noticed until the monthly invoice landed. The session logs showed 2.1M output tokens — roughly 14x what we expected. Turned out a subagent was stuck in a retry loop, regenerating the same file diff 40 times.

You can't optimize what you can't see. Here are four ways to track Claude Code token usage before the bill surprises you.

1. The Built-in: /usage

Claude Code ships with a /usage slash command. Run it inside any session and you get a token breakdown for that session:

text
1Session Usage:
2 Input tokens: 45,230
3 Cached input: 312,890
4 Output tokens: 8,410
5 Cache hit rate: 87.4%
6 Estimated cost: $1.23

Fast. No setup. But it only covers the current session — yesterday's sessions are gone, and there's no team-wide aggregation. For subscription (Pro/Max) users, the dollar figure doesn't appear because usage is baked into the plan.

For API users, /usage is your baseline sanity check. Run it before closing a session. If the cost looks wrong, dig into the token breakdown — a low cache hit rate or unusually high output tokens usually points to a problem.

2. The Source of Truth: Anthropic Console

The Usage page in the Anthropic Console is the billing source of truth. It shows daily token consumption broken down by model, with costs calculated at official rates.

The catch: data lags by 24-48 hours, and the granularity stops at the organization level. You can see that 2M Sonnet tokens were consumed on Tuesday, but not which developer or which project burned them.

For teams with shared API keys — which is most teams — the Console tells you that costs spiked, not why. You need session-level data for that.

3. The Community Tool: ccusage

ccusage is a local CLI that reads Claude Code's session log files and produces detailed breakdowns:

bash
1npx ccusage@latest

Output looks like this:

DateModelInput TokensCache ReadCache WriteOutput TokensCost
2026-07-01sonnet-4-61.2M8.4M0.3M0.4M$12.18
2026-07-02sonnet-4-60.8M6.1M0.1M0.3M$8.42
2026-07-03opus-4-80.4M2.1M0.2M0.1M$6.80

What makes ccusage better than /usage: it separates cache reads from cache writes from uncached input. That distinction matters because cached reads cost $0.30/M on Sonnet while uncached input costs $3/M — a 10x difference. If your cache read ratio drops, your bill spikes, and the aggregate numbers from the Console won't tell you why.

ccusage also exports JSON, which makes it scriptable for dashboards and alerts.

4. The Team Solution: OpenTelemetry

For teams running multiple Claude Code instances, OpenTelemetry export is the way to get per-developer attribution. Claude Code natively exports metrics (token counts, costs, tool activity) and events via the standard OTel protocol.

Set the environment variables:

bash
1export OTEL_METRICS_EXPORTER=otlp
2export OTEL_LOGS_EXPORTER=otlp
3export OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector:4318
4export OTEL_LOG_TOOL_DETAILS=true

Point it at any OTel-compatible backend — Grafana, Datadog, Honeycomb — and you get per-session, per-developer, per-model dashboards. This is what we run internally. The OTEL_LOG_TOOL_DETAILS flag is worth enabling: it logs which tools are consuming the most tokens, which is how we caught our agent's tool output waste problem.

What to Actually Look For

Once you have tracking in place, three metrics matter more than the rest:

Cache hit rate. Below 60% on Sonnet means you're paying 10x more for input than necessary. Check our caching guide for fixes.

Output token ratio. If output exceeds 15-20% of total tokens, a subagent is probably stuck in a retry loop or generating excessive diffs. That's the pattern that cost us $180.

Session cost variance. Track the 90th percentile session cost, not just the average. A few runaway sessions will dominate your bill, and the average hides them.


We built Synrouter partly because we got tired of discovering costs weeks after the fact. The gateway logs every request with full token attribution — cached vs uncached, per session, per developer — so you see costs as they happen, not when the invoice arrives.

If your Claude Code bill has been creeping up and you can't pinpoint why, sign up to get started — per-session cost visibility is included from day one.

Read next: Claude Code API Pricing: Real Costs & How to Cut Your Bill 85%

FAQ

How do I check Claude Code token usage?

Use the /usage slash command inside a Claude Code session to see input, output, and cached tokens for the current session. For aggregate billing data, check the Usage page in the Anthropic Console at console.anthropic.com.

Does Claude Code have a cost command?

Claude Code exposes session-level token usage via /usage. For API users, this includes estimated dollar costs. Subscription (Pro/Max) users see token counts but not dollar amounts, since usage is included in the plan.

How accurate is Claude Code's built-in usage tracking?

The /usage command is accurate for the current session but does not account for cache write surcharges or multi-session overhead. For team-wide tracking, use ccusage or OpenTelemetry export, which capture all sessions and calculate effective costs including cache hits and misses.

What is ccusage?

ccusage is an open-source CLI tool that reads Claude Code's local session logs and produces per-day, per-session, and per-model token breakdowns with estimated costs. It separates cached reads from uncached input, which /usage does not surface clearly.