# One command to set up
npx @ymstar/agentmeter init
# Launch dashboard
npx @ymstar/agentmeter dashboardThat's it. AgentMeter will automatically track all tool calls in the background.
- Zero Config — One
initcommand sets up Claude Code hooks - Auto Tracking — Captures every tool call automatically
- Beautiful Dashboard — Dark-themed web UI with charts and sparklines
- Multi-View — Analyze by tool, session, model, or agent type
- Cache Hit Tracking — Shows cache hit/miss rate per call and in aggregate
- Multi-Model Pricing — Built-in pricing for Claude, GPT, Gemini, DeepSeek, MiMo, GLM
- Effort Tracking — Records effort level (high/medium/low) per call
- Budget Alerts — Set spending limits and get warnings
- Token Estimation — Smart 3-layer token counting (parse → estimate → fallback)
- CJK Aware — Accurate token estimation for Chinese/Japanese/Korean text
- Data Export — Export to CSV or JSON
- Local Storage — All data stored locally in SQLite
| Command | Description |
|---|---|
agentmeter init |
Configure Claude Code hooks (one-time) |
agentmeter dashboard |
Launch web dashboard |
agentmeter stats |
Show stats in terminal |
agentmeter budget |
Check budget status and warnings |
agentmeter export |
Export data to CSV or JSON |
agentmeter reset |
Clear all recorded data and start fresh |
agentmeter dashboard # default port 3940
agentmeter dashboard --port 8080The dashboard shows:
- Today / Week / Month token usage cards with sparklines
- Cache Hit Rate card with hit/miss breakdown
- Token consumption trend chart (7 / 30 / 90 days) with cache read overlay
- Cost by model doughnut chart
- Top tools by token usage doughnut chart
- Hourly activity bar chart
- By Tool — Statistics grouped by tool name
- By Session — Statistics grouped by Claude Code session
- By Model — Statistics grouped by LLM model
- By Agent — Statistics grouped by agent type
- Recent Calls — Each call shows model, effort level, cache hit rate, and cost
agentmeter export # CSV to stdout, last 30 days
agentmeter export -f json -o data.json # JSON to file
agentmeter export -d 7 # Last 7 daysagentmeter budgetShows daily and monthly spending against configured limits.
agentmeter reset # prompts for confirmation
agentmeter reset --force # skip confirmationAgentMeter stores config at ~/.agentmeter/config.json:
{
"daily_limit_usd": 10,
"monthly_limit_usd": 100,
"daily_limit_tokens": 5000000,
"monthly_limit_tokens": 50000000,
"warn_at_percent": 80
}agentmeter initadds aPostToolUsehook to~/.claude/settings.json- Every time Claude Code uses a tool, the hook fires and captures the call
- AgentMeter parses token usage, detects model & agent type, estimates cost
- Data is stored in
~/.agentmeter/meter.db(SQLite) - View stats via
agentmeter dashboardoragentmeter stats
AgentMeter auto-detects the model from Claude Code's environment:
- Hook input field → 2. Environment variables (
ANTHROPIC_MODEL,CLAUDE_MODEL,OPENAI_MODEL) → 3.~/.claude/settings.json→ 4. Default to Claude Sonnet
Agent type detection (identifies Claude Code):
CLAUDECODEenv var → 2.CLAUDE_CODE_SESSION_IDenv var → 3. Session ID format → 4.~/.claudedirectory → 5. Model name pattern
When Claude Code uses prompt caching, the API returns cache_creation_input_tokens and cache_read_input_tokens. AgentMeter captures these and calculates:
- Cache Hit Rate — percentage of input tokens served from cache
- Cache-aware cost — cache reads are cheaper (e.g., Claude: 0.1x input price)
Built-in per-1M-token pricing (input / output / cache read / cache write):
| Model Family | Models | Input | Output |
|---|---|---|---|
| Claude | Opus 4, Sonnet 4, 3.5 Sonnet, 3.5 Haiku, 3 Opus | $0.8–$15 | $4–$75 |
| GPT | 4o, 4o-mini, 4-turbo, 3.5-turbo | $0.15–$10 | $0.6–$30 |
| Gemini | 2.5 Pro, 2.5 Flash, 2.0 Flash | $0.1–$1.25 | $0.4–$10 |
| DeepSeek | v4-flash, v4-pro, v3.2, r1 | $0.14–$1.74 | $0.28–$3.48 |
| MiMo | v2.5-pro, v2.5, v2-flash | $0.1–$1 | $0.3–$3 |
| GLM | 5.1, 5, 4.7, 4.7-flash, 4.5-air | $0.06–$1.2 | $0.4–$4 |
Unknown models default to Claude Sonnet pricing.
- Claude Code — fully supported via
PostToolUsehook - Cursor / Gemini CLI / others — not yet supported, contributions welcome
git clone https://github.com/ymstar/agentmeter.git
cd agentmeter
npm install
npm run build
npm testNo linter configured — CI type-checks with npx tsc --noEmit on Node 20 and 22.