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
| Variable | What it does | Default |
|---|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | The master switch. Nothing is exported without it. | off |
OTEL_METRICS_EXPORTER | otlp, prometheus, console or none | none set |
OTEL_LOGS_EXPORTER | Events. otlp, console or none | none set |
OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf, http/json or grpc. Claude Code has no default, so set it. | none |
OTEL_EXPORTER_OTLP_ENDPOINT | The collector's base URL. The SDK appends /v1/metrics and /v1/logs itself. | none |
OTEL_METRIC_EXPORT_INTERVAL | Milliseconds between metric exports | 60000 |
OTEL_LOGS_EXPORT_INTERVAL | Milliseconds between event exports | 5000 |
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE | delta or cumulative | delta |
OTEL_METRICS_INCLUDE_ENTRYPOINT | Tags each data point with app.entrypoint (CLI, IDE extension, desktop, SDK) | false |
OTEL_LOG_USER_PROMPTS | Adds prompt text to events | off |
OTEL_LOG_TOOL_DETAILS | Adds tool details: MCP server and tool names, skill names, Bash commands and tool input | off |
OTEL_RESOURCE_ATTRIBUTES | Your own tags, such as team=support,cost_center=42 | none |
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.
| Metric | Unit | Useful attributes |
|---|---|---|
claude_code.session.count | count | how the session started (fresh, resume, continue) |
claude_code.token.usage | tokens | type: input, output, cacheRead, cacheCreation; model |
claude_code.cost.usage | USD | model. An estimate computed by Claude Code, not an invoice. |
claude_code.lines_of_code.count | count | type: added, removed |
claude_code.commit.count | count | commits made through Claude Code |
claude_code.pull_request.count | count | pull requests created through Claude Code |
claude_code.code_edit_tool.decision | count | tool_name, decision: accept or reject, language |
claude_code.active_time.total | seconds | type: 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_decisionandclaude_code.tool_result: a tool accepted or rejected, and its outcome.claude_code.user_prompt: a prompt was sent. Its length only, unlessOTEL_LOG_USER_PROMPTSadds 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=1puts prompt text into events.OTEL_LOG_TOOL_DETAILS=1adds 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:
| What | Where it goes | How to turn it off |
|---|---|---|
| OpenTelemetry export | Your own collector | Off by default. Remove CLAUDE_CODE_ENABLE_TELEMETRY or set it to 0. |
| Operational metrics | Anthropic | DISABLE_TELEMETRY=1 |
| Error reports | Anthropic | DISABLE_ERROR_REPORTING=1 |
| All non-essential traffic | Anthropic | CLAUDE_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 event | What it tells you |
|---|---|
codex.sse_event (event.kind=response.completed) | Token counts for one response |
codex.conversation_starts | A new session |
codex.api_request | Request latency and status, by model |
codex.tool_decision | A 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 theenvblock insettings.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]makesconfig.tomlunparseable. 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.usageis 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