Claude code metrics via a local LGTM stack A developer documented how to export Claude Code telemetry to a locally running LGTM stack (Loki, Grafana, Tempo, Prometheus/Mimir) via OpenTelemetry. By setting environment variables such as CLAUDE_CODE_ENABLE_TELEMETRY, OTEL_METRICS_EXPORTER, and OTEL_EXPORTER_OTLP_ENDPOINT, Claude Code emits metrics (token usage, cost, session count, lines of code, active time), logs, and beta traces to an OTLP gRPC endpoint on port 4317. The writeup notes that containerized setups must swap localhost for host.containers.internal and points to Grafana dashboard ID 25255 for visualization. This assumes that you have an LGTM stack running locally, for example https://github.com/schroenser/lgtm 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 https://direnv.net/ Required export CLAUDE CODE ENABLE TELEMETRY=1 Metrics export OTEL METRICS EXPORTER=otlp export OTEL METRIC EXPORT INTERVAL=5000 Logs / events export OTEL LOGS EXPORTER=otlp export OTEL LOGS EXPORT INTERVAL=5000 Traces beta — requires the flag below export CLAUDE CODE ENHANCED TELEMETRY BETA=1 export OTEL TRACES EXPORTER=otlp export OTEL TRACES EXPORT INTERVAL=5000 Transport export OTEL EXPORTER OTLP PROTOCOL=grpc export OTEL EXPORTER OTLP ENDPOINT=http://localhost:4317 export OTEL EXPORTER OTLP METRICS TEMPORALITY PREFERENCE=cumulative Optional: include sensitive content in logs export OTEL LOG USER PROMPTS=1 export OTEL LOG TOOL DETAILS=1 | 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 https://grafana.com/grafana/dashboards/25255 dashboard, which can be imported into grafana using the "Grafana ID" 25255 .