/Catalogue/Prompt/hoangsonww/hoangsonww-claude-code-agent-monitor-cost-breakdown

Origin: github

cost-breakdown

Break down Claude Code costs using the Agent Monitor pricing engine. Shows per-model costs (input, output, cache_read, cache_write at $/Mtok rates), per-session costs, daily trends, and compaction baseline token recovery. Use when analyzing spending, comparing model costs, or planning budgets.

by hoangsonww · updated 20h ago · imported from GitHub

Installs0+0/7d
Security score0/100
Retention 14d0%
GitHub stars1K

Skill logic

Execution graph
User message
Prompt rewrites behaviour
Response

SKILL.md

View on GitHub ↗

Cost Breakdown

Detailed cost analysis from the Agent Monitor's pricing engine.

Input

The user provides: $ARGUMENTS

This may be: "today", "this week", "last 30 days", a session ID, or "budget $50/week".

Data Sources

EndpointReturns
GET /api/pricing{ pricing: [{ model_pattern, display_name, input_per_mtok, output_per_mtok, cache_read_per_mtok, cache_write_per_mtok }] }
GET /api/pricing/costTotal cost: { total_cost, breakdown: [{ model, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, cost, matched_rule }] }
GET /api/pricing/cost/{sessionId}Per-session cost with same breakdown shape
GET /api/sessions?limit=200Sessions list — each includes inline cost field (bulk pricing)
GET /api/analyticsToken totals (total_input, total_output, total_cache_read, total_cache_write — baselines pre-summed), daily trends

How costs are calculated

The pricing engine matches model names against model_pattern using SQL LIKE (e.g. claude-sonnet-4-5% matches claude-sonnet-4-5-20250514). Longest pattern wins for specificity. Cost per model:

cost = (input_tokens / 1M) × input_per_mtok
     + (output_tokens / 1M) × output_per_mtok
     + (cache_read_tokens / 1M) × cache_read_per_mtok
     + (cache_write_tokens / 1M) × cache_write_per_mtok

Token counts are effective totals = current + baseline (baselines preserve pre-compaction tokens that would otherwise be lost when the transcript JSONL is rewritten).

Default pricing tiers (seeded on first run)

FamilyInput $/MtokOutput $/MtokCache Read $/MtokCache Write $/Mtok
Opus 4.5/4.6$5$25$0.50$6.25
Sonnet 4/4.5/4.6$3$15$0.30$3.75
Haiku 4.5$1$5$0.10$1.25

Report Sections

1. Cost by Model

Table from /api/pricing/cost breakdown — each model with 4 token counts + cost. Highlight which pricing rule matched.

2. Cost by Session (Top 10 Most Expensive)

From sessions list with inline cost — sort descending. Show session name, model, duration, cost.

3. Daily Cost Trend

Cross-reference daily_sessions with per-session costs to compute daily spend. Show 7/30-day trend with direction arrows.

4. Token Efficiency Analysis

  • Cache hit rate: total_cache_read / (total_cache_read + total_input) × 100 — higher = more efficient
  • Compaction baseline recovery: Tokens preserved via baseline columns (tokens not lost to compaction)
  • Output/input ratio: Balanced ratio indicates good prompt efficiency

5. Cost Optimization Opportunities

  • Sessions where cache_write >> cache_read (poor cache reuse)
  • Expensive models used for simple tasks (check subagent_type vs model)
  • Sessions with many compactions (context overflow = wasted tokens)

Output

Structured Markdown with tables. Currency as USD to 4 decimal places. Include total and per-model subtotals.

Discussion

No comments yet — start the thread.

Sign in to join the discussion.

/More from hoangsonww/Claude-Code-Agent-Monitor

hoangsonww· 20h agoSandbox
config-audit

Prompts · TypeScript · v0.1.0

Run a full audit of the user's Claude Code configuration via the Agent Monitor Config Explorer API: counts per surface (user vs project), duplicate or overlapping skills and subagents, hooks that run shell commands, and which surfaces are read-only vs mutable. Reads /api/cc-config/overview, /skills, /agents, /commands, /hooks, and /settings. Use when reviewing your Claude Code setup for sprawl, duplication, or risk.

#ai-agents#claude-agents#claude-code

0 1K
hoangsonww· 20h agoSandbox
hook-inventory

Prompts · TypeScript · v0.1.0

Inventory hooks across the user, project, and project-local settings plus the ~/.claude/hooks scripts directory — read through the Agent Monitor Config Explorer API — and flag hooks that POST to the network or run arbitrary commands. Reads /api/cc-config/hooks and /api/cc-config/hook-scripts. Use when auditing hook safety.

#ai-agents#claude-agents#claude-code

0 1K
hoangsonww· 20h agoSandbox
mcp-audit

Prompts · TypeScript · v0.1.0

Audit the configured MCP servers (user + project scope) via the Agent Monitor Config Explorer API: transport (stdio vs http), command/args and env variable names, headers, and the source file each definition came from. Reads /api/cc-config/mcp. Use when reviewing MCP integrations for hygiene, duplication, or unexpected transports.

#ai-agents#claude-agents#claude-code

0 1K
hoangsonww· 20h agoSandbox
memory-review

Prompts · TypeScript · v0.1.0

Review the file-based memory store via the Agent Monitor Config Explorer API: the user and project CLAUDE.md plus per-project auto-memory files under ~/.claude/projects/<slug>/memory/*.md. Groups by project, shows the index (MEMORY.md) vs per-fact files, and flags stale or oversized facts. Reads /api/cc-config/memory and /api/cc-config/file?path=. Use when curating agent memory.

#ai-agents#claude-agents#claude-code

0 1K