Token Optimisation for AIOS
Most Claude Code users burn 60–90% more tokens than needed. Defaults are the problem, not you. Four levers — none costing anything — can get your ratio above 2x and keep sessions running longer before you hit caps.
Why Optimise on a Flat Plan?
Your bill doesn't drop when you optimise tokens on a subscription. So why bother?
Because the win you feel is real: "I don't hit the weekly cap anymore"
and "sessions last longer." Every token saved delays throttle, extends context
before /compact, and becomes real dollars the moment you exceed caps or switch to API.
(4 months)
ccusage read your local JSONL logs
and multiply every token by its API rate. The $3,053 figure is what those tokens would have cost
on pay-per-token API billing — a hypothetical comparison, not a bill. It's how you measure the value
flowing through your flat-rate plan.
- $20 / $100 / $200 per month, fixed
- 5h rolling session window + weekly cap
- Bill doesn't move with token count
- Win = sessions run longer, caps hit less often
- Every token has a price — linear cost
- No caps — but bill can balloon fast
- Where ccusage shadow prices come from
- Savings become real the moment you exceed subscription caps or switch to API
The 4 Levers — All Free, All Stack
Four tools that work together. None cost anything. Installing all four takes about 90 minutes. If you only do one thing: install RTK. Five minutes, immediate win.
The Baseline settings.json — 2-Minute Change
Copy this into ~/.claude/settings.json. If you copy nothing else from this
workshop, copy this. It changes four defaults that are costing you tokens on every prompt.
"model": "sonnet",
"env": {
"MAX_THINKING_TOKENS": "8000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "60",
"CLAUDE_CODE_SUBAGENT_MODEL": "haiku",
"CLAUDE_CODE_EFFORT_LEVEL": "medium"
}
}
| Line | Why it matters |
|---|---|
| model: sonnet | Sonnet 4.6 matches Opus 4.6 on most coding at ~1/5 the input price. Escalate per-task with /model opus or /model opusplan when you actually need reasoning. |
| MAX_THINKING_TOKENS: 8000 | Default is 31,999. This single setting gives ~70% thinking-cost reduction. Thinking bills at output rate — most tasks don't need 32k thinking tokens. |
| CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: 60 | Default fires at 95% — by then you've already paid for everything. Compact at 60% for cleaner context and earlier refresh. Reframe: autocompact is a failure mode, not a safety net. |
| CLAUDE_CODE_SUBAGENT_MODEL: haiku | ~80% cheaper on Task tool calls. Haiku handles most subagent work fine. The savings compound fast on any workflow using parallel agents. |
| CLAUDE_CODE_EFFORT_LEVEL: medium | Prevents unexpected xhigh thinking spikes on Opus 4.7. Critical if you're using Opus 4.7 for anything — without this, thinking can explode unexpectedly. |
.claudeignore — 50-70% Less File-Scanning Waste
Without a .claudeignore at workspace root, every grep walks node_modules,
every Read can pull a lockfile. Add this file and eliminate low-signal bulk from every scan.
node_modules/
.git/
.venv/
dist/
*.lock
*.log
data/*.db
outputs/playwright/
.claudeignore
has 60+ patterns sectioned by category. Consider adding an /optimize-context skill
that scans your repo for large/low-signal files and suggests new patterns to add.
Every pattern you add is tokens saved on every scan, forever.
Cache Economics — The "Free Money" Lever Nobody Uses
Prompt caching is automatic in Claude Code — you don't enable it, you just need to not break it. The economics are stark enough that understanding them changes how you work.
- Cache write: $10/MTok — one-time cost to write a prefix to cache.
- Cache hit: $0.50/MTok — 10x cheaper than fresh input ($5/MTok). For a session-length of work, one write amortises across the whole thing.
- 1-hour TTL now available (April 2026) — alongside the 5-minute TTL. Use 1h TTL for long sessions to avoid cache expiry mid-flow.
- What breaks cache: Rewriting CLAUDE.md or system prompts mid-session. Adding new text before existing cached content. Don't modify the prefix during a session — any change forces a full re-tokenize and re-write.
- Cache miss from idle: Pause >5 minutes (with 5-min TTL) and the prefix re-tokenizes. Fix: don't pause mid-flow on the default TTL. Or switch to the 1h TTL for long sessions.
2026 Pricing Cheat Sheet
5× cost delta between Opus and Sonnet on input. The decision of which model to use is not aesthetic — it has direct financial consequences. Pick deliberately.
| Model | Input / MTok | Output / MTok | Best for |
|---|---|---|---|
| Haiku 4.5 | $1 | $5 | Subagents, greps, simple lookups |
| Sonnet 4.6 ★ | $3 | $15 | Default. Coding, refactoring, routine tasks. Matches Opus 4.6 on most coding. |
| Opus 4.6 | $15 | $75 | Complex architecture. Legacy but still active. |
| Opus 4.7 | $5 | $25 | Heavy reasoning — but ~35% tokenizer inflation vs 4.6. Always pair with EFFORT_LEVEL=medium. |
Model Routing — The Right Tool Per Task
| Task | Command | Why |
|---|---|---|
| Planning / architecture | /model opus | Complex reasoning needs the bigger model. Use it deliberately for this phase only. |
| Execution / coding | /model sonnet | Default. Sonnet matches Opus on most coding at 1/5 the cost. |
| Plan then execute in one session | /model opusplan | Plans in Opus, executes in Sonnet. ~40% cheaper than staying on full Opus throughout. |
| Subagents (Task tool) | SUBAGENT_MODEL=haiku | ~80% cheaper. Set once in settings.json, applies to every subagent call automatically. |
The Live HUD — See It to Save It
The psychological shift from "I wonder how much I've spent" to "I have $5.80 left today" changes behaviour more than any config tweak. Install the status line so you can see burn rate in real time.
npx ccstatusline@latest
"statusLine": {
"type": "command",
"command": "npx -y ccstatusline@2.2.8",
"padding": 0
}
- ccstatusline — 1.1K stars, interactive TUI. 25+ widgets: model, context %, session cost, daily cost, 5h block burn, git state, token counts. Auto-wires into settings.json.
- ccusage — 13K stars, the data layer ccstatusline runs on. Accept the install prompt when you run ccstatusline for the first time.
- cc-budget (optional) —
npm i -g cc-budget. Sets a hard daily cap with traffic-light readout. 25 stars — bleeding-edge, not a core recommendation. Start with ccstatusline + ccusage; add cc-budget when you want a hard cap.
RTK + context-mode — The Two Plugins That Matter
RTK — strips raw tool output before it enters context
brew install rtk
rtk init -g --hook-only
rtk gain # check your savings
--hook-only. Without it, RTK adds ~400 tokens per prompt
and defeats the entire purpose. This is the most common installation mistake.
- ~89% of CLI noise tokens stripped (community-validated). Works via PreToolUse hook — every Bash call is auto-optimised with zero friction.
- 68% total input-token reduction over 8,865 commands = 13.5M tokens saved across 6 weeks of real usage.
context-mode — sandboxes tool output, preserves state
- Claude plugin / MCP server. Tool output goes to a sandbox — not the main context. Queryable via
ctx_searchandctx_executewhen the AI needs to reference it. - One 5.4h session (76 calls): 1.5 MB processed, 857 KB stayed in sandbox — never hit context. 56% token reduction. 105 items preserved across compactions.
- Solves the "context loss after /compact" problem. Items in the sandbox survive compaction and are available when referenced.
Habits — No Config Fixes a Bad Habit
/clear between phases is the most impactful single habit change.8 Spike Patterns — Know What's Bleeding You
CLAUDE.md Budget — Every Line Costs Every Turn
CLAUDE.md is loaded on every single prompt. Every line you add costs tokens on every message for the life of the session. Treat it as an index, not a dump.
.claude/rules/, skill SKILL.md, or docs/.
CLAUDE.md just needs enough to orient Claude — workspace structure, available commands,
and a few pointer lines. Nothing more.
One-Time Setup — 90 Minutes Total
Order matters: settings.json first (free, immediate), RTK second (5 min), context-mode third.
~/.claude/settings.json with the baseline config above2 minutes. Immediate impact on every session..claudeignore to workspace rootCopy the block from Section 05. Grow it over time.Measure weekly:
Per-session habits:
/clear between phases (explore → implement)What to Remember
Expected results after full implementation: sessions run ~2.5× longer before hitting limits, ~60–70% overall token spend reduction, better quality in long sessions, ratio above 2× on the paid vs API-equivalent comparison.
Tools Referenced
- RTK: rtk-ai.app —
brew install rtk && rtk init -g --hook-only - context-mode: github.com/mksglu/context-mode
- ccusage:
npm i -g ccusage(13K stars) - ccstatusline: github.com/sirmalloc/ccstatusline (1.1K stars)
- cc-budget: github.com/boyand/cc-budget (optional hard cap, 25 stars)
- Questions: valera@aaaaccelerator.com
handout-token-optimisation.md) and
slides PDF (handout-slides.pdf) were distributed with the original workshop.
The handout is the definitive reference — copy-paste ready config blocks, all checklists,
and pricing tables in one document for use inside your Claude Code workspace.