Token Saver
Everything in context is re-sent on every later turn — the cheapest token is the one never loaded. Priority: correctness > quality > security > efficiency > tokens. Before each step: does it move the result forward or make it safer? No → skip it.
1. Size the task (internally, before the first tool call)
- Done-criterion: one checkable sentence ("test X passes", "button centred on mobile").
- Minimal path: the files/spots that must change — read only those.
- Smallest reliable check that proves the criterion.
| Tier | Typical | Read | Tests | Subagents |
|---|---|---|---|---|
| A trivial | typo, one config value | target spot, 1–3 tool calls | check the change directly | never |
| B simple | small style fix, one function | + direct callers | 1 targeted check | never |
| C normal | feature, API integration, related files | affected files | affected tests | broad search only |
| D complex | hard bug, larger refactor | + dependencies | affected + adjacent | if real benefit |
| E very complex | architecture, system issue | + side effects | full relevant suite | second opinion OK |
Data loss, security, auth, payments, production, migrations, irreversible actions → at least +1 tier.
2. Reuse before fetching
- Already in context (file, output, answer) → use it. Don't re-read, re-run or re-ask.
- Resuming / long task:
git status -s,git log --oneline -10,git diff --statshow what's done. Build on existing code and commits; never redo finished work. - Unsure → search locally first (README, docs, config, tests, existing code, CLAUDE.md). Ask only if still unresolved and it matters — one short question, not several built variants.
- Web only when local sources can't answer; WebFetch with a precise
prompt, never raw HTML via curl. - Reuse the codebase's patterns, utils and libraries instead of writing new ones.
3. Search
- Grep/Glob tools, not
grep -r/find. Don't install new tools for one-off searches. - Count first (
output_mode: count/files_with_matches); fetch content only when hits are few. - Narrow with
type/glob+path; exclude node_modules, dist, build, vendor, .venv, *.min.js, lockfiles. Sethead_limit, context ≤ 3 lines. - Batch: one regex (
foo|bar); independent calls in parallel in one message.
4. Read
- Normal source file → Read directly. Likely large (logs, data, generated, > ~300 lines) →
wc -l, Grep for line numbers, Read withoffset/limit. - Never read lockfiles, minified/build output, binaries. Big JSON/CSV → inspect structure by script (keys, length, first 3 rows).
- Files via Read, not
cat/head/tail(piping command output through them is fine). - Expand only on concrete cause: error points elsewhere · assumption disproved · side effect found · tier rises. No "just in case" reads, no re-surveying the project after each step.
5. Cap tool output
| Purpose | Instead of | Use |
|---|---|---|
| git | git status / git diff / git log |
git status -s / git diff --stat then git diff -- file / git log --oneline -10 |
| install | npm install |
npm i --silent --no-audit --no-fund 2>&1 | tail -5, pip install -q |
| tests | full verbose suite | one file: pytest -q -x path, vitest run file --reporter=dot, jest file --silent |
| build/logs | everything | 2>&1 | grep -iE "error|warn|fail" | head -30 |
| HTTP | curl url |
curl -s -o /dev/null -w "%{http_code}" or | head -c 1500 |
| processes | ps aux |
pgrep -fl name |
Success needs no output (-q, --silent, >/dev/null && echo OK). Unknown length → | wc -l first or cap with head/tail.
6. Change
- Minimal and surgical: only what the task needs, match existing style. No unrequested features, abstractions, refactors, docs or config files. New tests only for risky changes or where the project convention expects them.
- Edit over Write for existing files. Don't re-read after Edit/Write — the tool errors if it failed. Don't repeat changed code in chat.
- Long task → phases, each with its own check. Commit after each verified phase when the user or project workflow wants commits.
7. Debug
- Reproduce with the smallest command — one test, one request.
- Error message + topmost own stack frame first; read only that spot.
- One hypothesis → one targeted check → fix directly. No shotgun edits, no long deliberation.
- Bisect instead of reading:
git bisect, halve the code or the input. - Remove debug prints after the fix.
8. Escalate, don't loop
- 2 targeted attempts failed, or unexpected dependencies / more files / architecture or security question → tier +1, one line:
↑ D — reason. - Still failing after escalating → stop; report state + hypotheses.
- Simpler than expected → finish now.
9. Models & subagents (Claude Code)
- Main session model/effort can't be switched by Claude — only recommend (
/model opus,/effort high), and only at D/E on a weaker model. Switching drops the prompt cache: not worth it for A/B. Before risky or irreversible D/E steps, wait for the switch. - Subagent only for independent parallel subproblems, broad searches where raw data ≫ conclusion, or a genuine second opinion. Self-contained prompt; ask for the conclusion, not dumps.
- Always set
modelper subtask, as alias: search/collect →haiku· implement/review →sonnet· hard analysis →opus.
10. Communicate & finish
- During autonomous work: no narration between tool calls, no restating the plan or what tools just showed.
- Criterion met + verified → stop. No polishing, bonus checks, or re-running unchanged tests.
- Report: result + open points in 1–3 lines.
- Long session → suggest
/compact <focus>; unrelated new topic →/clear./contextshows what fills the window.
Never cut to save tokens
Verification of the core result · tests for risky changes · security checks · secret scan before commits · confirmation before irreversible actions · completeness of what was asked.