Report where Claude Code token spend goes, for main sessions and subagents separately — totals, spend by agent type, per-day trend, the costliest projects and sessions, concentration, turn shape, cold cache, what fills the context, the fixed start every context pays, and whether the plugin's rules are holding. Use when asked where tokens/usage went, why Claude Code usage or cost is high, which session or project cost the most, how much a subagent or agent type is spending, what a session or s...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Agent Cost?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/agulhas-labs-agent-cost)
---
name: agent-cost
description: >-
Report where Claude Code token spend goes, for main sessions and subagents separately — totals, spend by
agent type, per-day trend, the costliest projects and sessions, concentration, turn shape, cold cache,
what fills the context, the fixed start every context pays, and whether the plugin's rules are holding.
Use when asked where tokens/usage went, why Claude Code usage or cost is high, which session or project
cost the most, how much a subagent or agent type is spending, what a session or subagent starts with
(instructions, deferred tools, skill listing), or to compare spend before/after a change.
---
# agent-cost
Run the report script in this skill's folder rather than analysing transcripts by hand or writing a
new script — it already parses the (undocumented, versioned) transcript format correctly: turn
deduplication by `message.id` (a later duplicate line carries the *more complete* `output_tokens`, not
the first), the window-vs-mtime prefilter, and the pricing formula below.
```
python3 "${CLAUDE_SKILL_DIR}/scripts/agent_cost.py" [--since X] [--until X] [--projects DIR]
[--project NAME] [--transcript PATH...] [--top N] [--tools] [--sections NAMES] [--rows]
```
- The script needs Python 3 and the standard library only; without `python3` the shell fails with exit 127.
Where `python3` is missing or a placeholder (often on Windows), run the same line with `py` or `python`.
- `--since`/`--until` accept `today`, `yesterday`, `<N>d`, `<N>h`, `<N>m`, `YYYY-MM-DD`, or an ISO datetime
(`2026-09-15T16:06`, local unless it carries `Z`/an offset). Default: last 7 days.
- To compare spend **before/after a change**, run it twice with `--since`/`--until` datetimes that
bracket each side of the change (e.g. the commit time), not two separate loose windows.
- `--tools` adds a section listing the tools each agent type actually called, with counts. It is the
evidence for an agent definition's `tools:`/`disallowedTools:` line: a tool a type never calls is
context re-sent on every one of its turns, and a tool its jobs need but its list drops is a failure.
- `--project NAME` reports on one project: its path, or the path's trailing part (`App`,
`work/App`). `--projects` is not that filter: it is the folder that holds every project's transcripts.
- `--transcript PATH...` takes several paths and shell-style globs (expanded by the script, so a quoted glob
works); a session named twice loads once. One path reports on one session (its `subagents/` come along) or one subagent file,
ignoring the window — use it to inspect a single agent's start or shape. A transcript is a
`.jsonl` file; any other name is refused before it is read.
- `--rows` prints JSONL instead of the report, one object per context (main session or subagent), for an A/B
of an agent change or any per-agent table. It takes the same options; a row always covers a whole context, so with a window it lists the contexts whose first turn falls inside it (all their turns, even ones after `--until`), and with `--transcript` the window and `--project` are ignored and a path matching no file is an error. Fields: `session_id`, `agent_id` (null for a main session), `kind`, `project`, `agent_type`,
`model`, `turns`, `input_equivalent`, `usd` (list price), `peak_context`, `wall_seconds` (first to last
turn), `turns_before_first_edit` and `usd_before_first_edit` (null when it never edited or a turn before the edit is unpriced; 0 when it edited on its first turn),
`first_commit_turn` (null when it never committed), `report_chars` (its hand-back message or last text;
null when it has none). Example: `... --rows --since 1d | jq -s 'group_by(.agent_type)[] | {t: .[0].agent_type, usd: (map(.usd) | add)}'`
- `--sections NAMES` prints only those sections, comma-separated, each named by any prefix of it:
`totals, spend-by-type, per-day, main-sessions, concentration, turn-shape, cold-cache, what-fills-the-context,
fixed-start, rule-scorecard, review-by-rung, budget-marks, largest-contexts, tools-called`. An unknown name fails before any transcript is read
and lists the ones that exist.
- **Ask for the sections the question needs.** The full report is about 200 lines and every line of it
lands in the context. "Why was yesterday expensive?" is `--sections totals,per-day,main-sessions`,
not Fixed start; "did that change help?" is the one or two sections that measure it, run over each
window; "what should this agent's `tools:` be?" is `--sections tools-called`. Run the whole report
when the question is open ("where did my tokens go?"), and a selection for every follow-up after it —
re-reading a section you already have costs as much as reading it the first time.
## Reading the report
The section names `--sections` takes are the headings below, lowercased and hyphenated, plus
`tools-called` for the `--tools` section.
Every section shows main sessions and subagents separately, and leaves out a kind the window does not
hold: someone who has never started a subagent gets no subagent rows. Read the rows for the kind that
holds the spend first, and give advice for that kind. Delegation advice means nothing to a person whose
spend is all in their own sessions.
- **Totals** (`/ by model`) — the top-line number, main and subagent each on its own row, with input-eq and
`list $` (see Spend by agent type).
- **Spend by agent type** — one row per agent type (plugin prefix dropped, so a renamed plugin's types
line up) and `main`: contexts, median turns and peak context, input-eq, its share and the average per
context (`avg/ctx`), `list $` and `$/ctx`, output, and how many contexts peaked at 150k or 200k and over.
`list $` is input-eq priced at each model's list input price, plus output at five times it, from the
same price table as `cache-guard`: `-` for a model the table cannot place, Haiku 5.5 at its rate up to
100k tokens. It is a list-rate comparison, not a bill. Rows sort by `list $`. **Action**: compare rungs
on `$/ctx`; input-eq does not price one model against another, so an input-eq per context close to the
rung above says nothing about which is cheaper across models (measured over ten days on one machine:
`builder` $1.77 per context, `builder-lite` $0.60). A rung with a handful of uses is one the
orchestrator does not reach for.
A subagent typed `main` or `total` gets its own `subagent:` row.
- **Per day** — trend, with each day's main and subagent spend. A rising top-10% share or rising median
turns over days means contexts are running longer, not that more work is happening. A day with under
ten contexts shows `-` for the top-10% share: there is no decile to take.
- **Main sessions** — spend per project, then the largest sessions with their turns and peak context.
**Action**: a session with hundreds of turns and a peak in the hundreds of thousands is the person's
own largest lever. End it at a natural break and start the next piece of work fresh (`/clear`, from
a short note of where things stand), or `/compact`.
- **Concentration** — spend is roughly quadratic in turns (a turn resends its whole context), so a
high top-10%-of-contexts share, or a low share from contexts under 50 turns, means a few long-running
contexts dominate the bill. Under ten contexts it reports the largest context's share instead.
**Action**, main: shorter sessions, as above. **Action**, subagent: hand off one job per agent,
start a fresh agent for each review round, never resume a long-running one to "just finish one more
thing."
- **Turn shape** — the % of turns carrying exactly one tool call, and their share of spend. A second line
counts the turns that made one read-only call straight after another such turn (reads, searches, git
inspection): the most that requesting them together could save, since a read may have depended on
the one before it. High values here mean calls that could have been requested together were made
one at a time, each paying the full context over again. **Action**: batch independent tool calls into one response. In a main session the
person can ask for it ("look these up together"); for subagents it belongs in the handoff or the
agent definition.
- **Cold cache** — the turns that arrived after the prompt cache had expired (a gap of 5 minutes or
more, and under half the previous context read back from cache), their share of spend, and the
"avoidable" part: what writing that context in again cost above a warm cache read. The `cache writes`
line shows the lifetime the writes were actually bought at, per kind — where the records carry the
split, and prints `no lifetime recorded` where they do not — and it sets how long an idle context
stays warm. The main-only gap x size table is the case for a guard that warns before a prompt is
sent into a cold, large context. **Action**: a large main-session context left idle past the cache
lifetime is cheaper to `/clear` and restart from a short handoff than to continue; `/compact` pays
for the cold context once, and every turn after it is small. A model or effort change mid-session
resets the cache the same way, with no gap, so this section does not count it. The section also
shows what subagent cold turns were waiting on; when most follow one Bash call, the fix is fewer
long waits inside a large context (run the long suite once, at the end; a narrow test between
edits), and no prompt guard can catch them.
- **What fills the context** — a category table showing
which kind of content is resident in a typical context and how much of it gets re-sent turn after
turn. With both kinds present, `main %` and `sub %` give each category's share of that kind's own
re-sent total, so each column adds to 100% and the two can be compared row by row. `bash: wait loop
(polling a run)` is a command that slept until a log showed a verdict: its cost is the wait, which
the Cold cache section prices. **Action**: if `Read (whole file)` or a re-read-heavy category dominates, read files by range
and don't re-read what's already in context; if a `bash: cat/sed/head window` or grep category is
high, prefer the project's structural index/search tool over ad hoc text search.
- **Fixed start** — the context every turn pays before any work happens, by model and agent type, then
broken into instructions files, deferred MCP tool counts, skill listing, hook context, and the first
prompt. **Action**: the per-file instruction sizes say which rule or `CLAUDE.md` to trim (a file
loaded into every subagent is re-sent on every one of its turns); the per-server deferred-tool counts
say which MCP servers/connectors to disconnect for coding sessions; the skill listing likewise if it's
large relative to what a session actually uses. All of it applies to a main session as much as to a
subagent: the difference is that a subagent pays it again for every agent started.
- **Rule scorecard** — one line per rule the `delegate` plugin states, with the metric that measures it in
the window, the measured baseline where there is one (a target for the model ceiling), and `holds` or
`not holding`. Its `handoffs carry the code` line is the share of maker spend (`builder`, `builder-lite`,
and `mechanic` in older transcripts) before their first edit: a high share means handoffs aren't carrying the code the job touches, so quote it in
the handoff, or send a scout first. An edit made through Bash counts: in-place `sed` or `perl`, a
`git apply` that isn't a dry run, `patch`, `tee` or a redirect into a file outside scratch space, logs
and `.build/`, and a Python run that writes a file. The `maker handoffs carry gates` line is the share
of maker handoffs with a gate line, and how many named a handoff file no longer on disk. Handoff files a
prompt names (absolute or `~/` `.md`/`.txt`, up to five, 256 KB each) are read when the report runs, for
the gate line, the class line and for Review by rung's branch links. The `builder handoffs name a class`
line counts `builder` handoffs with a `Rung: builder — <class>` line and the share of builder spend held by
those without one; a low count means builders are chosen without saying why. The `a scout before the makers`
line sets the median spend and turns before the first edit of makers briefed by an earlier scout in the
session (a `.md`/`.txt` path both first prompts name) against those not briefed, with the scout count and
median spend; it holds when a briefed run-up is at or below the baseline measured before the scout existed,
and an unbriefed run-up well above a briefed one means a scout pays. `calls requested together` has no baseline verdict,
since its 70% baseline was measured on earlier models. `the model ceiling` leaves out subagents whose
call named its own model, which the hook leaves alone, and says how many.
- **Review by rung** — per maker type (`builder`, `builder-lite`) and round (first, or later
when an earlier maker in the session shares a branch), how many makers a later reviewer in the same
session passed, passed with lows or after fixes, or failed, the fail share of the classified reviews, and
the mean input-eq per maker. The link is a heuristic: a branch name both handoffs state (backticked, a
`feat/`-style word, or the worktree's own branch); a maker no reviewer names, or whose reviewer falls
outside the window, counts as unlinked. A reviewer that gave one verdict line per branch
(`Verdict (fix/name): …`) gives each maker the line naming its branch. **Action**: if the cheaper rung's fail share is no higher than
the dearer one's in the same round, route more of that work to it; compare first rounds with first
rounds, since the cheaper rung is mostly used for fix rounds.
- **Budget marks** — one line per rung and budget mark (120k, 150k and 200k; this plugin's own scout's 60k, 80k and
95k): how many agents reached it, the median turns they took after it, split by whether they had
already committed, and for the hand-back and stop marks, how many reports listed work left. For a
maker, it also counts the hand-backs linked to a later maker in the session (a shared branch, or a
prompt that reads as a continuation), what those follow-ups paid to reach their first edit against
what their turns from the first edit on would have added in the old, larger context, and how many hand-backs were
cheaper. **Action**: if few hand-backs are cheaper, the run-ups are the cost to cut: quote the code in
the follow-up's handoff, or send a scout first.
- **Largest contexts** — the worst individual offenders, for a closer look with `--transcript`.
## Caveats (the report states these too)
- Input-equivalent (`input-eq`) prices every token against the uncached input rate (cache read x0.1, or x0.025 on
Claude Fable 5.1, whose published cache-read price is a fortieth of its input price;
cache write 5-minute x1.25, cache write 1-hour x2, uncached x1) — it is **a price comparison, not a
token count**. Output tokens are reported separately and never folded into it.
- `list $` is a list-rate comparison, not a bill.
- Figures marked `≈` are `chars/4` estimates, not exact token counts.
- The transcript format is undocumented and has changed before; the report prints every harness
`version` it read so a surprising number can be checked against the version that produced it.