cc-metrics
Local metrics pipeline for Claude Code and OpenAI Codex CLI:
Claude Code ─┐
├─ OTLP ─> OpenTelemetry Collector ─> Prometheus ─> Grafana
Codex CLI ───┘
Runs entirely on your machine. Published ports bind to 127.0.0.1 by default.
Client authentication stays in Claude Code or Codex; this stack needs no
provider API key.
Dashboard
One Grafana dashboard, "Token & Usage Monitor", provisioned automatically. Five
rows:
| row | what it answers |
|---|
| Overview | session starts, tokens, estimated cost, Codex threads, active time, cache hit rate |
| Token Usage | tokens over time, split by type, model, and Claude effort level |
| Cost Analysis | estimated cost over time and by model, across both vendors |
| Agents | tokens and estimated cost for Claude traffic carrying a named agent |
| Sessions & Productivity | commits, pull requests, lines changed, edit decisions |
Cost split by model across both vendors is the reason this exists rather than
either vendor's own view. Claude figures are the provider's own estimates;
Codex figures are list-price estimates computed here — see
Cost meaning for what that difference implies.
Overview headline tiles:
Token usage over the selected range, split by token type:
The Codex side of the cost split, priced from the list-price rules:
Named-agent attribution — the share of Claude tokens carrying an agent name,
and its split by agent type:
Every panel is empty until a client sends data. Setup steps 3 and 4 do that.
Features
- Claude Code and Codex token views under one
ai_* metric namespace.
- Provider-emitted Claude cost estimates.
- Standard OpenAI API list-price estimates for selected Codex models.
- Configurable host ports, environment label, retention, and image references.
- Optional, forward-looking Codex commit counter.
- Prometheus rule, dashboard contract, hook, pricing, and hygiene tests.
Requirements
| Component | Supported requirement |
|---|
| Host | macOS or Ubuntu only |
| Containers | Docker with docker compose |
| Claude Code | 2.1.214 or newer for corrected streaming token/cost accounting |
| Codex CLI | 0.145.0 or newer for GPT-5.6 cache-write telemetry |
| Python | 3.10 or newer for hook installation, pricing maintenance, and tests |
| Git | Needed for cloning and the optional commit metric |
| Password g | |