Install
$ agentstack add mcp-ymstar-agentmeter β scanned Β· β verified, works with Claude Code, Cursor, and more.
Security review
β PassedNo issues found. Passed automated security review. Β· v0.1.0 How review works β
- β Prompt-injection patterns
- β Secret / credential exfiltration
- β Dangerous shell & filesystem operations
- β Untrusted network calls
- β Known-malicious package signatures
What it can access
- β Network access No
- β Filesystem access No
- β Shell / process execution No
- β Environment & secrets No
- β Dynamic code execution No
From automated source analysis of v0.1.0. βUsedβ means the capability is present in the source β more access means more to trust, not that itβs unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work βAbout
Open-source token usage & cost tracking CLI for AI coding agents. Automatically monitor Claude Code token consumption, cache hit rates, and API costs. Beautiful dashboard β’ Budget alerts β’ Multi-model pricing β’ Local-first SQLite storage.
Why AgentMeter?
| Feature | AgentMeter | Manual Tracking | API Dashboard | |---------|-----------|----------------|---------------| | Automatic tool-call tracking | β | β | β | | Cache hit rate monitoring | β | β | β | | Per-session & per-tool breakdown | β | β | β οΈ | | Multi-model pricing (Claude, GPT, Gemini, DeepSeek) | β | β | β | | Budget alerts & spending limits | β | β | β οΈ | | Local-first (no cloud dependency) | β | β | β | | Beautiful web dashboard | β | β | β | | Zero config setup | β | β | β | | CSV/JSON export | β | β | β οΈ |
AgentMeter hooks into Claude Code's PostToolUse event β every tool call is automatically captured with token usage, model info, cache stats, and estimated cost. No manual logging, no API polling, no cloud services.
Quick Start
# One command to set up
npx @ymstar/agentmeter init
# Launch dashboard
npx @ymstar/agentmeter dashboard
That's it. AgentMeter will automatically track all tool calls in the background.
Features
- 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
Commands
| 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
agentmeter dashboard # default port 3940
agentmeter dashboard --port 8080
The 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
agentmeter export # CSV to stdout, last 30 days
agentmeter export -f json -o data.json # JSON to file
agentmeter export -d 7 # Last 7 days
agentmeter budget
agentmeter budget
Shows daily and monthly spending against configured limits.
agentmeter reset
agentmeter reset # prompts for confirmation
agentmeter reset --force # skip confirmation
Configuration
AgentMeter 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
}
How It Works
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
Model Detection
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
Cache Token Tracking
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)
Model Pricing
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.
Supported Agents
- Claude Code β fully supported via
PostToolUsehook - Cursor / Gemini CLI / others β not yet supported, contributions welcome
Development
git clone https://github.com/ymstar/agentmeter.git
cd agentmeter
npm install
npm run build
npm test
No linter configured β CI type-checks with npx tsc --noEmit on Node 20 and 22.
License
[MIT](LICENSE)
Use Cases Claude Code cost tracking β’ AI agent token monitoring β’ LLM API budget management β’ Developer productivity analytics β’ Multi-model usage comparison β’ Prompt caching optimization
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source β we do not rehost the code.
- Author: ymstar
- Source: ymstar/agentmeter
- License: MIT
- Homepage: https://www.npmjs.com/package/@ymstar/agentmeter
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.