agentleFS
YadavSanjayYadavSanjay/ClaudeConfig-Public/skills/cost-report/SKILL.md

cost-report

Skill1 starsChanged 12 days agoMITView on GitHub

Report Claude Code token usage, API-equivalent cost and plan-limit usage from a local ledger built from session transcripts: per session, per subagent (with the nested agent tree), per subagent type, model × effort, day, skill, project, cache behaviour, subagent fan-out, recorded 5-hour/weekly limit snapshots, and reconciliation against Claude Code's own cost figure. Use when asked what something cost, how many tokens a session or subagent used, where spend goes, how close the plan limits are, which skills or agents are expensive, or about cache efficiency; or by name (/cost-report). Numbers come only from the scripts; never estimate them.

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use one fixed Python 3.12 interpreter, written <python> below, and never a bare python: on Windows it may be a Store stub.

    line 20
  2. Distinctive:

    Add two or three observations taken from the numbers, for example the top cost driver, the subagent share, or the cache-write cost after …

    line 47
  3. Distinctive:

    Do not compute, extrapolate or round figures beyond what the JSON contains.

    line 58
  4. Very specific:

    The hooks: always exit 0 and print nothing.

    line 95
  5. Very specific:

    If --level limits stays empty,: read cost/statusline-last.json.

    line 100

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

cost-report: usage, cost and limits

Args: [level] [window] [--session ID] [--project NAME]. Defaults: session, last 7 days. Design and decisions: design.md.

Run

Use one fixed Python 3.12 interpreter, written <python> below, and never a bare python: on Windows it may be a Store stub. From PowerShell:

& "<python>" "$env:CLAUDE_CONFIG_DIR/skills/cost-report/scripts/rollup.py" --level <level> --since <window> --format json
  1. Pick the level from the question.

    QuestionLevel
    Most expensive sessions; main vs subagent splitsession
    One session, broken down by agenttree --session <id prefix>
    Which subagent types cost mostagent-type
    What each model × effort costsmodel-effort
    Spend over timeday
    Cost per skillskill
    Cost per repoproject
    Cache efficiency; idle-gap rewritescache
    How much fan-out costsfanout
    How close the 5-hour/weekly limits arelimits
    Does the ledger match Claude Codereconcile

    Window: --since 24h|7d|2w|YYYY-MM-DD|all.

  2. Run the script. It first ingests new transcript lines, then prints JSON.
  3. Present the result.
    • Show a compact table of rows (and any sections).
    • Add two or three observations taken from the numbers, for example the top cost driver, the subagent share, or the cache-write cost after idle gaps.
  4. Always state the cost basis. Figures are API list prices. On a Pro/Max subscription they are an API-equivalent comparison, not a bill. The plan's real limits are the 5-hour and weekly percentages in limits.
  5. Repeat every warning in totals:
    • incomplete_output (cost is a lower bound);
    • unpriced / unpriced_models;
    • assumed_price_models;
    • anomalies_ledger_wide.

Do not compute, extrapolate or round figures beyond what the JSON contains. If the script fails, report its error output as it is.

Other commands:

$py = "<python>"; $s = "$env:CLAUDE_CONFIG_DIR/skills/cost-report/scripts"
& $py "$s/ingest.py" scan            # incremental ingest of every transcript
& $py "$s/ingest.py" scan --full     # re-read everything (idempotent)
& $py "$s/rollup.py" --level day --since 2w      # table output for a human

The ledger is $CLAUDE_CONFIG_DIR/cost/ledger.db; override it with $COST_LEDGER_DB. It's local runtime data, ignored by git, and holds no prompt or response text.

Setup (once per machine)

  1. Backfill: & $py "$s/ingest.py" scan.
  2. Retention: settings.json sets "cleanupPeriodDays": 365, so transcripts outlive the default 30 days.
  3. Hooks and status line. Merge this into settings.json, with <python> and <config> as absolute paths (settings.example.json has the same block).

    "hooks": {
      "SessionStart": [{ "hooks": [{ "type": "command", "timeout": 60,
        "command": "<python> <config>/skills/cost-report/scripts/ingest.py hook --scan" }]}],
      "SessionEnd": [{ "hooks": [{ "type": "command", "timeout": 30,
        "command": "<python> <config>/skills/cost-report/scripts/ingest.py hook" }]}]
    },
    "statusLine": { "type": "command",
      "command": "<python> <config>/skills/cost-report/scripts/statusline.py" }
    • Shell-neutral commands. Absolute paths with no spaces need no quotes and no PowerShell &, so the same command works whether Claude Code runs it through PowerShell, Git Bash or cmd. Hooks run through PowerShell on this machine; the status line's shell is unconfirmed.
    • The hooks always exit 0 and print nothing; errors go to cost/errors.log.
    • The status line shows [model] · 5h 34% (Sat 14:00) · wk 61% (Mon 09:00) · session $2.10 API-eq. It records each change in a limit to the ledger, which feeds --level limits.
    • The paths are machine-specific, like the Node path in CLAUDE.md.

    If --level limits stays empty, read cost/statusline-last.json. The status line rewrites it on every refresh, with key names only (no values).

    • The file is missing: Claude Code never ran the command. Check the statusLine block and restart the session.
    • error is "empty stdin": the command ran but got no input. The status line also shows [cost-report: empty stdin] in that case.
    • rate_limits is null but has_cost is true: Claude Code isn't sending plan limits for this account. Subscription limits then have to be estimated (design.md section 7).

Known limits

  • Subagent output is under-counted. Subagent transcripts often miss the final output count. Each subagent's last request is restored from the parent's tool result; the rest stay flagged as incomplete.
  • Background calls are missing. Title generation and similar calls never appear in transcripts. reconcile shows them as the unattributed gap, where Claude Code wrote its own figure.
  • Subscription limits are shared. They are also consumed by claude.ai and other devices, so usd_per_pct in limits is an upper-bound estimate.

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.