---
name: agent-budget-audit
description: Audit how a project spends its Claude Code tokens, then make sessions cheaper and faster without losing quality - measure first from the project's own transcripts, find the waste (a heavy start, idle turns, the big model on chores, long tool output, bloated docs), write a test with a prediction and a kill rule, and change nothing until the user says yes. Use whenever someone wants to stretch their Claude subscription, hits usage limits too often, asks why sessions are slow or expensive, wants to cut token usage or their API bill, asks how big their context or CLAUDE.md is, or wants to know where the tokens go, even if they never say "audit".
---

# Agent budget audit

Every turn re-reads the whole context. It is mostly cached, but it is still counted against your limit or your bill. So cost is
roughly **the number of turns times the size of the context**. The levers are:
- a smaller start;
- fewer idle turns;
- the small model for routine work;
- scripts instead of repeated judgments;
- fewer, shorter docs.

The order matters: **measure, find the waste, write the test, ask, then change.** A cut you didn't measure is a guess. Guesses
about tokens are often wrong, especially in the desktop app (see step 2a).

## Hard stops

- Stay read-only until the user says yes to a numbered change.
- Never print secrets. Settings, `.env` files, MCP config and **hook commands** can all hold tokens. Report names and sizes only,
  and mask anything that looks like a key.
- Delete nothing. To switch something off, disable it in settings or move it, and say how to undo each change.
- Anything that touches every project (user-level settings, plugins other projects use, account connectors) needs its own
  separate yes.
- Say plainly what you couldn't measure, and give a range instead of a made-up exact number.

## 1. Measure (read-only)

Run the bundled script (Node 18+, no packages):

```bash
node <this skill's folder>/scripts/measure.mjs --project <the project's folder> --sessions 30
```

It reads `~/.claude/projects/<the project path with "/" replaced by "-">/*.jsonl`, plus worktree folders and subagent
transcripts. It prints one dated table:
- first-turn context, turns, peak context and context read per turn;
- models, prompts typed against automated ones, subagent runs;
- active hours, and sessions per week;
- skills and MCP servers actually used;
- tool output by size.

It also prints **what the first turn is made of**, wherever the transcript records it. Newer desktop transcripts do: the tool
schemas, system prompt, deferred tool names, skills list, MCP instructions, hook output and each CLAUDE.md or memory file.
`--json` gives the same data for your own sums.

Read the notes at the top before trusting any number:
- **Small samples.** Under 10 sessions, a median is a hint, not a finding.
- **Deleted sessions.** Sessions deleted in the desktop app can't be measured, and deleting more during a test breaks the test.
- **The audit itself is left out.** A transcript written to in the last 10 minutes is treated as live, usually the audit itself.
  `--include-live` counts it.
- **Automated kinds.** Check the "Automated, by kind" row. A tag the script doesn't know (a button click in the app, say) counts
  as automated, so correct it by hand if a kind is really the user.

**The first-turn split.** Characters per token vary a lot (about 2.6 to 3 in the tests). So the script gives each part as a range:
- **low:** characters / 4;
- **high:** the part's share of the measured first turn.

Quote the range. If a transcript doesn't record the tool schemas, the script shows them as "not recorded". Estimate the CLAUDE.md
files and memory from their sizes on disk.

**Expect the start to be mostly the app and your user-level setup, not the project.** In the tests, the project's own CLAUDE.md
was 2% to 10% of the first turn. Tool schemas, deferred tool names, the skills list and MCP instructions made up most of the rest.

Where things live, so you can name the source of each part:
- MCP servers: `~/.claude.json` (top level, and per project under `projects`), and `.mcp.json` in the project.
- claude.ai connectors: on the account. They appear in transcripts as long IDs (`mcp__825d615b-…`), so name them from their tool names.
- Hooks: in each settings file's `hooks`.

## 2. Find the waste

Rank by tokens saved per hour of work. The active hours in the table give the per-hour part.

**a. The start.** The start is re-read on every turn, so a cut here saves (tokens cut) × (turns per session).
- **Instructions.** Over about 10k tokens? Move the parts that concern one area, word for word, into rules that load only when
  matching files are read (path-scoped rules, if this version supports them). Often the instructions are small, and this lever is small.
- **Unused things.** Plugins, MCP servers and connectors this project never calls (the "used" rows show what it does call).
  Switch them off for this project only, in project settings.
- **Skills.** Switching skills off saves little on its own: the skills list is capped by a listing budget, so fewer skills mostly
  means longer descriptions for the rest. Lowering the budget itself is a separate, user-wide change that can make skills trigger less reliably.
- **Settings to look up.** These names were seen in the Claude Code settings docs in November 2026. Confirm each in the current
  docs before proposing it, and say which file it goes in:
  - `enabledPlugins`
  - `disableClaudeAiConnectors`
  - `enableArtifact`
  - `deniedMcpServers`
  - the skill-listing budget keys
- **Prove each cut in the client the user actually works in**, by the first-turn size of a fresh session there. A setting can
  shrink a terminal session (`claude -p`) and do nothing in the desktop or IDE app. In one test (November 2026), project-level
  plugin switches shrank a terminal session, while desktop sessions measured 115.5k tokens before and 114.5k after. If project
  settings don't take, the lever is user-level settings, which touch every project, so list those separately.

**b. Idle turns.** A session that polls, waits or coordinates other sessions pays the full context for every message it
receives. Count those turns: the automated column, by kind.
- Prefer one background wait to repeated checks.
- Have no session whose job is managing other sessions.
- Run at most about 3 sessions at once.
- Short scheduled tasks pay the whole start for a few turns, so a frequent schedule's cost is mostly its first turn. Ask whether
  the schedule could be less frequent, combined with another, or a plain script.

**c. Model per job.** Search, log reading, cleanup, git chores and simple checks go to the smallest model (a subagent with its
model set). The big model is for design and hard code. On a subscription, the big model also counts more heavily against the limit.

**d. Scripts over judgment.** Any check done by reading (a test summary, a status report, "is this branch merged?") becomes a
script, which costs no tokens to run.

**e. Long outputs.** For commands that flood the context (the tool table's "biggest single" column), save the full output to a
file and print only the summary and the first error. Results the app already saved to `<session>/tool-results/` sit on disk; only
their preview is in context.

**f. Docs.** Compare the words in the docs with the size of the code. Docs cost tokens only when they are loaded or read, so check
the transcripts for that before ranking this high.
- Rewrite status; don't append to it.
- Keep lessons as short rules by topic, and decisions as one line each.
- Delete a plan when its work lands. That means the user deletes it, or says yes to you deleting it; see the hard stops.
- Write docs only where the code and its comments can't hold the knowledge.

**g. Session length.** Cost per turn grows with the context, whatever the window size, so use a token figure, not a percentage:
- Split around 150k to 200k tokens.
- Above that, write a short handoff and start fresh.
- One outcome per session.

With a 1M window, a percentage rule like "split at 60%" would let a session run past 500k tokens per turn.

## 3. Write the test before changing anything

- A hypothesis.
- Numeric predictions:
  - An instant check: the first turn of one fresh session in the user's own client. This proves the setting is honoured.
  - A trend over the next 10 to 25 sessions. For example: first-turn context down 8% or more, context per turn down 5% or more,
    and no session over 250k, with no workflow broken.
  - Base every number on the savings you estimated, not a round guess.
- A kill rule: if it misses, restore everything.
- The readout: `node <this skill's folder>/scripts/measure.mjs --project <folder> --split <the date of the change> --sessions 25`,
  which prints before and after side by side.
  - The split is by start date, so a session started before the change and resumed after it counts as "before".
  - Ask the user to keep their sessions until the readout. A deleted session drops out of the test.

## 4. Ask, in one short numbered list

For each change, give:
- the expected saving in tokens (per turn, per session, and per week at the current pace);
- its risk;
- how to undo it;
- your recommendation.

Put project-level and user-level changes in separate groups. Habits (shorter sessions, a handoff) are changes too, so list them.
Change project files only on a yes.

## 5. After the yes

1. Make the changes.
2. If the project uses git, commit them with the test written down: hypothesis, predictions, kill rule and readout command.
3. Run the instant check, and tell the user its number.
4. Say when to read the trend: after about 10 to 25 sessions, or on a date at the current pace.

**Tested on** one Apple Silicon Mac, macOS 26, Node 22.22, with Claude Code desktop app transcripts read on 2026-11-12 from
three projects (4, 25 and 30 recent sessions, including worktrees, subagents, scheduled tasks and deleted sessions). The script
was run in every mode. A fresh session did steps 1 to 4 on one project with an earlier version of this skill. It produced a full
audit and the list of changes, changed nothing, and its notes shaped this version. Step 5 (making changes and reading a test) has
not been run. Linux, Windows, the terminal CLI's own transcripts and Cowork were not tried.
