/session-metrics:audit-session-metricsfrom session-metrics
Audits session-metrics JSON exports for token-usage waste, producing a plain-English findings report in quick or detailed mode.
Ships in session-metrics. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Reads a session-metrics JSON export and produces a prioritised, plain-English
audit of token-usage waste. It runs on the session's current model (it no
longer pins one — a hard model pin capped the usable context at that model's
window and broke invocation on long sessions). The work is mostly
summarisation over a small disk-read export, so for a much cheaper run
/model haiku before invoking. On the Anthropic API haiku is Haiku 5.5
(1M window, so long sessions fit; prompts over 100K tokens bill at its higher
rate). On Bedrock, Google Cloud, Microsoft Foundry, and Claude Platform on AWS
it is still Haiku 4.5 with a 200k window — short/early sessions only there.
Supports three JSON scopes auto-detected from digest.scope:
session_*.json) — per-turn analysisproject_*.json) — per-session analysisinstance/*/index.json) — per-project analysisFirst positional argument received: $ARGUMENTS[0]
Second positional argument received: $ARGUMENTS[1]
Read $ARGUMENTS[0] and match by literal equality:
$ARGUMENTS[0] | Route | Then read (session scope) | Then read (project/instance scope) |
|---|---|---|---|
quick | Quick audit | references/quick-audit.md | see Scope routing below |
detailed | Detailed audit | references/detailed-audit.md | see Scope routing below |
| (empty / other) | Print usage and stop | this file's "Usage" block below | — |
$ARGUMENTS[1] must be the path to a JSON export written by session-metrics.
Accepted patterns:
exports/session-metrics/session_<id8>_<ts>.json — session scopeexports/session-metrics/project_<ts>.json — project scopeexports/session-metrics/instance/<datedir>/index.json — instance scopeIf $ARGUMENTS[1] is missing, empty, or the file does not exist, print:
Usage: /audit-session-metrics {quick|detailed} <path-to-session-metrics.json>
Accepted JSON types: session: exports/session-metrics/session_.json project: exports/session-metrics/project_.json instance: exports/session-metrics/instance/*/index.json
…and stop without further work.
Run the extract helper once with the input path:
python3 scripts/audit-extract.py $ARGUMENTS[1] --mode $ARGUMENTS[0]
The helper emits a single JSON digest to stdout. Read digest.scope
from the output — it will be "session", "project", or "instance".
Do not read the raw .jsonl, and do not re-derive numbers the
digest already carries.
Scope routing — read the matching reference file:
digest.scope | $ARGUMENTS[0] | Reference file |
|---|---|---|
session | quick | references/quick-audit.md |
session | detailed | references/detailed-audit.md |
project | quick | references/project-quick-audit.md |
project | detailed | references/project-detailed-audit.md |
instance | quick or detailed | references/instance-quick-audit.md |
Follow the playbook step-by-step. Do not improvise additional phases.
For detailed mode on session scope only, the playbook also asks
you to read the user's config files (~/.claude/CLAUDE.md,
./CLAUDE.md, ~/.claude/settings.json, ./.claude/settings.json,
./.claudeignore). Each is capped at ≤500 lines — if a file is
bigger, that itself is a finding.
Output contract — three artefacts. All playbooks specify the same three-artefact contract:
<project>/exports/session-metrics/audit_<id8>_<ts>_<mode>.json — structured findings (versioned schema, enum'd metrics).<project>/exports/session-metrics/audit_<id8>_<ts>_<mode>.md — same content rendered for humans.<id8> and <ts> come from digest.session_id_short and
digest.ts_str (the helper parses the input filename and
normalises all three filename patterns).
Write order. Populate the JSON object first using the digest
values, write the JSON sidecar, render the markdown using the
template in the playbook, write the markdown copy, then print the
markdown inline (without the H1 heading — the chat client already
shows context above the audit). Finish with two stderr-style lines
on their own:
[audit] saved → <json-path>
[audit] saved → <md-path>
IMPORTANT: Use the Write tool directly for steps 3 and 5.
Do NOT generate a Python script (e.g. writing to /tmp/audit_synthesis.py
and executing it) — this adds unnecessary failure modes (syntax errors,
f-string escaping) and is never required. Build the JSON in the AI's own
context; call Write. Render the markdown in context; call Write again.
The audit is a distinct, user-initiated analysis step over a finished
export, not part of generating one. It reads only the on-disk JSON — never
the conversation — so it stands alone as its own turn, which is why
session-metrics suggests /audit-session-metrics rather than invoking it
programmatically. Running it as a fresh slash command keeps the turn focused
and lets the user decide when to spend on it. The work is summarisation-heavy
and the input is tiny, so the cost path is /model haiku before invoking
(Haiku 5.5 with a 1M window on the Anthropic API; on other providers
haiku is Haiku 4.5 with a 200k window, so short/early sessions only) — far
cheaper than a frontier model, with identical output (every dollar figure is
pre-computed by audit-extract.py, not guessed by the model).
references/quick-audit.md — Distilled
ratios + cache health + top expensive turns. Read when scope=session,
mode=quick.references/detailed-audit.md — Quick
audit findings plus config + re-read scans. Read when scope=session,
mode=detailed.references/project-quick-audit.md —
Per-session cost outliers, cache health, breaks, weekly trend. Read when
scope=project, mode=quick.references/project-detailed-audit.md —
Project quick findings plus per-session turn-level drilldown on the most
expensive sessions. Read when scope=project, mode=detailed.references/instance-quick-audit.md —
Per-project cost breakdown, cache health, weekly cost trend. Used for both
quick and detailed modes (no per-turn data available at instance scope).references/detailed-audit.md (opens in a new tab)references/instance-quick-audit.md (opens in a new tab)references/project-detailed-audit.md (opens in a new tab)references/project-quick-audit.md (opens in a new tab)references/quick-audit.md (opens in a new tab)scripts/audit-extract.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
lowThree short reads, in order
npx claudepluginhub centminmod/claude-plugins --plugin session-metrics3 skills in this plugin
/session-metricsTally Claude Code session token usage and cost estimates from the raw JSONL conversation log. Trigger when the user asks about session cost, token usage, API spend, cache hit rate, input/output tokens, or wants a breakdown of how much a Claude Code session has cost. Also trigger for "how much have we spent", "show me token usage", "session summary", "cost so far", or any request to analyse or display per-turn metrics from the current or a past session.
Do NOT auto-dispatch compare mode (--compare / --compare-prep / --compare-run / --count-tokens-only) from natural-language phrases. The skill body uses $ARGUMENTS[0] as the dispatch key — if the first positional argument is not literally "compare", "compare-prep", "compare-run", or "count-tokens", route to the default single-session report.
/task-breakdownGroup a session-metrics session's turns into higher-level SEMANTIC TASKS ("what was I actually trying to do") and render a Tasks companion page (*_tasks.html + *_tasks.md) with a worth-it / mixed / likely-waste verdict per task. Trigger when the user runs /task-breakdown, when session-metrics suggests a task breakdown after a JSON export, or when the user asks to "group my turns into tasks", "what tasks did this session cover", "which work was worth it vs wasted", or "break this session into tasks". Consumes the deterministic per-request breakdown (request_units) from a session-metrics JSON export — it never re-derives cost or token numbers. Args: $ARGUMENTS[0] = path to a session-metrics JSON export (optional; if omitted, generate one first).
Other plugins' skills for the same job