I Built an Exporter and Grafana Dashboard for Claude Code

Published: (February 12, 2026 at 08:34 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

The Problem

I use Claude Code daily, but I had no idea where my tokens were going. How many tokens per model? Which tools get called the most? How active are my sessions?

Claude Code stores usage data locally in ~/.claude, but it’s raw JSON — not exactly easy to read.

So I built CC Exporter: a Prometheus exporter that reads Claude Code’s local data and exposes it as metrics, with a pre‑built Grafana dashboard for visualization.

Screenshots

Screenshot 1

Screenshot 2

What It Tracks

  • Token usage by model — input, output, cache read, cache creation
  • Real‑time active sessions — live token counts, session count, message count
  • Daily trends — messages, sessions, tool calls, tokens over time
  • Hourly activity — see when you’re most active
  • Tool usage breakdown — which tools (Read, Write, Bash, etc.) you use most
  • Errors & retries — API errors, retries, context compaction events

Quick Start

Full Stack (One Command)

Deploy Exporter + Prometheus + Grafana with a pre‑configured dashboard:

git clone https://github.com/aireet/cc-exporter.git
cd cc-exporter
./start.sh

# Open http://localhost:3000/d/claude-token-monitor — login with admin / admin.

Service URLs:

┌────────────┬───────────────────────────────┐
│  Service   │              URL                │
├────────────┼───────────────────────────────┤
│ Grafana    │ http://localhost:3000          │
├────────────┼───────────────────────────────┤
│ Prometheus │ http://localhost:9099          │
├────────────┼───────────────────────────────┤
│ Exporter   │ http://localhost:9101/metrics  │
└────────────┴───────────────────────────────┘

Exporter Only (Docker Hub)

If you already have Prometheus and Grafana, just run the exporter:

docker run -d --name claude-exporter \
  -p 9101:9101 \
  -v ~/.claude:/data/claude:ro \
  -e CLAUDE_STATS_FILE=/data/claude/stats-cache.json \
  -e CLAUDE_DIR=/data/claude \
  xuexuexue1994/cc-exporter:latest

Add this to your Prometheus config:

scrape_configs:
  - job_name: "claude-exporter"
    static_configs:
      - targets: ["localhost:9101"]

Then import the dashboard JSON from the repository:

https://github.com/aireet/cc-exporter/blob/main/grafana/dashboards/claude-tokens.json

Architecture

~/.claude (read‑only)
    |
    +-- stats-cache.json ──→ ┌────────────┐   ┌────────────┐   ┌─────────┐
    +-- projects/*/?.jsonl → │ Exporter   │──→│ Prometheus │──→│ Grafana │
                              │ (Go, :9101)│   │ (:9099)   │   │ (:3000) │
                              └────────────┘   └────────────┘   └─────────┘
  • Exporter — Go binary that reads stats-cache.json (historical) + scans active JSONL files (real‑time)
  • Prometheus — Scrapes every 30 s, retains 90 days
  • Grafana — Pre‑provisioned datasource and dashboard

Data Safety

  • All Claude data is mounted as read‑only.
  • Everything stays on your machine — nothing is uploaded anywhere.
  • GitHub:
  • Docker Hub:
  • License: MIT
0 views
Back to Blog

Related posts

Read more »

Cast Your Bread Upon the Waters

!Cover image for Cast Your Bread Upon the Watershttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-t...