By li195111
Audit Claude Code session token spending with anomaly detection, cost breakdowns by project/model, usage trend analysis, and actionable optimization suggestions
This skill should be used when the user asks about "anomalies", "problems", "有異常嗎", "哪些會話有問題", "排查", "診斷", or suspects waste or efficiency issues in Claude Code usage. Scans for 6 types of statistical anomalies with severity scoring and automatic drill-down into suspicious sessions. Can also be routed from the main cta skill.
This skill should be used when the user asks about "monthly costs", "cost report", "這個月花多少", "成本報告", "月度審計", "預算", or needs to understand cost distribution by project, model, or time period. Supports cross-month comparison and model cost optimization suggestions. Can also be routed from the main cta skill.
This skill should be used when the user asks for a "quick check", "overview", "how much did I spend", "看看狀況", "總覽", or wants a fast one-page summary of Claude Code token usage and costs. The lightest CTA workflow, completes in under 3 minutes. Can also be routed from the main cta skill.
This skill should be used when the user asks to "analyze this project", "project health check", "分析這個專案", "專案健檢", "subagent efficiency", "tool usage analysis", "工具使用", or needs detailed analysis of a specific project's token usage patterns. Provides four-dimension analysis: cost, efficiency, tools, and architecture. Can also be routed from the main cta skill.
This skill should be used when the user asks about "trends", "usage trends", "趨勢", "用量在漲嗎", "預測", "燃率", "burn rate", or wants to understand whether Claude Code usage is increasing or decreasing over time. Supports daily/weekly/monthly granularity with simple forecasting. Can also be routed from the main cta skill.
Admin access level
Server config contains admin-level keywords
Own this plugin?
Verify ownership to unlock analytics, metadata editing, and a verified badge. GitHub access is read-only (username + org membership).
Sign in to claimOwn this plugin?
Verify ownership to unlock analytics, metadata editing, and a verified badge. GitHub access is read-only (username + org membership).
Sign in to claimBased on adoption, maintenance, documentation, and repository signals. Not a security audit or endorsement.
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 under the plugin data directory in plugin mode and falls back to ~/.claude/ in standalone mode. 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 or ~/.claude/token-analyzer.db |
CTA_PROJECTS_DIR | Session logs directory | ${CLAUDE_CONFIG_DIR}/projects or ~/.claude/projects |
CTA_ARCHIVE_DIR | Archive directory | ${CLAUDE_PLUGIN_ROOT}/data/token-analyzer-archive or ~/.claude/token-analyzer-archive |
CTA_PRICING_PATH | Custom pricing TOML | Embedded in binary |
CLAUDE_CONFIG_DIR | Claude config root for session logs | unset |
Path resolution priority:
$CLAUDE_PLUGIN_ROOT) > standalone mode ($HOME/.claude/)$CLAUDE_CONFIG_DIR/projects) > standalone mode ($HOME/.claude/projects)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 (106 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 .npx claudepluginhub li195111/claude-token-analyzer --plugin claude-token-analyzerhtop for your Claude Code sessions — real-time cost tracking, cache efficiency, model comparison, smart alerts, web dashboard, and session analytics
Session intelligence for Claude Code — find why your sessions fail and fix them
Audit, fix, and monitor Claude Code context window usage. Find the ghost tokens.
Tracks Claude Code session usage (tokens, costs, skills, MCP, subagents) and sends data to a self-hosted dashboard.
Real-time session dashboard for Claude Code — cost tracking, analytics, and smart alerts
OTel + Hooks analytics for Claude Code. Run /init-claudalytics to configure telemetry and hooks capture for this project.