Claude Code Usage Audit (token-audit)
A comprehensive picture of Claude Code usage in this container, built from
the local session transcripts in ~/.claude/projects/**/*.jsonl (each
assistant message records its token usage, tool calls, model, and metadata).
This covers ALL Claude Code activity — interactive, subagents, hooks, MCP,
web tools — and answers two questions: where is my usage going? and is any
of it runaway automation?
Engine adapted (MIT) from pacphi/agentic-kit's ruflo-token-audit; see the
attribution header in the script. Stdlib-only Python, no network, no extra
dependencies.
When to use
Trigger on: "where are my tokens/usage going", "why is my usage so high",
"break down my Claude Code activity", "I'm hitting my Max/Pro limit", "what am
I spending tokens on", "audit token usage". Also proactively if the user
mentions surprising usage.
Procedure
Run the engine (baked at the skills tree; stdlib-only Python 3):
token-audit --days 7
- Honour any window the user gives ("past month" →
--days 30).
--top N widens each section; --json gives machine-readable output;
--no-daemons skips the ps cross-reference.
Read the whole picture, then lead with the headline. Synthesize, don't
echo. Key sections and what they tell you:
| Section |
Read it for |
| BY MODEL |
Opus/Fable = interactive; heavy Haiku/Sonnet = automation/subagents |
| SESSIONS PER DAY |
tens = human; hundreds–thousands = automation (≈one/min = robotic) |
| ACTIVITY BY HOUR |
a flat 24h histogram (busy at 3am) is automation, not a person |
| TOOL USAGE |
what the work actually is (Bash/Read/Edit vs Task/MCP) |
| MCP USAGE |
per-server call volume; heavy MCP also means a per-session tool-def tax |
| SUBAGENT FAN-OUT |
Task spawns + sidechain share — how much is delegated/parallel |
| BUSIEST SESSIONS |
a single runaway conversation surfaces here by token total |
| CACHE EFFICIENCY |
high cache-read% is normal/cheap; flag only with huge automated volume |
| STARTUP CONTEXT TAX |
fixed per-session cost (CLAUDE.md + tool/skill manifests) × many sessions |
| RUNNING DAEMONS |
live ruflo daemon start processes mapped to top-burn projects |
Check the daemon cross-reference (the classic leak upstream: six leaked
daemons produced ~8.1B tokens in a week, ~94% background). In agentbox,
ruflo AI workers are pinned off (RUFLO_DAEMON_AI_WORKERS=0 in the runtime
env) and no ruflo daemon runs under supervisord — so ANY daemon in this
section is unexpected. If daemons are listed and the user authorises:
ruflo-daemon-gc # preview
ruflo-daemon-gc --kill # stop them
Then re-run the audit to confirm.
Report like a diagnosis, not a data dump. Lead with the verdict (where
usage is going + interactive vs automation + the single biggest driver).
Then a small supporting table, then ranked concrete fixes with exact
commands. Levers worth naming: kill runaway daemons; trim an oversized
CLAUDE.md; drop or gate a heavy always-on MCP (its tool defs are a
per-session tax); reduce hook/loop fan-out.
Caveats (be honest)
- The cost-weight is an Opus-equivalent reference to compare line items —
NOT the user's actual plan billing. Don't present it as dollars owed.
- High cache-read is normal and cheap; flag it only when it's huge and
multiplied by thousands of automated sessions.
- A few hundred sessions (or Task spawns) from legitimate parallel subagent
work is not a leak. The tell is unattended, repeating activity — flat
overnight hours, near-identical session counts across projects, daemons
running.
- Consultant-tier calls (codex/zai/perplexity/deepseek MCP servers) are logged
separately under
/var/lib/agentbox/consultations/*.jsonl — this audit sees
their MCP call counts, not their provider-side token spend.
Sample prompts
- "Audit my Claude Code usage for the last 7 days — where is it all going?"
- "Break down what I've been spending tokens on this week."
- "I'm hitting my Max limit in a day. Run the usage audit and tell me why."
- "Check for runaway ruflo daemons and show me my heaviest sessions."
1---2name: token-audit3description: Use when the user asks where their Claude Code usage/tokens are going, is burning through their plan unexpectedly fast, hitting limits, or wants a breakdown of Claude Code activity. Produces a COMPREHENSIVE usage report from local session transcripts: tokens by day/model/project, tool usage, MCP usage, subagent fan-out, web-tool calls, cache efficiency, busiest sessions, hourly activity, and a runaway-daemon cross-reference — distinguishing interactive work from automation and recommending concrete fixes.4---56# Claude Code Usage Audit (token-audit)78A **comprehensive** picture of Claude Code usage in this container, built from9the local session transcripts in `~/.claude/projects/**/*.jsonl` (each10assistant message records its token usage, tool calls, model, and metadata).11This covers ALL Claude Code activity — interactive, subagents, hooks, MCP,12web tools — and answers two questions: *where is my usage going?* and *is any13of it runaway automation?*1415Engine adapted (MIT) from pacphi/agentic-kit's `ruflo-token-audit`; see the16attribution header in the script. Stdlib-only Python, no network, no extra17dependencies.1819## When to use2021Trigger on: "where are my tokens/usage going", "why is my usage so high",22"break down my Claude Code activity", "I'm hitting my Max/Pro limit", "what am23I spending tokens on", "audit token usage". Also proactively if the user24mentions surprising usage.2526## Procedure27281. **Run the engine** (baked at the skills tree; stdlib-only Python 3):2930 ```bash31 token-audit --days 732 ```3334 - Honour any window the user gives ("past month" → `--days 30`).35 - `--top N` widens each section; `--json` gives machine-readable output;36 `--no-daemons` skips the `ps` cross-reference.37382. **Read the whole picture, then lead with the headline.** Synthesize, don't39 echo. Key sections and what they tell you:4041 | Section | Read it for |42 |---|---|43 | BY MODEL | Opus/Fable = interactive; heavy Haiku/Sonnet = automation/subagents |44 | SESSIONS PER DAY | tens = human; hundreds–thousands = automation (≈one/min = robotic) |45 | ACTIVITY BY HOUR | a flat 24h histogram (busy at 3am) is automation, not a person |46 | TOOL USAGE | what the work actually *is* (Bash/Read/Edit vs Task/MCP) |47 | MCP USAGE | per-server call volume; heavy MCP also means a per-session tool-def tax |48 | SUBAGENT FAN-OUT | Task spawns + sidechain share — how much is delegated/parallel |49 | BUSIEST SESSIONS | a single runaway conversation surfaces here by token total |50 | CACHE EFFICIENCY | high cache-read% is normal/cheap; flag only with huge automated volume |51 | STARTUP CONTEXT TAX | fixed per-session cost (CLAUDE.md + tool/skill manifests) × many sessions |52 | RUNNING DAEMONS | live ruflo `daemon start` processes mapped to top-burn projects |53543. **Check the daemon cross-reference** (the classic leak upstream: six leaked55 daemons produced ~8.1B tokens in a week, ~94% background). In agentbox,56 ruflo AI workers are pinned off (`RUFLO_DAEMON_AI_WORKERS=0` in the runtime57 env) and no ruflo daemon runs under supervisord — so ANY daemon in this58 section is unexpected. If daemons are listed and the user authorises:5960 ```bash61 ruflo-daemon-gc # preview62 ruflo-daemon-gc --kill # stop them63 ```6465 Then re-run the audit to confirm.66674. **Report like a diagnosis, not a data dump.** Lead with the verdict (where68 usage is going + interactive vs automation + the single biggest driver).69 Then a small supporting table, then ranked concrete fixes with exact70 commands. Levers worth naming: kill runaway daemons; trim an oversized71 CLAUDE.md; drop or gate a heavy always-on MCP (its tool defs are a72 per-session tax); reduce hook/loop fan-out.7374## Caveats (be honest)7576- The cost-weight is an **Opus-equivalent reference** to compare line items —77 NOT the user's actual plan billing. Don't present it as dollars owed.78- High **cache-read** is normal and cheap; flag it only when it's huge *and*79 multiplied by thousands of automated sessions.80- A few hundred sessions (or Task spawns) from legitimate parallel subagent81 work is not a leak. The tell is *unattended, repeating* activity — flat82 overnight hours, near-identical session counts across projects, daemons83 running.84- Consultant-tier calls (codex/zai/perplexity/deepseek MCP servers) are logged85 separately under `/var/lib/agentbox/consultations/*.jsonl` — this audit sees86 their MCP *call counts*, not their provider-side token spend.8788## Sample prompts8990- "Audit my Claude Code usage for the last 7 days — where is it all going?"91- "Break down what I've been spending tokens on this week."92- "I'm hitting my Max limit in a day. Run the usage audit and tell me why."93- "Check for runaway ruflo daemons and show me my heaviest sessions."