Claude Code token usage analysis: costs, trends, anomalies, and optimization
npx claudepluginhub li195111/claude-token-analyzerAnalyze Claude Code session token usage, costs, trends, and anomalies
Share bugs, ideas, or general feedback.
Your Claude Code sessions might be burning tokens you can't see. Diagnoses where your tokens go, why they're wasted, and what to fix first.
Fully local — parses your ~/.claude JSONL files into SQLite. Nothing leaves your machine. No cloud. No telemetry.
# Install (binary auto-downloads, no Rust toolchain needed)
claude plugin install claude-token-analyzer
Then just ask in any Claude Code session:
> cta
> how much did I spend this month?
> scan for anomalies
> analyze this project
> show me usage trends
~/.claude/projects/**/*.jsonl Your session logs (never modified)
→ parser.rs Extract + deduplicate responses
→ analyzer.rs Cost calculation, 10-dimension metrics
→ storage.rs Upsert into local SQLite
→ detector.rs 6-type anomaly detection + severity scoring
→ MCP tools / Skills You ask, it answers
All processing happens locally. The SQLite database lives in the plugin directory. No network calls, no external dependencies at runtime.
| Skill | Trigger Phrases | What It Does |
|---|---|---|
cta | "cta", "analyze tokens" | Routes to the right sub-skill |
cta-health-check | "quick check", "overview", "看看狀況" | One-page usage summary |
cta-cost-audit | "monthly costs", "cost report", "這個月花多少" | Monthly cost breakdown with model split |
cta-anomaly-hunt | "anomalies", "problems", "有異常嗎" | Statistical anomaly scan with drill-down |
cta-project-review | "analyze project", "專案健檢" | Four-dimension project analysis |
cta-trend-watch | "trends", "burn rate", "趨勢" | Usage trend analysis with forecasting |
| Tool | Purpose |
|---|---|
sync_db | Sync JSONL session logs to SQLite |
analyze_session | 10-dimension session analysis |
analyze_project | Project-level aggregation with sorting |
analyze_global | Cross-project panoramic view |
cost_report | Monthly cost report (daily granularity available) |
anomaly_scan | 6-type anomaly detection with severity scoring |
trend_report | Time-series trends (daily/weekly/monthly) |
Environment variables (all optional):
| Variable | Purpose | Default |
|---|---|---|
CTA_DB_PATH | SQLite database location | ${CLAUDE_PLUGIN_ROOT}/data/token-analyzer.db |
CTA_PROJECTS_DIR | Session logs directory | ~/.claude/projects |
CTA_ARCHIVE_DIR | Archive directory | ~/.claude/token-analyzer-archive |
CTA_PRICING_PATH | Custom pricing TOML | Embedded in binary |
Path resolution priority: Environment variable > Plugin mode ($CLAUDE_PLUGIN_ROOT) > Standalone mode ($HOME/.claude/)
git clone https://github.com/li195111/claude-token-analyzer.git
cd claude-token-analyzer
bash scripts/build.sh
# Binary: mcp-server/target/release/cta-mcp-server
# Run tests (98 tests)
cargo test --all-targets --manifest-path mcp-server/Cargo.toml
# Lint
cargo clippy --manifest-path mcp-server/Cargo.toml -- -D warnings
# Launch with plugin loaded
claude --plugin-dir .
Requires: Rust toolchain
Issues and PRs welcome! See open issues for starter tasks.
Development setup:
bash scripts/build.shcargo test --all-targets --manifest-path mcp-server/Cargo.toml to verifyclaude --plugin-dir .Rust toolchain required. The project uses cargo clippy -- -D warnings for linting.
MIT
你的 Claude Code 會話可能正在浪費你看不見的 token。 診斷 token 流向、浪費原因,並告訴你該優先修正什麼。
全本地運行 — 解析 ~/.claude JSONL 檔案到 SQLite。資料不離開你的機器。無雲端、無遙測。