cd /news/ai-tools/claude-code-metrics-via-a-local-lgtm… · home › topics › ai-tools › article
[ARTICLE · art-164381] src=gist.github.com ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

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.

by read1 min views29 publishedNov 2, 2026

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.

── more in #ai-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/claude-code-metrics-…] indexed:0 read:1min 2026-11-02 · —