This assumes that you have an LGTM stack running locally, for example https://github.com/schroenser/lgtm. LGTM stands for
- L — Loki (for logs)
- G — Grafana (for visualization and correlation)
- T — Tempo (for distributed traces)
- M — Prometheus / Mimir (for metrics — with Prometheus handling collection/storage and Mimir often used for long-term scalable metrics)
A set of environment variables must be set before running claude.
This can be done either using an .envrc file or claudes settings.json.
💡 Note that if you run claude in a (dev)container itself, you need to exchange localhost for host.containers.internal so it can reach the gRPC port which the LGTM stack exposes on the host machine.
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_METRIC_EXPORT_INTERVAL": "5000",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORT_INTERVAL": "5000",
"CLAUDE_CODE_ENHANCED_TELEMETRY_BETA": "1",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_TRACES_EXPORT_INTERVAL": "5000",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317",
"OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "cumulative"
}
}
e.g. with direnv
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_METRIC_EXPORT_INTERVAL=5000
export OTEL_LOGS_EXPORTER=otlp
export OTEL_LOGS_EXPORT_INTERVAL=5000
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
export OTEL_TRACES_EXPORTER=otlp
export OTEL_TRACES_EXPORT_INTERVAL=5000
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative
| Signal | Key names | Default interval |
|---|---|---|
| Metrics | claude_code.token.usage ,claude_code.cost.usage ,claude_code.session.count ,claude_code.lines_of_code.count ,claude_code.active_time.total |
60 s |
| Logs | claude_code.user_prompt ,claude_code.api_request ,claude_code.tool_result ,claude_code.tool_decision |
5 s |
| Traces (beta) | claude_code.interaction ,claude_code.llm_request ,claude_code.tool ,claude_code.tool.execution |
5 s |
The most straight forward dashboard to view those metrics is the Claude Code Metrics (Prometheus) dashboard, which can be imported into grafana using the "Grafana ID" 25255.