/audit:usage [--by phase|task|model|author|agent|attr|branch|session|hour|day|month] [--phase <id>] [--author <who>] [--area <tag>] [--since 7d] [--format md|ascii] [--json] [--backfill]from audit
Audit pipeline: token spend attributed by phase, task, model, author and time — with cache economics, cost-per-task and a usage trend. Read-only (never mutates the manifest).
Ships in audit. Installing the plugin adds it to Claude Code.
Run
python3 "${CLAUDE_PLUGIN_ROOT}/scripts/usage/audit-usage.py" --format md $ARGUMENTS
Print its stdout verbatim in your own reply — a tool result is collapsed behind the tool
call, so running the command is not delivering it. Do NOT re-format, summarize, re-tabulate,
or "improve" it. Whether it goes in a code fence depends on the format, and only on that:
the default md output is printed unfenced, because it is already markdown (pipe tables,
bullets) and a fence would disable the table rendering it exists for; ascii output is printed
inside a fenced block, because it is fixed-width text that only lines up in one. The script renders its own final output for a
reason: a usage tool that spends a pile of tokens laying out its own tables every time you ask
what you spent is self-defeating. Reading the numbers back to the user costs roughly as much as
the report describes. Just show it. (A user-supplied --format ascii in the arguments wins over
the default above — argparse takes the last occurrence; print that verbatim too, fenced as
said above.)
The only thing worth adding is a single line of interpretation when something in the output is genuinely notable — a phase that cost several times its peers, a cache hit rate that collapsed, a model routed somewhere it shouldn't be. Otherwise say nothing.
Read-only: this never takes the audit lock and never touches the manifest. The one exception is
--backfill, which rewrites the monthly ledger files and takes the shared usage lock for the
duration — the same claim, in the same place, that audit-lock.py status and /audit:doctor
report. That lock excludes only another backfill. The metering hook runs on every turn and never
takes it. What it takes instead is the month's own lock, across each append's open, write and
close; the backfill takes that same lock only around each month's last read and replace. So while
a month is swapped no appender is mid-write or holding the file open, appending goes on through the
rebuild, and the rows appended since the backfill read the month are carried into the new file —
those of sessions it did not re-read. A project with no git repository has no lock scheme at
all; there the backfill says so in its own output rather than inventing a guard nothing else can
see.
What that still leaves open, stated rather than implied closed:
--backfill again once no other session of the project is active; it rebuilds
every session it reads from the transcripts. The session running the backfill is exposed only
through a subagent of its own finishing in the window: its own Stop metering runs when the
turn ends, after the backfill has finished.A month with no file yet is created empty before its rebuild and held the same way, so a row the hook appends while the backfill writes that month is carried like any other.
A month file the backfill could not rewrite cleanly is named in its output, and the backfill
exits non-zero. A session whose rows all sit in months that failed keeps its old cursor, which
matches a month whose replace was refused. A session that also has rows in a month that was
rewritten has its cursor saved, because that month already holds every row of the session and
an old cursor would have the next metering pass append them there again; its rows in the failed
month are missing until the next --backfill. Run it again.
Pass $ARGUMENTS through unchanged. Nothing here needs interpreting on your side.
| Flag | Effect |
|---|---|
--by phase|task|model|author|agent|day|month|hour|session|branch|attr | one focused table instead of the dashboard |
--phase <id> --task <id> --model <name> --author <who> | narrow the rows (--model/--author match on substring) |
--area <tag> | only spend whose phase carries this area tag (untagged selects spend no area owns) |
--attr task|phase|window|unattributed | filter by attribution precision |
--since 7d|2w|3m|YYYY-MM-DD, --until YYYY-MM-DD | bound the window |
--top N | cap TOP TASKS (default 10) |
--no-cost | tokens only, no dollar figures |
--format md|ascii | md (the default above) renders pipe tables for this chat surface; ascii is the fixed-width terminal shape for pipes, logs and CI |
--color auto|always|never | ANSI color for humans at a real terminal (auto = TTY with NO_COLOR unset; this chat surface is a pipe, so it stays plain; md never colors) |
--json | machine-readable, for CI - keeps the cost fields beside showCost, which the payload carries at top level, rather than withholding either |
--backfill | re-read every transcript and rebuild the ledger |
#no-plan work, sessions predating the ledger — lands in unattributed and is
still counted. A run showing everything as unattributed is normal on a repo that has not run a
phase since metering was installed.equiv because it is computed from a price table, not from a bill.
Subscription plans carry no per-token charge, so treat it as "what this would have cost on the
API", not as money spent.phaseId and the
phase carries the tags, so re-tagging a phase re-attributes its whole ledger history on the next
read, with no backfill. A phase tagged with several areas counts its rows under each tag, so
the BY AREA rows can sum past the total — the output says so when it applies. untagged is
where spend with no area lands (untagged phase, unknown phase, or no phase on the row).MONTHLY appears once the rows in view span two calendar months — one month would restate
the totals line. Its ledger columns follow the filters; its plan columns (tasks done, bugs,
fixed, merged) count the whole project by event month, and the footer says so. --by month
is the same bucketing as a plain grouped table.The output says so and points at --backfill. Metering is a Stop / SubagentStop / SessionEnd
hook, so a brand-new install has nothing until a turn completes. --backfill reads the transcripts
already on disk and is idempotent — running it twice leaves identical totals.
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
21 commands in this plugin
/bug/audit:bug — bug tracking on the audit manifestTrack bugs in the audit manifest — report (add), list, materialize a TDD fix task (fix), or close. Execution of the fix stays in /audit; the repro test must fail red-first, proving the bug./doctor/audit:doctor — is this setup actually working?Audit pipeline: diagnose the setup before it bites — interpreter the hooks will use, git root, config, manifest + shard integrity, which plan-gate tier is active, submodule conflicts, build runners, whether the skills the plan names would resolve from a clone or only here, whether hooks have ever fired and which copy of the plugin ran them, the usage ledger, whether the audit trail still holds, and whether the capability policy is inert, contradicted by the plan, or never enforced. Read-only, no locks, no mutations./guide/audit:guide — ask the plugin about itselfAsk the plugin about itself — what a config key does, how the plan gate grades, what the journal can prove — answered from its own docs with a citation for every claim, by the read-only guide agent./init/audit:init — generate the audit manifestMulti-agent codebase audit that GENERATES the audit manifest (phases/tasks) at manifestPath. Interviews you for scope/goals, fans out parallel read-only explorers, synthesizes findings, then presents the proposed phases for approval BEFORE writing — approve to materialize, or park them as proposals for later /audit:propose materialize. Asks which manifest layout to write (one file, the default, or one file per phase for parallel worktrees)./layout/audit:layout — pick the manifest layout, in either directionAudit pipeline: choose how the manifest is stored — `sharded` (an index plus one file per phase: fewer tokens per phase run, parallel-safe across worktrees) or `single-file` (one file, one diff, no index). A layout CHOICE, not a version upgrade: both shapes are current, neither goes out of date, and this command moves in either direction under one lock, one backup and a re-validate-or-restore. `merge-driver install|uninstall|status` sets up the git merge driver that merges the manifest by record, in either layout./logs/audit:logs — clean the feeds this plugin writesAudit pipeline: prune the local feeds this plugin writes under logsDir — today the plan-gate events feed rendered by the panel Plan gate card. Removes rows that no longer belong (paths outside this repository, lines that are not JSON, optionally rows past an age you name), prints what went and what stayed, and never touches anything outside logsDir. This one WRITES: the verb is mandatory and --dry-run is the read-only half.npx claudepluginhub aleksandarbisevac/claude-plugins --plugin auditOther plugins' commands for the same job