session-cost-audit

Aggregates Claude Code session transcripts into token cost breakdowns and anti-pattern flags.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/psw7205/skills --skill session-cost-audit-psw7205
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: session-cost-audit
Source: https://github.com/psw7205/skills/tree/main/skills/session-cost-audit
Command: npx skills add https://github.com/psw7205/skills --skill session-cost-audit-psw7205

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Claude Code sessions silently accumulate token costs through oversized contexts, prompt cache rebuilds, unpinned subagent models, and large tool outputs, with no built-in way to see where the spend goes. This Skill reads local session transcripts and reports exactly which cost-equation terms drive your usage and what to change. ## Core Features & Use Cases - Weighted spend breakdown: Aggregates input, cache write, cache read, and output tokens per model across main and subagent transcripts, using Anthropic price ratios as relative weights (never absolute dollar amounts). - Anti-pattern flag detection: Automatically flags prompt-init overhead, context over 400K, prefix rewrite waste, model-switch rewrites, idle-expiry rewrites, large tool results, unpinned subagent models, subagent underuse, output-heavy sessions, high effort defaults, and MCP-heavy usage, each with metric, impact, and remediation. - Prefix rebuild cause analysis: Classifies every full cache rewrite by cause (session start, compaction, model switch, idle gaps) with event counts and token shares. - Use Case: After noticing a project burns tokens unusually fast, run the audit to discover that 40% of cache writes come from mid-session model switches and that Read results over 40KB dominate tool output, then pin subagent models and delegate bulk reads. ## Quick Start Ask the assistant to run a session cost audit on the current project and report the top token waste flags with recommended fixes.

Frequently Asked Questions about session-cost-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I analyze Claude Code token usage per session?▼

Run the session-cost-audit.py script against your ~/.claude/projects transcript directory. It aggregates requests, context sizes, and token categories across sessions and prints a weighted spend share report plus ranked anti-pattern flags.

How to find why prompt cache keeps missing in Claude Code?▼

The audit classifies every full prefix rewrite by cause: session first request, after compaction, model switch, or idle gaps over 5 minutes or 1 hour. The prefix_rewrites report shows event counts and token shares per cause so you can target the dominant one.

Does the audit include subagent token costs?▼

Yes. Subagent transcripts stored under <session-id>/subagents/*.jsonl with isSidechain are parsed separately and reported with their own model breakdown and weighted spend share. It also flags Agent calls that inherit the primary model instead of pinning a cheaper one.

Why does manual jq token counting differ from the audit results?▼

Assistant responses are split into one line per content block, each repeating the same usage object, so naive summation roughly doubles the counts. The script deduplicates by message id, which jq pipelines typically do not.

Can I audit worktree sessions or a different project?▼

Yes. Pass --project with the repo path and --include-nested to merge worktree transcript directories, which are stored under separately encoded project dir names. You can also point --dir at a transcript directory directly.

Does the cost audit report actual dollar amounts?▼

No. It reports weighted relative spend using configurable price ratios (default 1, 2, 0.1, 5 for input, cache write, cache read, output). Override with --weights if vendor pricing changes; the report never states absolute dollar figures.