agentleFS
TH3H4RM1N4T0RTH3H4RM1N4T0R/claude-code-cost-monitor/.claude/skills/cost-monitor/SKILL.md

cost-monitor

Skill1 starsChanged 8 months agoMITView on GitHub

Query Claude Code API costs and tool usage from the local OTel stack. Wraps cost-monitor.py — a zero-dependency Python script that queries Prometheus (costs) and Jaeger (per-turn tool breakdown). Claude Code emits OTel metrics to Prometheus via the collector: - claude_code_cost_usage_USD_total — cost per session/model - claude_code_token_usage_tokens_total — tokens per session/model/type The cost command queries these with last_over_time() PromQL. Single HTTP call, instant results, no pagination issues. Fetches trace spans from Jaeger to show per-turn tool usage and cost. Subject…

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. huifer/CloudSaver★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repositoryOne other file it gives its agents.

The file

Files
SKILL.md

Skill: cost-monitor

Query Claude Code API costs and tool usage from the local OTel stack. Wraps cost-monitor.py — a zero-dependency Python script that queries Prometheus (costs) and Jaeger (per-turn tool breakdown).


Entry point

# Check stack health (Prometheus, Jaeger, OTel Collector)
python3 cost-monitor.py status

# Per-session cost breakdown (via Prometheus — fast, reliable)
python3 cost-monitor.py cost
python3 cost-monitor.py cost --lookback 12      # last 12 hours
python3 cost-monitor.py cost --lookback 168     # last 7 days

# Per-turn tool breakdown (via Jaeger — subject to NaN bug on large sessions)
python3 cost-monitor.py turns --lookback 2      # last 2 hours
python3 cost-monitor.py turns --lookback 1      # last 1 hour

Commands

CommandBackendDescription
statusHTTP probesCheck if Prometheus, Jaeger, and Collector are reachable
costPrometheus PromQLPer-session cost + token breakdown, per-model summary
turnsJaeger tracesPer-turn: which tools were called, cost per turn, bash commands

Options

FlagApplies toDefaultDescription
--lookback Ncost, turns24 (cost), all (turns)Hours to look back
--service NAMEcost, turnsclaude-codeOTel service name
--prometheus-urlcost, statushttp://127.0.0.1:9090Prometheus URL
--jaeger-urlturns, statushttp://127.0.0.1:16686Jaeger URL

How it works

Cost (Prometheus path — recommended)

Claude Code emits OTel metrics to Prometheus via the collector:

  • claude_code_cost_usage_USD_total — cost per session/model
  • claude_code_token_usage_tokens_total — tokens per session/model/type

The cost command queries these with last_over_time() PromQL. Single HTTP call, instant results, no pagination issues.

Turns (Jaeger path)

Fetches trace spans from Jaeger to show per-turn tool usage and cost. Subject to the Jaeger BadgerDB NaN bug — the tool auto-retries with smaller page sizes when it hits HTTP 500. Results may be limited during active sessions with large context.


Stack management

# Start the OTel stack
docker-compose up -d

# Stop
docker-compose down

# Configure Claude Code to send telemetry
source setup.sh

Known issues

  • Jaeger NaN bug: Large spans (from long sessions) cause HTTP 500. The turns command handles this by retrying with smaller limits and warning about partial results. The cost command is not affected (uses Prometheus).
  • Collector health: Uses port 13133 for health checks. If the collector shows unreachable but telemetry is flowing, restart: docker-compose restart otel-collector

Retention

  • Prometheus: 60 days
  • Jaeger BadgerDB: 60 days

Running tests

python3 -m pytest -q tests/

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.