Analyze Claude Code costs by model
cost-breakdownskillsetup L2★364
hoangsonww/Claude-Code-Agent-Monitor ↗What it does
Calculate detailed cost breakdown from Claude Code Agent Monitor
Best for
Weekly or monthly cost review when you want to understand spending by model and identify high-cost sessions for optimization.
Inputs
- · Time period: 'today', 'this week', 'last 30 days'
- · Optional: session ID for per-session cost
- · Optional: budget constraint (e.g., 'budget $50/week')
Outputs
- · Cost by model table (input, output, cache_read, cache_write tokens + cost)
- · Cost by session (top 10 most expensive)
- · Daily cost trend (7 or 30-day)
- · Token efficiency metrics (cache hit rate, compaction baseline recovery, output/input ratio)
- · Cost optimization recommendations
Requires
- · Agent Monitor API: /api/pricing, /api/pricing/cost, /api/pricing/cost/{sessionId}, /api/sessions, /api/analytics
Preconditions
- · Agent Monitor must be running (GET /api/health returns 200)
- · Pricing rules must be seeded (default: Opus/Sonnet/Haiku tiers)
Failure modes
- · Fails if Monitor API unreachable (must run 'npm start' in project dir)
- · Pricing rules can be customized but default tiers may not match actual rates
- · Session cost calculation depends on baselines — old sessions without baseline data show underestimated cost
- · Cache efficiency metric only meaningful if cache_write > 0
Trust signals
- · Four-endpoint API design (pricing rules, total cost, per-session cost, session list with inline cost)
- · Cost calculation formula explicitly shown: (input_tokens/1M) × input_per_mtok + ...
- · Longest model_pattern wins for specificity (e.g., claude-sonnet-4-5% matches exact version)
- · Baseline token preservation: old sessions' pre-compaction tokens tracked in baselines column
- · Default pricing tiers seeded for Opus/Sonnet/Haiku with input/output/cache-read/cache-write rates