Claude Code cost tracking
· 2 min read
Claude Code can report its own usage: every request it makes to the model, with tokens, cost estimate, timing and errors. Turned on for a team, this answers questions the plan page cannot: which repositories use the most, which models, which sessions were unusually expensive, and whether prompt caching is working.
What Claude Code reports
Claude Code exports telemetry with OpenTelemetry when you turn it on. For each API request it sends an event with:
- the model;
- input, output, cache-read and cache-write tokens;
- its own cost estimate (
cost_usd); - the duration;
- errors, with the status code and attempt number;
- the session id, user id, and (when available) the repository.
Prompts and code are not exported unless the user explicitly turns that on.
Turn it on
Five environment variables, in the shell profile or in Claude Code's settings.json under env:
export CLAUDE_CODE_ENABLE_TELEMETRY=1 export OTEL_LOGS_EXPORTER=otlp export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf export OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector.example.com export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>"
OTEL_LOGS_EXPORTER=otlp is the one people miss: the per-request events are log events, so without it nothing about individual requests is sent.
For a team, set the same values in your organisation's managed settings so every developer reports without doing anything.
Pro and Max plans
On a Pro or Max subscription you are not billed per token, but Claude Code still reports cost_usd: what the same usage would cost on the API. That is the right number for comparing sessions, models and repositories, and for deciding whether a team is better off on subscriptions or on the API.
What to look at
- Cost per repository. Some codebases cost far more per session, usually because of how much context Claude Code reads.
- Cache-read share. Claude Code relies on prompt caching. A low share of input read from cache means you pay more for the same work.
- Model mix. How much runs on the largest model.
- Long sessions. Context grows with every turn; a very long session costs more per step at the end than at the start.
- API errors. Rate limits and overloaded errors slow developers down and show up as retries.
How Zexl tracks Claude Code
Point the endpoint at Zexl's intake (https://zexl-intake.fly.dev) with a Zexl key in the header. Each Claude Code session becomes a run, the repository becomes the feature, and the person becomes the actor. Zexl shows spend per repository, model and developer, flags missed caching and growing context, and drops any prompt text that arrives. Setup takes two minutes: Track Claude Code.
See where your own AI spend goes
One import in a Python app, or five environment variables for Claude Code. Prompts never leave your servers.