You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(framework): conform token-optimization recipe to recipe contract
Align the recipe with references/recipe-contract.md: drop the Time row
(no longer in the template), name the section "Steps to <outcome>" instead
of a bare Steps, remove the "ranked by impact" filler line, and give each
step how-bullets plus a concrete example.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|**Prerequisites**| An AI coding assistant (Claude Code, GitHub Copilot, Codex, Cursor, …); a terminal |
10
9
11
10
## Why
12
11
13
-
Tokens are the bill. Every turn re-sends your context window — instructions, file reads, command output, the model's own narration — and you pay for all of it, every time. Most of it is waste: filler prose, noisy logs, stale context, oversized instruction files. The tips below attack each source. Stack them and large savings are realistic; every percentage here is **as reported by the tool**, not an independent benchmark.
12
+
**Token usage** is the bill. Every turn re-sends your whole **context window** — instructions, file reads, command output, narration — and you pay for it again. Most of it is waste: filler prose, noisy logs, stale context, bloated instruction files. Reach for this recipe when **cost** climbs faster than output.
14
13
15
-
> **Measure before you optimise.** You cannot cut what you do not see.
14
+
## Steps to cut token usage
16
15
17
-
##Best tips
16
+
### 🟢 Beginner
18
17
19
-
Ranked by impact-to-effort. Start at the top.
18
+
#### 1) 📊 Measure first
20
19
21
-
#### 1) Measure first
20
+
You cannot cut what you cannot see, so find what fills the window before changing anything.
22
21
23
-
You cannot improve what you do not track, and the bill is rarely where you think — cache reads usually dominate, not generation.
24
-
25
-
- In Claude Code: `/context` shows what fills the window, `/cost` shows the session cost and plan usage, `/insights` reports your session patterns and friction points.
26
-
- For a per-prompt breakdown across every session, use [`prompt-analytics-for-claude-code`](https://github.com/romainfjgaspard/prompt-analytics-for-claude-code).
22
+
- Built-in: run `/context`, `/cost`, and `/insights` in Claude Code.
23
+
- Cross-session detail: install [`prompt-analytics-for-claude-code`](https://github.com/romainfjgaspard/prompt-analytics-for-claude-code) and run it with `uvx`.
before: "Great question! Let me walk you through each of the steps involved…"
65
+
before: "Great question! Let me walk you through each step involved…"
54
66
after: "3 steps:"
55
67
```
56
68
57
-
#### 4) Filter noisy command output
69
+
#### 5) 🧹 Filter noisy command output
58
70
59
-
Test runs, installs, and build logs flood the context with lines the model never needs.
71
+
Test, install, and build logs flood context with lines the model never needs.
60
72
61
-
- A CLI proxy strips them before they land: [`RTK`](https://github.com/rtk-ai/rtk) (Rust) or [`SNIP`](https://github.com/edouard-claude/snip) (Go, YAML filters). Both report 60–90% on noisy output, zero overhead when no filter matches.
73
+
- Install a CLI proxy: [`RTK`](https://github.com/rtk-ai/rtk) (Rust) or [`SNIP`](https://github.com/edouard-claude/snip) (Go, YAML filters).
74
+
- Run noisy commands through it; it keeps only the signal (reported 60–90%).
62
75
63
76
```bash
64
77
$ rtk proxy npm test
65
78
# full build log in → only failures + final summary kept
66
79
```
67
80
68
-
#### 5) Prefer CLI over MCP
81
+
#### 6) 🔌 Prefer CLI over MCP
69
82
70
-
An MCP server loads its full tool schema into **every** turn; a CLI call costs a few tokens only when you use it.
83
+
An MCP server loads its full schema every turn, while a CLI costs tokens only when called.
71
84
72
-
- Reach for the CLI when one exists; keep MCP for what truly needs it. See [`mcp-installation.md`](mcp-installation.md).
85
+
- Use the CLI when one exists (`gh`, `acli`, …); keep MCP for what has none.
86
+
- See [`mcp-installation.md`](mcp-installation.md).
73
87
74
88
```bash
75
-
$ gh pr list # a few tokens per call
76
-
# vs a GitHub MCP server: its whole schema rides along every turn
89
+
$ gh pr list # a few tokens per call, vs a GitHub MCP schema riding along every turn
77
90
```
78
91
79
-
#### 6) Use progressive disclosure
92
+
###🔴 Expert
80
93
81
-
Don't paste big procedural docs into context. Load knowledge only when the task needs it.
94
+
#### 7) 📚 Use progressive disclosure
82
95
83
-
- Install an AIDD framework so skills, rules, and runbooks load on demand instead of riding along every turn.
96
+
Load knowledge only when the task needs it, instead of riding along every turn.
97
+
98
+
- Install an AIDD framework so skills, rules, and runbooks load on demand.
84
99
85
100
```text
86
101
skill description matched → its steps load
87
102
no match → 0 tokens spent
88
103
```
89
104
90
-
#### 7) Compact deliberately
91
-
92
-
Auto-compaction fires late and may drop what you wanted kept.
93
-
94
-
- Run `/compact` around 60–70% context, passing focus instructions for what to retain.
95
-
96
-
```bash
97
-
$ /compact keep the repro steps and the failing test; drop the file dumps
98
-
```
99
-
100
-
#### 8) Route by difficulty
105
+
#### 8) 🎯 Route by difficulty
101
106
102
-
The top model on a routine task is wasted spend.
107
+
The top model on routine work is wasted spend.
103
108
104
-
- Send research and routine work to a cheaper/faster model or a fresh subagent context; reserve the strongest model for the hard reasoning.
109
+
- Send research and boilerplate to a cheaper model or a fresh subagent.
110
+
- Reserve the strongest model for hard reasoning.
105
111
106
112
```text
107
113
research / boilerplate → small model or subagent
108
114
architecture / tricky bug → top model
109
115
```
110
116
111
-
#### 9) Cap extended thinking
117
+
#### 9) ✅ Cap extended thinking
112
118
113
-
Extended reasoning can silently add thousands of tokens per turn on tasks that don't need it.
119
+
Extended reasoning can silently add thousands of tokens on tasks that don't need it.
114
120
115
-
- Control it with `MAX_THINKING_TOKENS` in your settings — set `0` to turn extended thinking off when you don't need it. See the [Claude Code settings docs](https://code.claude.com/docs/en/settings).
121
+
- Set `MAX_THINKING_TOKENS` to `0` for routine work.
122
+
- See the [Claude Code settings docs](https://code.claude.com/docs/en/settings).
116
123
117
124
```bash
118
125
# settings.json (env)
@@ -121,9 +128,9 @@ Extended reasoning can silently add thousands of tokens per turn on tasks that d
121
128
122
129
## Verify
123
130
124
-
- Run `/cost`(or `prompt-analytics summary`) before and after a typical task — the token count should drop measurably.
131
+
- Run `/cost` before and after a typical task — the token count drops measurably.
125
132
-`/context` shows your instruction file and tool schemas taking a smaller share of the window.
126
-
- A noisy command (test suite, `npm install`) routed through RTK or SNIP returns far fewer lines than the raw run.
133
+
- A noisy command routed through RTK or SNIP returns far fewer lines than the raw run.
0 commit comments