How to Track Claude Code Token Usage and Cost: From /usage to Dashboards and APIs
Claude Code gives you five places to see token usage, and each answers a different question. /usage (still reachable as /cost) shows what the current session has spent. /context shows what is filling the context window right now. The statusline keeps a live cost and cache figure in front of you. OpenTelemetry exports per-request token and cost metrics for teams. Local log tools such as ccusage add up daily and monthly history on one machine. If you use Claude Code through QCode, the QCode dashboard and Open API show what was actually charged against your key across every tool and device. This guide covers each one as of 2026-11-25 (Claude Code 2.1.3xx), then shows how a daily quota converts to tokens and which habits cut usage the most. QCode is an independent third-party API service and is not affiliated with or endorsed by Anthropic.
Updated 2026-11-26
Key facts
/usageis the main command;/coststill works as an alias. Command names and aliases vary between builds, so run/helpto see the current list. Its dollar figure is a local estimate at list price and resets on/clear.- In an API-key session (including a third-party endpoint like QCode) you see the session cost block only. Anthropic's plan-usage breakdown and 5-hour/7-day bars are for its Pro, Max, Team and Enterprise subscriptions.
- OpenTelemetry is off by default. Turn it on with
CLAUDE_CODE_ENABLE_TELEMETRY=1. The key metrics areclaude_code.token.usageandclaude_code.cost.usage. - QCode bills official price × multiplier, currently ×1.0 for Anthropic and OpenAI models, so a list-price estimate from Claude Code and the QCode charge use the same rates. The dashboard is the authoritative number.
- The QCode daily quota resets at 00:00 Beijing time. On the Daily 35 plan that is $35 of list-price usage per day, which on Sonnet 5.5 is roughly a thousand cached agent requests, or about half that on Opus 5.5 (worked example below).
Which tool answers which question
| Question | Best tool | Scope |
|---|---|---|
| How much has this session cost so far? | /usage (or /cost), statusline cost.total_cost_usd |
Current session, this machine |
| What is eating my context window? | /context |
Current session |
| How much did I use per day this month on this laptop? | ccusage | Local logs, one machine |
| How much does each developer on my team use? | OpenTelemetry | Every machine that exports |
| What did my provider actually charge? | QCode dashboard / Open API | Every tool using the key |
/usage, /cost and /context inside Claude Code
Type /usage in a session. In an API-key session the Session block lists total cost, API duration, wall-clock duration, lines changed, and a per-model breakdown of input, output, cache-read and cache-write tokens. An illustrative line looks like this:
Total cost: $1.42
Total duration (API): 6m 12s
Total duration (wall): 38m 40s
Total code changes: 214 lines added, 61 lines removed
Usage by model:
claude-sonnet-5-5: 18.4k input, 21.7k output, 2.1m cache read, 96.0k cache write ($1.42)
How to read it:
- Cache read dominates in healthy sessions. Claude Code resends the whole conversation each turn, and the prompt cache serves most of it at a twentieth of the input price on Sonnet 5.5 and Opus 5.5. If cache write is close to cache read, your cache is going cold, usually because of long pauses or frequent model switches.
- The cost is an estimate. It is computed on your machine from list prices unless your organisation sets the managed-only
modelPricingsetting (v2.1.242+). It resets when you run/clear. - On v2.1.251+ a Prompt cache (main) line shows the hit ratio for the main conversation.
/context (or /context all) draws a coloured grid of the context window: system prompt, tools, MCP servers, memory files, skills and messages. Use it to find the expensive part of every turn. A large MCP block or a long CLAUDE.md is paid for on every request, even when it is cached.
Two more built-ins help: the spinner shows an approximate output token count for the current turn, and /insights writes an HTML report to ~/.claude/usage-data/report.html (it costs tokens to generate). For scripts, claude -p "..." --max-budget-usd 2 --max-turns 20 stops a headless run before it overspends.
A live cost figure in the statusline
The statusline receives the same numbers as JSON on every update and costs no tokens. A minimal one-liner in ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "jq -r '\"\\(.model.display_name) | ctx \\(.context_window.used_percentage // 0)% | $\\(.cost.total_cost_usd // 0 | . * 100 | round / 100) | cache \\((.prompt_cache.hit_ratio // 0) * 100 | floor)%\"'"
}
}
The full script version, with endpoint and output style, is in the statusline guide. Section 5 below adds the real QCode daily spend to the same line.
OpenTelemetry for teams
OpenTelemetry (OTel) is the official way to collect usage across many machines. Set these in the shell, or in the env block of user or managed settings (CLAUDE_CODE_ENABLE_TELEMETRY is ignored in project and local settings files):
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp # otlp | prometheus | console | none
export OTEL_LOGS_EXPORTER=otlp # per-request events
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-collector-token"
export OTEL_METRIC_EXPORT_INTERVAL=60000 # default 60 s
claude
To test without a collector, run with OTEL_METRICS_EXPORTER=console and OTEL_METRIC_EXPORT_INTERVAL=1000, and the metrics print to the terminal.
| Signal | What it contains |
|---|---|
claude_code.token.usage |
Tokens, with attribute type = input, output, cacheRead or cacheCreation, plus model |
claude_code.cost.usage |
Estimated cost in USD per model |
claude_code.session.count |
Sessions started |
claude_code.lines_of_code.count |
Lines added and removed |
claude_code.active_time.total |
Active time in seconds |
claude_code.api_request (event) |
Per request: model, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens, cost_usd, duration_ms |
Send these to any OTel backend (Prometheus with Grafana, or a hosted observability tool) and group by user and model. Like /usage, cost_usd is an estimate at list price, so reconcile monthly totals against your provider's bill.
Local history with ccusage
Claude Code stores session transcripts as JSONL files under ~/.claude/projects/ (older installs: ~/.config/claude/projects/). The open-source community tool ccusage reads those files locally, without sending data anywhere, and totals tokens and estimated cost:
npx ccusage@latest daily # per-day tokens and cost
npx ccusage@latest monthly # per-month totals
npx ccusage@latest session # per-session breakdown
# or: bunx ccusage daily
Because it only reads local logs, it works the same whether requests went to Anthropic directly or to a third-party endpoint. Two limits: it only sees the machine it runs on, and its dollar figures are list-price estimates keyed by model ID, so a model it does not recognise may show no cost.
What QCode actually charged: dashboard and Open API
The dashboard
Sign in at qcode.cc/dashboard. Usage Statistics shows the active key (full walkthrough in the docs):
- Daily Cost Limit: spent today against your plan, resetting at midnight Beijing time.
- Monthly Usage Overview: total tokens, requests and cost this month.
- Per-model breakdown: the day's input, output, cache-write and cache-read tokens for each model.
- Pay-as-you-go balance and Booster quota (Booster resets at 2 AM Beijing time).
You can set auto-refresh to Off, 5, 10, 30 or 60 minutes. The panel notes that figures may vary slightly while requests are still being settled, and there is no export button. For per-session numbers, use /usage in Claude Code.
The Open API
To read the same figures from a script, create an Open API token on the dashboard's Open API card (Manage token). It starts with qot_ and is shown once, so store it like a password. The usage query guide covers every endpoint. The main call:
export QCODE_OPENAPI_TOKEN=qot_xxxxxxxx
curl -s -H "Authorization: Bearer $QCODE_OPENAPI_TOKEN" \
https://qcode.cc/api/v1/openapi/keys \
| jq '.data.keys[] | {name, is_active, current_daily_cost, current_requests, monthly_cost_used, monthly_cost_limit}'
GET /api/v1/openapi/me returns an account summary, and GET /api/v1/openapi describes the API itself. The field names and currency in the example come from the usage query guide: run the call once and confirm them against the live response before you build a script on them. Poll once a minute at most; if you need a higher rate, test it against the live API first.
Put the real daily spend in your statusline
This helper caches the API response for 60 seconds so the statusline never hammers the endpoint:
#!/bin/bash
# ~/.claude/qcode-today.sh (needs curl + jq; chmod +x)
CACHE="${TMPDIR:-/tmp}/qcode-usage.json"
if [ -z "$(find "$CACHE" -mmin -1 2>/dev/null)" ]; then
curl -fsS -m 5 -H "Authorization: Bearer $QCODE_OPENAPI_TOKEN" \
https://qcode.cc/api/v1/openapi/keys -o "$CACHE.tmp" && mv "$CACHE.tmp" "$CACHE"
fi
jq -r '[.data.keys[] | select(.is_active)][0] | "QCode today: $\(.current_daily_cost)"' "$CACHE" 2>/dev/null
Call it from your statusline script (TODAY=$(~/.claude/qcode-today.sh)) and set "refreshInterval": 60 so the figure updates even while you are idle. Keep the qot_ token in your shell environment, not in a committed settings file. See settings.json and permissions for which files are safe to commit.
How a daily quota maps to tokens
Because QCode bills at official price ×1.0, a $35 daily quota is simply $35 of list-price usage. In raw tokens on Sonnet 5.5, at the $2 input and $10 output per million rates shown on /models, $35 buys about 17.5M uncached input tokens or 3.5M output tokens; at the $0.10 cache-read rate used in the example below, about 350M cache-read tokens. Real agent requests mix all four, so a per-request view is more useful. The figures below are illustrative arithmetic, not a benchmark — the cache rates are assumptions, so check /models before you budget on them:
| One agent turn | Sonnet 5.5 | Opus 5.5 |
|---|---|---|
| 55K tokens read from cache | $0.0055 | $0.011 |
| 5K new tokens written to cache | $0.0125 | $0.025 |
| 1.5K output tokens | $0.015 | $0.030 |
| Total per turn | ≈ $0.033 | ≈ $0.066 |
| Turns per $35 day | ≈ 1,060 | ≈ 530 |
The same Sonnet turn with a cold cache (all 60K tokens written fresh at the assumed $2.50/M cache-write rate, plus output) costs about $0.165, five times more. That is why idle gaps longer than the cache lifetime, model switches mid-session and edits to CLAUDE.md in the middle of a task show up as sudden jumps on the dashboard. For plan sizing by spend, see Claude Code cost per day and monthly cost. For reference, Anthropic reports that across enterprise deployments the average is about $13 per developer per active day, with 90% of users under $30.
Why usage climbs, and how to cut it
Usage grows with context length, because every turn resends the conversation. The common causes of spikes are long sessions near the context limit, cache misses after a pause, subagents and agent teams (Anthropic notes about 7x the tokens of a single session when teammates run in plan mode), auto-compaction, and many MCP tool definitions.
The habits with the biggest effect, drawn from Anthropic's cost guidance:
/clearbetween unrelated tasks. Old context is paid for on every turn. Use/compact Focus on the API changeswhen you must keep a thread.- Pick the model per task. Sonnet 5.5 handles most coding at half Opus 5.5's price. Use
/modelto switch, and configure subagents to use a Haiku model for searches. - Trim always-loaded context. Disable MCP servers you are not using (
/mcp), prefer CLI tools such asgh, keep CLAUDE.md under about 200 lines, and move rarely-needed instructions into skills. - Filter noisy output with hooks. A
PreToolUsehook can make test runs print only failures instead of thousands of lines. - Lower effort for simple work with
/effort. Thinking cannot be fully disabled on Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable, but a lower level shortens it. - Plan before large changes. Plan mode catches a wrong approach before Claude spends tokens implementing it.
- Write specific prompts. "Fix the null check in
src/auth/session.ts" reads one file, while "fix the login bug" may read twenty.
To exclude large folders from reading, use permissions.deny rules such as "Read(./dist/**)". A .claudeignore file has no effect in Claude Code.
FAQ
Is /cost gone in Claude Code?
No. /usage is the main command and /cost still works as an alias. Command names change between releases, so /help shows the current list in your build.
Why does /usage show a different number from my QCode dashboard?
/usage is a local list-price estimate for one session that resets on /clear. The dashboard counts every request on the key, from every session, machine and tool, after settlement. For Claude models at ×1.0 the per-request rates match, but the scopes differ.
Why don't I see the subscription usage bars in /usage?
Those bars belong to Anthropic's Claude Pro, Max, Team and Enterprise subscriptions. An API-key session, including one through QCode, shows the session cost block. Check your plan's remaining quota on the QCode dashboard instead.
Does tracking usage cost tokens?
/usage, /context, the statusline and OpenTelemetry export do not call the model. /insights does, because Claude writes the report.
Can I see usage for my whole team?
Yes, with OpenTelemetry. Push the environment variables through managed settings and send the metrics to a shared collector, then group claude_code.token.usage by user and model.
Is ccusage safe to run?
It is an open-source command-line tool that reads Claude Code's local log files and, per its documentation, does not transmit them. As with any npm package, pin a version you have reviewed if you use it at work.
How many tokens is the Daily 35 plan?
It is a dollar quota, not a token quota: $35 of official-price usage per day. In the example above that is about 1,060 cached Sonnet 5.5 turns or about 530 Opus 5.5 turns. Your mix of cache hits and output changes the figure.
Does a .claudeignore file reduce token usage?
No. Claude Code does not read .claudeignore. Use permissions.deny Read rules, or add the paths to .gitignore so search tools skip them.
Keep a predictable daily budget
QCode's Daily 35 plan gives $35 of official-price usage every day (×1.0 for Anthropic and OpenAI models) and resets at 00:00 Beijing time. One key works with Claude Code and Codex CLI, and the dashboard and Open API show exactly where the budget went. Personal plans start from $9 per 30 days; see /pricing.
Sources: Anthropic Claude Code docs (Manage costs effectively, Commands, Monitoring, Status line), the ccusage project README, QCode docs dashboard guide and usage query guide, checked 2026-11-25.