Token-Efficiency Coach
Reads a Claude Code session transcript and coaches the user on token waste — the
observable inefficiencies (uncached context, context bloat, oversized tool output,
failed tool calls, output-heavy turns, wrong-tier routing, redundant reads) — with a
per-finding fix and a dollar estimate. It flags waste; it never grades work quality
or scores a person. The analyzer runs locally and reads only your own session log, so
no prompt leaves your machine.
The report below is generated at command time by the shared engine (scripts/analyze.py),
which auto-finds the latest session for this project when no path is given, or analyzes
the path you pass as an argument.
Coach report
!python3 "${CLAUDE_PLUGIN_ROOT}/scripts/analyze.py" $ARGUMENTS
Your task
- Relay the ranked report above to the user in your own words — lead with the
headline (total cost, the single biggest recoverable amount) and then the findings
in priority order. Keep dollar figures framed as upper-bound estimates, exactly as
the engine does. Do not invent numbers the report did not produce.
- Offer to apply the top fix. Pick the highest-severity finding and propose the
concrete remedy it implies, for example:
- Low cache hit → restructure the session so stable context (system prompt,
instructions, pinned files) sits at the FRONT and stays byte-identical so it caches.
- Context bloat / very long thread → compact the conversation or split the remaining
work into a fresh session to shed dead context.
- Oversized tool output / redundant reads → read targeted line ranges, grep for the
lines needed, and pipe noisy commands through head/tail instead of dumping whole files.
- Everything on the priciest model → route mechanical steps (renames, greps,
boilerplate, file reads) to a cheaper tier and reserve the top model for real reasoning.
- Offer to wire up the live statusline if the user does not already have one. The
plugin ships
scripts/statusline.py (live $cost · ctx tokens · cache-hit% · ⚠),
but a plugin cannot register a statusLine itself — it must go in the user's
~/.claude/settings.json pointing at a stable copy of the script. If they say yes,
walk them through the README's "Wire up the statusline" steps (copy the script to a
stable path, add the statusLine block, accept the trust dialog).
If the report says no waste patterns tripped, congratulate the user on a clean session
and skip the fix offer (the statusline offer may still apply).
Notes for maintainers
- All detection logic lives in
scripts/analyze.py (the single engine). This command
adds zero analysis logic — it only injects the engine's output and relays it.
- Waste patterns + coaching copy live in
scripts/patterns.json; prices in
scripts/prices.json. Edit those, not this file, to tune behavior.
${CLAUDE_PLUGIN_ROOT} is substituted in skill content for plugin skills, so the
engine path above resolves to the installed plugin's scripts/analyze.py.
1---2name: coach3description: Run the token-efficiency coach on a Claude Code session transcript: find wasted tokens (uncached context, bloat, oversized tool output, redundant reads, wrong-tier spend) and report the fixes with dollar estimates. Use when a session felt expensive/slow or the user wants to cut token spend.4---56# Token-Efficiency Coach78Reads a Claude Code session transcript and coaches the user on **token waste** — the9observable inefficiencies (uncached context, context bloat, oversized tool output,10failed tool calls, output-heavy turns, wrong-tier routing, redundant reads) — with a11per-finding fix and a dollar estimate. It flags *waste*; it never grades work *quality*12or scores a person. The analyzer runs locally and reads only your own session log, so13no prompt leaves your machine.1415The report below is generated at command time by the shared engine (`scripts/analyze.py`),16which auto-finds the latest session for this project when no path is given, or analyzes17the path you pass as an argument.1819## Coach report20!`python3 "${CLAUDE_PLUGIN_ROOT}/scripts/analyze.py" $ARGUMENTS`2122## Your task231. **Relay the ranked report above to the user** in your own words — lead with the24 headline (total cost, the single biggest recoverable amount) and then the findings25 in priority order. Keep dollar figures framed as upper-bound estimates, exactly as26 the engine does. Do not invent numbers the report did not produce.272. **Offer to apply the top fix.** Pick the highest-severity finding and propose the28 concrete remedy it implies, for example:29 - *Low cache hit* → restructure the session so stable context (system prompt,30 instructions, pinned files) sits at the FRONT and stays byte-identical so it caches.31 - *Context bloat / very long thread* → compact the conversation or split the remaining32 work into a fresh session to shed dead context.33 - *Oversized tool output / redundant reads* → read targeted line ranges, grep for the34 lines needed, and pipe noisy commands through head/tail instead of dumping whole files.35 - *Everything on the priciest model* → route mechanical steps (renames, greps,36 boilerplate, file reads) to a cheaper tier and reserve the top model for real reasoning.373. **Offer to wire up the live statusline** if the user does not already have one. The38 plugin ships `scripts/statusline.py` (live `$cost · ctx tokens · cache-hit% · ⚠`),39 but a plugin cannot register a `statusLine` itself — it must go in the user's40 `~/.claude/settings.json` pointing at a stable copy of the script. If they say yes,41 walk them through the README's "Wire up the statusline" steps (copy the script to a42 stable path, add the `statusLine` block, accept the trust dialog).4344If the report says no waste patterns tripped, congratulate the user on a clean session45and skip the fix offer (the statusline offer may still apply).4647## Notes for maintainers48- All detection logic lives in `scripts/analyze.py` (the single engine). This command49 adds **zero** analysis logic — it only injects the engine's output and relays it.50- Waste patterns + coaching copy live in `scripts/patterns.json`; prices in51 `scripts/prices.json`. Edit those, not this file, to tune behavior.52- `${CLAUDE_PLUGIN_ROOT}` is substituted in skill content for plugin skills, so the53 engine path above resolves to the installed plugin's `scripts/analyze.py`.