Reference

Claude Code OpenTelemetry: metrics, events and setup

Claude Code can export its own usage as OpenTelemetry: tokens, cost, sessions, lines changed, commits and tool decisions. OpenAI's Codex CLI can too. This page gathers the settings, the metric names and the gotchas in one place, as we use them to run Acadmi.

Updated · Checked against Claude Code's monitoring documentation

In short. OpenTelemetry export is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose an exporter. Metrics and events (logs) are separate pipelines. Prompt text, Bash commands and file paths are not exported unless you turn on OTEL_LOG_USER_PROMPTS or OTEL_LOG_TOOL_DETAILS. Codex is configured in ~/.codex/config.toml, not with environment variables.

Turn it on

Put the variables in the env block of ~/.claude/settings.json rather than only in your shell profile. Sessions started from an IDE or the desktop app never read your shell profile, so variables set only there silently miss them.

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:4318",
    "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "delta",
    "OTEL_METRIC_EXPORT_INTERVAL": "30000",
    "OTEL_LOGS_EXPORT_INTERVAL": "30000",
    "OTEL_METRICS_INCLUDE_ENTRYPOINT": "true"
  }
}

This sends both pipelines over OTLP/HTTP to a collector on your own machine (port 4318 is the OTLP/HTTP default). Point the endpoint at any OpenTelemetry collector: your own, Grafana, Datadog, Honeycomb or another backend that accepts OTLP. To try it without a collector, set both exporters to console and watch the output.

The settings that matter

VariableWhat it doesDefault
CLAUDE_CODE_ENABLE_TELEMETRYThe master switch. Nothing is exported without it.off
OTEL_METRICS_EXPORTERotlp, prometheus, console or nonenone set
OTEL_LOGS_EXPORTEREvents. otlp, console or nonenone set
OTEL_EXPORTER_OTLP_PROTOCOLhttp/protobuf, http/json or grpc. Claude Code has no default, so set it.none
OTEL_EXPORTER_OTLP_ENDPOINTThe collector's base URL. The SDK appends /v1/metrics and /v1/logs itself.none
OTEL_METRIC_EXPORT_INTERVALMilliseconds between metric exports60000
OTEL_LOGS_EXPORT_INTERVALMilliseconds between event exports5000
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCEdelta or cumulativedelta
OTEL_METRICS_INCLUDE_ENTRYPOINTTags each data point with app.entrypoint (CLI, IDE extension, desktop, SDK)false
OTEL_LOG_USER_PROMPTSAdds prompt text to eventsoff
OTEL_LOG_TOOL_DETAILSAdds tool details: MCP server and tool names, skill names, Bash commands and tool inputoff
OTEL_RESOURCE_ATTRIBUTESYour own tags, such as team=support,cost_center=42none

The metrics Claude Code sends

Every metric carries the session and, when signed in, the account and organization. With delta temporality each export carries only what happened since the last one, so a backend sums them.

MetricUnitUseful attributes
claude_code.session.countcounthow the session started (fresh, resume, continue)
claude_code.token.usagetokenstype: input, output, cacheRead, cacheCreation; model
claude_code.cost.usageUSDmodel. An estimate computed by Claude Code, not an invoice.
claude_code.lines_of_code.countcounttype: added, removed
claude_code.commit.countcountcommits made through Claude Code
claude_code.pull_request.countcountpull requests created through Claude Code
claude_code.code_edit_tool.decisioncounttool_name, decision: accept or reject, language
claude_code.active_time.totalsecondstype: user or cli

The events

Events go through the logs exporter, one record per thing that happened. The ones most teams read:

  • claude_code.api_request: one model call, with model, tokens, cost and duration. The most precise source for cost per request.
  • claude_code.api_error: a failed call, with its status code.
  • claude_code.tool_decision and claude_code.tool_result: a tool accepted or rejected, and its outcome.
  • claude_code.user_prompt: a prompt was sent. Its length only, unless OTEL_LOG_USER_PROMPTS adds the text.
  • claude_code.skill_activated, claude_code.mcp_server_connection, claude_code.plugin_loaded: which skills, MCP servers and plugins are in use.

Claude Code adds events as it grows; the official list is the source of truth.

What stays private by default

Out of the box the export is volume and metadata: counts, tokens, cost, model names, durations. Two switches widen it, and both are off unless you set them:

  • OTEL_LOG_USER_PROMPTS=1 puts prompt text into events.
  • OTEL_LOG_TOOL_DETAILS=1 adds tool details. It is the only way to learn which MCP tools and skills are used, but it also carries Bash commands and file paths.

If you want tool names without the commands, turn tool details on and strip the rest in your collector before it is stored. That is what Acadmi's agent does on each computer: it keeps the tool name and drops commands, paths and arguments before anything leaves the machine. Our privacy page lists exactly what is kept.

Turning telemetry off

"Claude Code telemetry" means two different things, with different switches:

WhatWhere it goesHow to turn it off
OpenTelemetry exportYour own collectorOff by default. Remove CLAUDE_CODE_ENABLE_TELEMETRY or set it to 0.
Operational metricsAnthropicDISABLE_TELEMETRY=1
Error reportsAnthropicDISABLE_ERROR_REPORTING=1
All non-essential trafficAnthropicCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

To leave one project out of an export that is on everywhere else, put this in that project's .claude/settings.json, or in .claude/settings.local.json, which git ignores:

{ "env": { "CLAUDE_CODE_ENABLE_TELEMETRY": "0" } }

Every session started in that folder then exports nothing. We tested this with one session with the override and one without.

OpenAI Codex CLI

Codex speaks the same OTLP/HTTP, but it is configured in a file, ~/.codex/config.toml (or $CODEX_HOME/config.toml), and the endpoint is the full per-signal URL rather than a base:

[otel]
log_user_prompt = false

[otel.exporter.otlp-http]
endpoint = "http://127.0.0.1:4318/v1/logs"
protocol = "binary"

Codex reports its usage as log records, so the logs exporter alone carries everything a usage dashboard needs:

Codex eventWhat it tells you
codex.sse_event (event.kind=response.completed)Token counts for one response
codex.conversation_startsA new session
codex.api_requestRequest latency and status, by model
codex.tool_decisionA tool call approved or denied

Two differences from Claude Code to plan for. Codex reports no cost, so a Codex-only user shows tokens but no dollars. And its attribute names differ: conversation.id where Claude Code says session.id, model_reasoning_effort for effort, and the HTTP status as an integer. Map them once, at ingest.

Gotchas we hit

  • Shell-only variables miss IDE sessions. VS Code, JetBrains and the desktop app don't source ~/.zshrc. Use the env block in settings.json.
  • Base URL vs. full URL. Claude Code wants the collector's base (…:4318); Codex wants the full logs URL (…:4318/v1/logs). Swap them and nothing arrives, with no error.
  • Codex rejects a second [otel] table. Appending one next to an existing [otel] makes config.toml unparseable. Edit the one that is there.
  • Sum deltas; don't take the last value. With delta temporality a dashboard that shows the latest point instead of the sum undercounts every session.
  • Traces are separate. Tracing is a beta behind its own switch. Usage dashboards don't need it, and a collector can accept and drop /v1/traces.
  • Cost is an estimate. claude_code.cost.usage is computed from list prices. On a Claude subscription it shows what the usage would have cost on the API, not what you pay.

Rather not run a collector?

Acadmi sets all of this up in one step, for Claude Code and Codex. It keeps counts and tool names, drops prompts, commands and paths on each computer, and turns the result into levels, streaks and a team leaderboard.

Join the waitlist