From token-audit
Audit Claude Code token usage and find where tokens are leaking. Reads ~/.claude/projects/*.jsonl transcripts locally, inventories settings/hooks/skills/MCPs, runs ccusage for baseline spend, then flags the highest-$-impact leaks (hook bloat, CLAUDE.md bloat, Opus on simple turns, context rot, skill description overhead, Bash anti-patterns, cache miss storms, redundant file reads) with ballpark weekly savings for each. All analysis is local — transcripts never leave the machine. Use when the user asks to audit their Claude Code usage, find where tokens are leaking, review token spend, optimize Claude Code, or understand why they're hitting weekly limits. Triggers: 'token audit', 'why am I hitting limits', 'optimize my Claude Code', 'token leak', 'audit my usage', 'where are my tokens going'.
npx claudepluginhub bayramannakov/token-audit-skill --plugin token-auditThis skill uses the workspace's default tool permissions.
Find where Claude Code tokens are leaking — and what to fix first.
references/additional-optimizations.mdreferences/hook-design.mdreferences/leak-taxonomy.mdreferences/thariq-heuristics.mdscripts/audit.pyscripts/bottlenecks.pyscripts/config_inspector.pyscripts/cost_model.pyscripts/detectors/__init__.pyscripts/detectors/bash_antipatterns.pyscripts/detectors/cache.pyscripts/detectors/claude_md_bloat.pyscripts/detectors/context.pyscripts/detectors/file_reads.pyscripts/detectors/hook_bloat.pyscripts/detectors/model_selection.pyscripts/detectors/recurring_scripts.pyscripts/detectors/skill_descriptions.pyscripts/detectors/tool_schema.pyscripts/ensure_ccusage.pyMandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Find where Claude Code tokens are leaking — and what to fix first.
Runs a local-only audit with three inputs:
~/.claude/projects/**/*.jsonl — per-turn analysis for patterns ccusage doesn't see~/.claude/settings.json, plugins, skills, MCP serversThen produces a ranked report of leaks with ballpark weekly $ savings for each.
python SKILL_DIR/scripts/audit.py --days 7
Outputs JSON to stdout. You (Claude) then synthesize a narrative report in the user's language — default English, switch to match the user's current conversation language.
/compact, /rewind, MCP, CLAUDE.md) stay untranslatedreferences/additional-optimizations.md for seeds (language efficiency, off-peak shifting, runaway cron check, local-model offloading, cache-TTL strategy, desktop-client blindness, skill pruning) and the brainstorming pattern. Curate 1-3 that actually apply to THIS user — don't list them all. If nothing fits, skip the section entirely.| Detector | What it catches | Source |
|---|---|---|
tool_schema | Full MCP tool schemas loaded every turn (~20k tok) — only fires if ENABLE_TOOL_SEARCH is OFF | Samarth Gupta audit |
hook_bloat | Session-start / PreCompact hooks re-injecting large output into every session | Novel |
claude_md_bloat | CLAUDE.md > 2k tokens, paid on every turn | Anthropic cost doc (200-line target) |
model_selection | Opus used on short/simple turns where Sonnet would suffice | Novel |
context | Turns past 400k-token context (context rot zone) | Thariq Shihipar, Anthropic |
skill_descriptions | Total skill-description budget per turn (flags fat individual skills + bloated totals) | Novel |
bash_antipatterns | cat/head/tail/find/grep via Bash instead of native Read/Glob/Grep | Samarth Gupta audit |
cache | Sessions with <50% cache hit ratio (churn-driven cache misses) | Novel |
file_reads | Same file Read 3+ times in one session (rewind candidate) | Thariq Shihipar, Anthropic |
npx — no install needed)~/.claude/projects/ and ~/.claude/settings.json (already yours)If ccusage is unavailable, the audit proceeds without baseline $ totals — detectors still work from JSONLs alone.
Most users are on a flat-rate subscription (Pro $20 / Max 5x $100 / Max 20x $200). Reporting "saves $2,200/week" when they pay $200 flat is misleading — they won't "save" that from their pocket. What they actually gain:
Narration rules when writing the report:
Detectors compute all of:
est_weekly_tokens — honest, plan-neutral primary metricest_weekly_cost_usd — at API list pricingest_weekly_savings_usd — what the fix would eliminate (at list pricing)Plan limits are published in scripts/cost_model.py (Pro/Max5x/Max20x ranges). Use plan_savings_summary(amount, plan) helper to generate the "≈ X% of subscription-week" phrasing.
Why we still compute dollars internally: for ranking. Dollar impact is the cleanest way to prioritize leaks across heterogeneous categories.
audit.py --days 7"Want me to apply any of these? I can: (a) add the Sonnet default to
<project>/.claude/settings.json, (b) trim the oversized CLAUDE.md, (c) enableENABLE_TOOL_SEARCH. Pick any."
references/hook-design.md for principles and patterns. Critical rules:
claude-code-guide agent or https://code.claude.com/en/docs/claude-code/hooks for the current hook API before writing any hook code — the spec changes, don't rely on memoryreferences/hook-design.md; surface this in step 5 of the invocation pattern)AGENTS.md, reasoning_effort), Aider (.aider.conf.yml, map-tokens), Cursor (Auto vs API pool routing).claudeignore absence, plan-mode underuse, stale-session resume, pasted-blob vs @file mentionsBaked into the analysis:
npx ccusage@latest fetch.