Module 13

Best practices for token optimization

Developer Tools How Claude Code Works

Module 13 — Best practices for token optimization

← Module 12 | Index | Next: Module 14 →


Every word Claude reads and writes is counted in tokens — small chunks of text (roughly ¾ of a word each). Tokens are the unit you’re billed in, and the unit that fills the context “desk” from Module 4. Optimizing tokens does two things at once: it saves money, and it keeps Claude sharp by not drowning it in noise. This module is the practical playbook.

First, a clarification that prevents confusion: token optimization is about quantity — using fewer tokens to get the same result. Context engineering (Module 14) is about quality — putting the right things in the window. They overlap, but think “cost/efficiency” here and “what to include” there.

Where tokens get wasted

Most waste comes from a few predictable places:

  • Stale conversation history. A long session carries every old message forward. After you’ve moved on, that history is dead weight being re-read on every turn.
  • Reading whole files when you needed ten lines. Pulling an entire 2,000-line file to check one function is the most common silent cost.
  • Bloated standing instructions. A CLAUDE.md that’s grown to hundreds of lines is paid for on every single turn of every session.
  • Dumping data into chat. Pasting a giant log, CSV, or JSON blob into the conversation when a file reference or a quick summary would do.
  • Re-deriving the same thing. Asking Claude to re-read and re-analyze material it already processed earlier.

The high-leverage habits

Clear between tasks. /clear is the single biggest token saver. It drops the entire accumulated history. When you switch topics, clear — you’re not just tidying, you’re cutting cost on every future turn.

Compact long sessions. /compact replaces a sprawling history with a short summary. You keep the gist and shed the bulk. Claude also auto-compacts, but doing it deliberately at a natural break is cheaper and cleaner.

Keep CLAUDE.md lean. Because it’s loaded constantly, it has the worst cost multiplier in the whole system. Ruthlessly prune it. Move rarely-needed detail into a skill or a reference file that’s loaded only when relevant (progressive disclosure, Module 5) instead of always-on instructions.

Let Claude read selectively. Trust the search-then-read pattern. Ask for the specific thing (“find the function that validates email”) rather than “read the whole file and tell me.” Point it at the right file or folder so it doesn’t search blindly.

Delegate bulk work to subagents. When a job means reading hundreds of files or a huge document, hand it to a subagent (Module 8). The subagent burns tokens on its desk and returns a small summary — the expensive reading never lands on your main context.

Reference files instead of pasting. Put large data in a file and tell Claude where it is. It reads what it needs, when it needs it, instead of carrying the whole blob in the conversation forever.

Ask for the output length you actually want. “Give me a one-line answer” or “just the code, no explanation” cuts output tokens directly. Verbose responses cost real tokens; request brevity when brevity is fine.

Batch related questions. Asking five related things in one well-formed message reuses the same loaded context once, instead of five turns each re-establishing it.

Model choice is a token-cost lever too

Not every task needs the strongest model. A fast, cheaper model handles routine edits, simple lookups, and formatting fine; reserve the powerful model for hard reasoning. In subagents you can even set the model per agent (Module 8) — a cheap model for the grunt-work researcher, a strong one for the reviewer.

A simple mental checklist

Before a long session, ask:

  • Am I starting clean, or dragging in unrelated history? → /clear
  • Is my CLAUDE.md earning its constant cost? → trim it
  • Is this a bulk-reading job? → subagent
  • Do I need the whole file, or a piece? → point precisely
  • Do I need a long answer, or a short one? → say so

None of this is about being stingy. It’s that a lean context is also a focused context — you save money and get better answers at the same time. That dual payoff is exactly why Module 14 picks up the “what to include” side of the story.


← Module 12 | Index | Next: Module 14 →