Measure what this project's Claude Code sessions load at start and spend (boot context, API-equivalent cost, agents, skill and lower-model candidates) and turn top savings into proposals. Use when asked for "context audit", "why is it so expensive", "token cost", "what loads at session start", "trim the context".
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 Context Audit?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ivan-ii-tech-digital-context-audit)
---
name: context-audit
description: Measure what this project's Claude Code sessions load at start and spend (boot context, API-equivalent cost, agents, skill and lower-model candidates) and turn top savings into proposals. Use when asked for "context audit", "why is it so expensive", "token cost", "what loads at session start", "trim the context".
model: opus
---
The numbers come from a script. Review subagents judge the skills. This skill merges both into one proposal list.
Read `${CLAUDE_PLUGIN_ROOT}/skills/context-audit/rules.md` before forming any proposal. Every proposal cites the rule it serves, as "rule N".
1. **Run the audit** from the project root (the primary checkout or any of its worktrees; both find the same transcripts):
```bash
"${CLAUDE_PLUGIN_ROOT}/bin/ak-context-audit" > "<scratchpad>/context-audit-$(date +%F).txt"
```
`<scratchpad>` is the session scratchpad directory named in your system prompt. Add `--since YYYY-MM-DD` when the user names a period, and use `--json` when you need exact fields. The script only reads transcripts and settings and only writes stdout.
2. **Check the header.**
- Relay every `WARNING:` line of the header, as printed, before any number.
- If the script exited non-zero (the report is one line, such as "No transcript folder …" or "audit failed softly: …"), stop and relay that line.
3. **Compare with budgets.** Run `"${CLAUDE_PLUGIN_ROOT}/bin/ak-config" '.contextBudgets // empty'` from the project root (it merges `config.local.json` the way the hooks do). If it prints an object, compare each measured value with its key; the shape is at the end of `rules.md`. Two keys have defaults:
- `autocompactTokens`: when absent, compare with 400,000.
- `keepPlugins`: plugins listed there are never proposed for disabling.
4. **Review the skills with subagents.** Spawn three unnamed subagents in parallel with `model: "opus"`, one per skill source:
- the project's `.claude/skills/` (plus `~/.claude/skills/`, or `$CLAUDE_CONFIG_DIR/skills/` when set, when the listing shows user skills);
- agent-kit plugins (`ak-*`);
- third-party plugins.
Each brief is a pointer, never a paste. It names:
- the report path, and the lines to read with `grep -n`: `skill listing by source`, `## Skills`, `## MCP servers`, `All invocations`, `Lower-model candidates`, `boot cost vs uses`, `skill files`;
- where the skill files are: `<project>/.claude/skills/*/SKILL.md`, or for a plugin, its path on the `skill files` line under `## Plugin usage`;
- `${CLAUDE_PLUGIN_ROOT}/skills/context-audit/rules.md` (the resolved path), which the subagent reads first. Those rules are its review criteria.
Each subagent judges every skill in its batch against those rules. Every finding cites the rule it serves, for example "rule 2: description is 4 sentences, tighten to one sentence plus triggers". It checks at least:
- description length and trigger quality (rule 2);
- fixed command sequences that could become a script (rule 4);
- lower-model candidates (rule 7), written as proposals only;
- overlap or duplication with another skill, in its batch or outside it;
- skills never invoked: the `uses` and `flag` columns of the `## Skills` table; its tail line names the unused rest;
- for a low-use plugin (rows flagged `unused` or `near-zero`): the rule-9 cause — compare its skill descriptions with the project's own rules, skills and pipelines, and say whether it is redundant, mis-triggered or genuinely unused.
A finding that cuts or shortens a line names its ground and what the line was the only source for (the cut rule under ## Rules; the brief quotes it). A finding that matches no rule goes under a separate `## Outside the rules` heading, so gaps in the rules surface. The brief also states that the subagent only reads and reports. It never edits a config, setting, skill file or model line.
Each subagent writes its findings with a shell heredoc to `<scratchpad>/context-audit-review-<batch>.md`. The Write tool refuses subagent report files. Its final message is a one-line verdict plus that path.
5. **Merge into one proposal list.** Merge the script numbers and the three findings files into one list, ordered by measured saving (USD first, then counts). Each item gives the measured number, the rule it serves and one concrete proposal:
- **Boot category (rules 1–3, 6):** name the file, plugin, server or skill behind it: the `instructions by file` line for memory files, the `## MCP servers` table for MCP instructions and tools, the `## Skills` table and the `skill listing by source` line for skills, the `Hook output` line for hook context. Say what to move, shorten or disable.
- **Agent spend (rule 5):** pointer briefs instead of copied documents. A cheaper model for routine agents is a rule-7 proposal.
- **Agent configuration (rule 11):** compare the "Agents" section with the project's agent configuration (team configs, the agent-tier rules in the root rules file, worktree settings) and propose adjustments: model per agent type, seat counts, worktree isolation added or dropped.
- **Repeated prompt, re-invoked skill or script candidate (rule 4):** say which steps become a script or a skill.
- **Skill description, overlap or never-invoked skill (rule 2):** quote the subagent finding with its file path. A never-invoked skill reads `uses` and `flag` straight from the `## Skills` table; `built-in` rows are never proposed.
- **Outside the rules:** list the subagents' findings under that heading separately, as possible gaps in the rules.
- **Autocompact (rule 8):** compare the `auto compactions by model` median for the model in use with the target.
- Give the `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` value that reaches the target: pct = 100 × target / window.
- When the `autocompact setting` line already implies the target but the measured median is far from it, report the gap as measured. Never guess the cause.
- **Unused plugin (rule 9):** for each plugin row flagged `unused` or `near-zero` that is enabled now and not in `keepPlugins`:
- say which rule-9 cause the evidence supports — redundant, mis-triggered or genuinely unused — from the review subagents' comparison of the plugin's skills with the project's own rules and flows;
- propose `"<plugin>@<marketplace>": false` under `enabledPlugins` in the project's `.claude/settings.json` (for a mis-triggered plugin, offer fixing the triggering as the alternative);
- give its boot tokens and est. USD;
- name `hook-only` and `few-sessions` rows, but do not propose them.
- Never write the setting yourself.
- **Unused MCP server (rule 9):** for each `## MCP servers` row flagged `unused` or `near-zero` that no plugin owns (a plugin-owned server is covered by its plugin's row), give its `boot now` tokens, its `if all loaded` ceiling and est. USD, and the mechanism for its source:
- a server in the project's `.mcp.json`: propose adding its name to `disabledMcpjsonServers` in the project's `.claude/settings.json`;
- a `claude.ai` connector: the user disables it in their claude.ai settings, which is account-wide, not per project. Say so and ask first.
- any other server: name it and ask the user; propose no setting.
Agent figures are shares and lower bounds, already inside the session totals. Never add them to the totals.
6. **Reply** with:
- the report path and the findings-file paths;
- the boot median and total spend (labelled API-equivalent USD, not the subscription bill), with the report's estimate line once next to the boot median: "Estimates from past transcripts (~2.9 chars/token, API list prices); live /context shows exact counts for one session.";
- the merged proposal list.
## Rules
**A cut names its ground.** A proposal to delete or shorten a description, instruction, rule or memory line names one ground: wrong (the evidence), duplicated (the copy that stays), never used (the `uses` count or other evidence; "nothing failed lately" is not one) or superseded (what replaced it). Cut check before it goes on the list: name what the line was the only source for (grep the rules files, skills and memory); each item moves elsewhere in the same proposal, or the cut is dropped.
## Closing section
End the reply with an optional next step for the user to decide:
- What it is: enable OpenTelemetry export in Claude Code's user or managed settings.
- Why: it gives exact per-agent token and cost attribution, which transcripts can only estimate.
- The kit never enables it. Neither does this skill. Never write it into project settings.