A comprehensive Grafana dashboard for monitoring Claude Code usage via OpenTelemetry.
- Overview — Sessions, Cost (24h), Tokens (24h), Lines Changed, Commits, Active Time
- Cost & Tokens — Cost by model, token usage by type (input/output/cache)
- Activity — Lines of code changed, sessions/commits/PRs over time
- Active Time & Tokens by Model — Active time breakdown, tokens per model
- Tool Decisions — Edit tool decisions by tool name, language, and source
- Cumulative — Running total cost and token counters
- API request count, errors, and latency
- Tool usage frequency and duration
- Per-request cost and token breakdown (input/output/cache read/cache creation)
- Formatted event log viewer
- Claude Code with OTel telemetry enabled
- OpenTelemetry Collector (Alloy, otel-collector, etc.) receiving OTLP and forwarding to Prometheus
- Prometheus datasource in Grafana
- Loki datasource in Grafana (optional, for the Events section)
Add the following to ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://<your-collector>:4317",
"OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "cumulative"
}
}Note: Restart Claude Code after changing
settings.json— environment variables are only loaded at process startup.
See the official docs for more details.
Option A — File upload:
- Open Grafana → Dashboards → Import
- Upload
dashboard.json - Select your Prometheus and Loki datasources
Option B — Grafana.com ID:
Coming soon.
| Metric | Description | Labels |
|---|---|---|
claude_code_session_count_total |
Number of sessions started | — |
claude_code_cost_usage_USD_total |
Cost in USD | model |
claude_code_token_usage_tokens_total |
Token count | model, type |
claude_code_lines_of_code_count_total |
Lines of code changed | type |
claude_code_commit_count_total |
Git commits made | — |
claude_code_pull_request_count_total |
Pull requests created | — |
claude_code_active_time_seconds_total |
Active coding time | type |
claude_code_code_edit_tool_decision_total |
Edit tool decisions | tool_name, decision, language, source |
If your collector forwards OTel logs to Loki, the Events section displays:
| Event | Key Attributes |
|---|---|
api_request |
model, cost_usd, duration_ms, input_tokens, output_tokens, cache_read_tokens |
api_error |
error, status_code |
tool_result |
tool_name, success, duration_ms |
tool_decision |
tool_name, decision |
user_prompt |
prompt_length |
MIT