By Maya Lindqvist, NBT
Once a team adopts an AI coding assistant, the questions change. It's no longer "does it work?" but "who's using it, for what, and what does it cost?" Guessing from a monthly bill doesn't answer that. Claude Code can tell you directly: it exports metrics and events over OpenTelemetry, the same open standard many teams already use for application monitoring.
This guide sets it up in stages: a one-minute console test on your own machine, a local Prometheus endpoint, then a shared collector for a team, with the privacy settings to decide on before you roll it out. Everything comes from Anthropic's Claude Code monitoring page, fetched on 6 December 2026. If you're still choosing a tool, see our comparison of AI coding assistant options: Claude Code, Codex and Copilot CLI.
What you get
The docs list these metrics:
| Metric | What it counts |
|---|---|
claude_code.session.count | Sessions started |
claude_code.lines_of_code.count | Lines of code modified |
claude_code.pull_request.count | Pull requests created |
claude_code.commit.count | Git commits created |
claude_code.cost.usage | Cost of the session, in USD |
claude_code.token.usage | Tokens used |
claude_code.code_edit_tool.decision | Permission decisions on code edits |
claude_code.active_time.total | Active time, in seconds |
claude_code.token.usage carries a type attribute: input, output, cacheRead and cacheCreation. Cache reads and writes are counted separately from plain input, which matters when you're working out why a long session was cheap or expensive.
Two caveats from the docs. The cost metric is an approximation; for billing, use the official cost reports. And exporting to your backend is opt-in: nothing is sent until you configure it.
Stage 1: a console test in one minute
Before involving any infrastructure, check that telemetry works at all:
export CLAUDE_CODE_ENABLE_TELEMETRY=1 export OTEL_METRICS_EXPORTER=console export OTEL_METRIC_EXPORT_INTERVAL=1000 claude CLAUDE_CODE_ENABLE_TELEMETRY=1 is required; without it nothing is collected. The console exporter prints metrics to the terminal, and the short interval (in milliseconds; the default is 60000) makes them appear quickly. Ask Claude something small and you should see claude_code.session.count and token counts.
If nothing appears, start with claude --debug-file <path> and look in that file. Failures from your exporters show as [3P telemetry] errors. Lines marked [Anthropic telemetry] are Anthropic's separate operational telemetry and don't mean your setup is broken.
Stage 2: a local Prometheus endpoint
If you already run Prometheus or Grafana, this is the shortest path to a chart:
export CLAUDE_CODE_ENABLE_TELEMETRY=1 export OTEL_METRICS_EXPORTER=prometheus claude Claude Code then serves metrics at http://localhost:9464/metrics for Prometheus to scrape. Point a scrape job at it and plot claude_code.token.usage by type.
This is fine for one developer. For a team you want everyone's data in one place.
Stage 3: a shared collector for the team
Run an OpenTelemetry Collector (or any OTLP-compatible backend) and point everyone at it:
export CLAUDE_CODE_ENABLE_TELEMETRY=1 export OTEL_METRICS_EXPORTER=otlp export OTEL_LOGS_EXPORTER=otlp export OTEL_EXPORTER_OTLP_PROTOCOL=grpc export OTEL_EXPORTER_OTLP_ENDPOINT=http://collector.internal:4317 export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-token" Metrics are numbers over time. Logs (events) are individual things that happened, such as a prompt being submitted. Turn on whichever you need; both exporters are optional.
To check it's working, look in your backend for claude_code.session.count after someone starts a session. For a logs-only setup, submit a prompt and look for a claude_code.user_prompt event.
Don't put this in the repository
It's tempting to add these variables to .claude/settings.json so everyone gets them. The docs say that won't work: Claude Code ignores the OpenTelemetry exporter variables in a repository's .claude/settings.json and .claude/settings.local.json, so a repo can't turn telemetry on, pick where it goes, or capture content. A repo can only switch a signal off by setting its exporter to none.
The supported places are each developer's shell or ~/.claude/settings.json (in its env block), or managed settings deployed by an administrator. For a company rollout, managed settings are the right choice. When OTEL_EXPORTER_OTLP_ENDPOINT is set there, Claude Code removes developer-set per-signal endpoints, so nobody can quietly redirect one signal elsewhere. The exporter selectors still follow normal precedence, so set those in managed settings too if they must stay on.
Stage 4: slice it by team
Add your own labels with OTEL_RESOURCE_ATTRIBUTES:
export OTEL_RESOURCE_ATTRIBUTES="department=engineering,team.id=platform,cost_center=eng-123" These attributes are attached to every metric and event, so you can filter dashboards by team, track cost per cost centre and alert on a single team's spend. The cost metric also carries skill.name, plugin.name and agent.name attributes, which tell you whether a particular skill or subagent is driving usage.
Decide on privacy before rollout
The defaults are conservative, and you should know what changes them:
- Prompt text isn't collected by default. Only prompt length is recorded.
OTEL_LOG_USER_PROMPTS=1turns on prompt content. The docs note thatuser_promptevents then carry the text in two attributes,promptandprompt_text, so a collector rule that redacts prompts must name both. - File contents and code aren't included by default. Variables such as
OTEL_LOG_TOOL_DETAILSorOTEL_LOG_RAW_API_BODIESchange that. Raw API bodies can include the whole conversation history. - Email addresses are included for OAuth users. When people sign in with OAuth,
user.emailis part of the telemetry attributes. It goes only to your endpoint, never to Anthropic, but filter it in your backend if that's a concern.
A sensible starting point for most teams: metrics on, logs on, every content variable off. Turn content on only for a specific investigation, then off again.
Four charts worth building first
- Tokens per day by
type. Because cache reads are counted apart from plain input, this shows how much of your usage is context being reused rather than sent fresh. - Approximate cost per team, using your
team.idattribute. - Commits and pull requests per week, from
claude_code.commit.countandclaude_code.pull_request.count, next to active time. - Edit decisions, from
claude_code.code_edit_tool.decision, to see how often people accept or reject proposed edits.
None of these measure whether the code is good. They tell you where the AI coding assistant is being used and what it costs, which is what you need before you can have that conversation with any evidence.

