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
## 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:
bash
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 │ URL │
├────────────┼───────────────────────────────┤
│ Grafana │ http://localhost:3000 │
├────────────┼───────────────────────────────┤
│ Prometheus │ http://localhost:9099 │
├────────────┼───────────────────────────────┤
│ Exporter │ http://localhost:9101/metrics │
└────────────┴───────────────────────────────┘
Exporter Only (Docker Hub)
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
Then add this to your Prometheus config:
scrape_configs:
- job_name: "claude-exporter"
static_configs:
- targets: ["localhost:9101"]
And https://github.com/aireet/cc-exporter/blob/main/grafana/dashboards/claude-tokens.json into Grafana.
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 30s, 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
Links
- GitHub: https://github.com/aireet/cc-exporter
- Docker Hub: https://hub.docker.com/r/xuexuexue1994/cc-exporter
- License: MIT


Top comments (0)