AI Coding Agents
Token Optimizer Review: Auditing Ghost Tokens Before You Compress
alexgreensh/token-optimizer is a zero-dependency Python plugin that audits and fixes structural token waste (bloated configs, unused skills, stale memory, model misrouting, retry loops) alongside the usual command-output compression, all tracked in a local SQLite ledger and dashboard. The project reports $597.72 in API-rate-equivalent value over 30 days. Logged token changes account for $78.59, with the remaining $519.13 modeled or estimated.
alexgreensh/token-optimizer takes a different bet from the compressors in this series. Its tagline, “Find the ghost tokens. Fix them. Survive compaction,” describes an audit-first philosophy: before shaving bytes off tool output, find the waste your agent never needed to create. The project argues that command output covers 15–25% of context while bloated configs, unused skills, stale memory, compaction loss, model misrouting and behavioral waste make up the rest, and it instruments all of it. As of November 30, 2026 it had 3,201 stars and 250 forks, only 4 open issues, and a release cadence that borders on continuous: v5.13.78 through v5.13.85 shipped inside the last week of November. One adoption caveat up front: the license is PolyForm Noncommercial (GitHub flags it as a non-standard assertion), so internal commercial use needs a license review first.
What it is and which cost layer it targets
The README splits waste into three kinds, which is the cleanest taxonomy in this category:
- Structural waste: oversized CLAUDE.md and MEMORY.md files, unused skills, stale memory entries, MCP tool definitions you never call. These tokens are re-sent every turn whether or not they ever help.
- Runtime waste: verbose command output, file re-reads, oversized tool results. This is the 15–25% the compressors target.
- Behavioral waste: model misrouting (expensive model on cheap tasks), cache expiry, retry loops, verbosity drift.
Token Optimizer covers all three. Its automatic layer includes Smart Compaction (checkpoints before auto-compact, restores after), Session Continuity (cross-session hints, cold-resume, checkpoint scoring), Active Compression (nine features on by default), a 7-signal quality score with letter grades, a 15-table SQLite session database, progressive disclosure for large tool results, a post-compaction Context Intel Digest, and model routing nudges. The on-demand layer is where the audit happens: /token-optimizer runs the full audit with guided fixes, /token-coach analyzes 30-day trends, route sizes the model and effort a task needs before you spend, doctor checks the install, savings and pilot-report produce dollar reports, memory-review audits MEMORY.md structure, and expand retrieves archived tool output.
How it works
PreToolUse hooks intercept every Read call: a file already read this session returns only the diff (the README says 65%+ of Read calls in real sessions are re-reads, and a 2,000-token re-read becomes ~50 tokens), while an unchanged code file re-read returns a structural skeleton; the README gives a 720 KB file becoming a 250-token skeleton as an example. The same README says v5.12 serves the target file in full on its first read and can inject skeletons for surrounding files. It illustrates search output shrinking from 500 lines to 20 and one pytest result shrinking from 564 tokens to 115. The command-output hook archives the original to disk, logs the event to SQLite, and is designed to preserve failure details.
Two design choices distinguish it. First, zero baseline overhead: it is an external process with no always-on instructions injected into context, no MCP server, no dependencies beyond the Python/TypeScript stdlib, and no telemetry. Second, cache-safety: it never modifies the existing context prefix, which is exactly the property that keeps provider prompt-cache economics intact (see context compression vs prompt caching).
The audit machinery is the real product. The session database keeps a full local audit trail; the dashboard (one HTML page regenerated after every session via the SessionEnd hook, plus an opt-in localhost server) shows per-turn token breakdowns, cost across four pricing tiers, cache TTL mix and hit rate, quality scores, subagent cost breakdowns, and a savings tracker that keeps metered and estimated tiers separate. A Claude Desktop “mod” status bar shows quality grade, context fullness, cache warmth and usage limits in the app itself.
Install and first run
On Claude Code, the recommended path is the plugin:
/plugin marketplace add alexgreensh/token-optimizer
/plugin install token-optimizer@alexgreensh-token-optimizer
Then run /token-optimizer once to set up hooks; everything after that is automatic. Two README gotchas worth repeating: enable auto-update for the marketplace (Claude Code ships third-party marketplaces with it off), and on Windows use the plugin install only, never install.sh.
Other clients: codex plugin marketplace add alexgreensh/token-optimizer for Codex, a token-optimizer-opencode plugins entry for OpenCode V2, openclaw plugins install github:alexgreensh/token-optimizer for OpenClaw, install.sh --hermes for Hermes, pi install git:github.com/alexgreensh/token-optimizer for Pi (then /token-optimizer enable), and install.sh --copilot, --cursor, --antigravity, --grok or --devin for those platforms. For claude.ai/code cloud sessions, python3 measure.py cloud-setup-script produces a setup script to paste into the environment. Uninstall is /plugin uninstall token-optimizer@alexgreensh-token-optimizer, and docs/uninstall.md covers per-runtime removal; the README calls the whole thing additive and reversible.
What it saves: the ledger, decomposed
The headline number is the project’s own 30-day snapshot ending November 1, 2026: $597.72 in “all-in API-rate-equivalent value” and 24.80M tokens saved, about 8% of the 311.02M tokens spent plus saved, across 1,644 main sessions and 3 delegated ones. The decomposition is the part worth reading carefully:
| Component | Amount | Evidence tier |
|---|---|---|
| Logged actions (4,945 metered events) | $78.59 | Metered |
| Model routing | $422.88 | Estimated (frozen pre-tool mix, fixed reference model cards) |
| Repeat reads avoided | $60.69 | Modeled |
| Other estimates | $35.56 | Estimated |
| Total | $597.72 | 86.9% modeled or estimated |
So about 13% of the claimed dollar value is metered; the single largest component, model routing at $422.88, is an estimate built on counterfactual assumptions. The project deserves credit for labeling the tiers and for stating that pricing is incomplete (unpriced repeat-read credits and debits are excluded), but the honest way to cite the number is “the project reports $597.72, of which $78.59 is metered.” No independent benchmark exists; the comparison tables admit the end-to-end study is “a controlled A/B on 7 real tasks” and that “pass-rate study not yet run.”
Prompt-cache and extra-turn risk
The design is cache-safe by construction (no prefix modification), and the checkpoint/restore system targets a failure mode other tools ignore: savings evaporating when the host auto-compacts. The residual risk is behavioral: lean-output nudges and routing advice change what the model does, and the README marks those savings as “estimated, not counterfactually measured.” Loop detection and quality nudges add advisory text in some situations; on token-priced plans, extra advisory content is itself a small cost.
What the GitHub issues show
Four open issues as of November 30, 2026, and a closed list full of ordinary integration bugs fixed quickly:
- Closed issue #215 is titled “Token Optimizer Memory Leaks.”
- Issue #211: Electron child processes on the Claude desktop app were counted as sessions (16 reported, 3 real). Closed.
- The title of closed issue #18 reports a discrepancy in the dashboard’s Sonnet model mix.
- Issue #104: hooks flashed visible cmd.exe windows on Windows, leaving orphan conhost.exe processes. Closed.
- Issue #61: cross-project session/recall leakage on Windows. Closed; note it concerns session continuity, the feature most tied to privacy expectations.
- Issue #42:
install.shfailed on fresh installs due to missing CHECKSUMS.sha256 release assets. Closed; releases now verify checksums at install.
The open issue count of four on a 3,201-star repo suggests either efficient triage or a fast-close culture; either way, the visible record shows fixes shipping.
A cost example (estimate)
Assume a trial records 10 million fewer fresh Sonnet input tokens over a month. At $2 per million, the estimated input saving is 10 × $2 = $20. Price cache reads and writes separately using their own rates. The project’s local ledger is a way to check which actions it logged. Use provider usage to check the change in billed tokens. See the AI provider pricing index for current rates.
Who should use it, who should skip it
Try it if you:
- Suspect your waste is structural (fat CLAUDE.md files, dead skills, stale memory, wrong-tier routing) rather than just noisy command output
- Want the audit trail: SQLite ledger, per-component reports, 30-day trends, metered-vs-estimated separation
- Use Claude Code (deepest integration, including the desktop status bar), Codex, OpenCode, Hermes, Pi, Cursor or Copilot
- Can use PolyForm Noncommercial software (personal work, or after a license review)
Skip it if you:
- Need it for commercial use without a license conversation first
- Want an independently validated savings number; none exists
- Prefer a single-purpose compressor; this one wants to manage your whole token economy, hooks, database, dashboard and all
How to trial it safely
- Install the plugin, run
/token-optimizeronce, and read the audit before enabling anything else: it tells you where your ghost tokens actually live. - Run a normal week, then open the dashboard and check the metered tier of the savings report rather than the headline total.
- Compare provider-billed input and output totals against a baseline week per how to measure coding agent token savings.
- Exercise the compaction path deliberately: work until the host auto-compacts, then confirm the checkpoint/restore kept your session coherent.
- If you uninstall, the plugin removal plus
docs/uninstall.mdrestores the pre-install state.
Alternatives and next reads
- Headroom context compression review and RTK review: the compress-first tools this project positions itself against.
- token-optimizer-mcp review: a different project with a nearly identical name; hooks plus proxy plus MCP, MIT-licensed.
- Stacking token saving tools: how audit-first and compress-first layers combine without double-counting.
Sources
- alexgreensh/token-optimizer repository (GitHub, accessed 2026-11-30)
- token-optimizer issue #215: memory leaks (GitHub, accessed 2026-11-30)
- token-optimizer issue #61: cross-project session leakage on Windows (GitHub, accessed 2026-11-30)
- token-optimizer issue #104: hooks flash cmd.exe windows on Windows (GitHub, accessed 2026-11-30)
- token-optimizer issue #18: dashboard under-reports Sonnet (GitHub, accessed 2026-11-30)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Token Optimizer Review: Auditing Ghost Tokens Before You Compress. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/token-optimizer-ghost-tokens-audit/