by centminmod
# Add to your Claude Code skills
git clone https://github.com/centminmod/claude-code-opentelemetry-setupMonitor your Claude Code usage with a complete observability stack: OpenTelemetry Collector, Prometheus, Loki, and Grafana. Track costs, token usage, cache efficiency, active time, and code changes in real-time with pre-built dashboards. Watch and check back for updates to this repo for step by step instructions for setting this up. Still fine-tuning the charts and panels.
An accompanying Claude Code usage metrics MCP server allows Claude Code access to it's own usage metrics (see below example along with example screenshots).
Based on Official Claude Code Documentation: Claude Code supports OpenTelemtry as described in Anthropic's official monitoring documentation.



claude mcp add --transport stdio metrics -s user -- uv run --directory /path/to/your/mcp-server metrics-server
claude mcp list
Checking MCP server health...
context7: https://mcp.context7.com/sse (SSE) - ✓ Connected
cf-docs: https://docs.mcp.cloudflare.com/sse (SSE) - ✓ Connected
metrics: uv run --directory /path/to/your/mcp-server metrics-server - ✓ Connected
This section showcases the actual JSON responses from all 14 MCP tools, demonstrating the format and data you can expect.
Returns today's total USD cost from Prometheus.
{
"metric": "Total Cost Today",
"value": 27.149809833783127,
"formatted": "$27.1498",
"unit": "currencyUSD"
}
Returns token breakdown by type (input, output, cacheCreation, cacheRead).
{
"metric": "Token Usage (24h)",
"breakdown": {
"cacheCreation": 2487212.387455661,
"cacheRead": 40278591.98958367,
"input": 16407.023220696385,
"output": 283598.58088185877
},
"total": 43065809.98114189
}
Returns cache hit rate percentage.
{
"metric": "Cache Hit Rate",
"value": 93.52789643057625,
"formatted": "93.53%",
"unit": "percent"
}
Returns comprehensive reference of all Prometheus metrics and Loki log events (truncated for brevity).
{
"prometheus_metrics": {
"claude_code_cost_usage_USD_total": {
"description": "Session cost in USD",
"type": "counter",
"labels": ["session_id", "model", "deployment_environment", "service_name"],
"example_query": "sum by (session_id) (increase(claude_code_cost_usage_USD_total[24h]))"
},
"claude_code_token_usage_tokens_total": {
"description": "Token usage by type",
...