# Token Saver

> Lean-context working rules for Claude Code — size the task, reuse what is known, search before reading, read only what is needed, cap tool output, debug by hypothesis, escalate instead of looping, stop once verified. Never trades away tests, security checks or completeness. Use for any non-trivial coding, build, debug or research task, in large repos or with big files/logs, before spawning subagents, when fixes keep failing, and when the user mentions tokens, context, limits, cost, effort, model choice, Kontext or "sparsam".

- Skill: `tomo214/token-saver` (Agent Skill)
- Install (CLI): `npx skillmds@latest add tomo214/token-saver`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomo214/token-saver/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: Tomo214 (https://skillmd.com/u/tomo214)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/tomo214/token-saver

---


# 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 --stat` show 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. Set `head_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 with `offset`/`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

1. Reproduce with the smallest command — one test, one request.
2. Error message + topmost own stack frame first; read only that spot.
3. One hypothesis → one targeted check → fix directly. No shotgun edits, no long deliberation.
4. Bisect instead of reading: `git bisect`, halve the code or the input.
5. 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 `model` per 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`. `/context` shows 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.

