Backend Foundation

Token Economy

Six levers to reduce context window bloat — from Caveman Mode to RTK. Real reduction: 35k tokens → 9k on the same task.

Why It Matters

Token bloat kills session quality

Every token in the context window is re-read by the model on every generation step. A bloated context means: slower responses, higher cost, and — critically — lower quality as the model loses focus on the signal amid the noise.

Measured result: Applying the 6 token economy levers to a standard backend task reduced context from 35,000 tokens to 9,000 tokens — a 74% reduction — with equivalent or better output quality.

Token economy is not about being cheap. It's about keeping the model's attention on what matters. A tight context produces sharper, more relevant code than a sprawling one.

Levers 1–3

Scope, structure, and silence

LeverDescription
1. Narrow scopeRead only the files needed for this task. Avoid "read the whole repo first" habits.
2. Structured CLAUDE.mdShort bullet instructions beat long paragraphs. Every word in CLAUDE.md enters every session.
3. No verbose outputInstruct Claude to return diffs, not full files. "Show me what changed" costs 10x less than "show me the file."
# CLAUDE.md lever 3 example:
"When editing files, show only the changed blocks — not the full file.
Use unified diff format where possible."
Lever 2 compounds: a 500-token CLAUDE.md versus a 2,000-token one costs 1,500 tokens per message. On a 20-message session that's 30,000 tokens wasted.
Levers 4–6

RTK, Caveman Mode, and clear context

LeverDescription
4. RTK (Read-Think-Know)Before reading a file, state what specific information you need. Don't read whole files to find one function.
5. Caveman ModeCompress your prompts. Drop articles, filler, pleasantries. "Fix auth bug in login.py line 42" beats a paragraph.
6. Clear context checkpointsRun /clear to wipe the conversation and start fresh when the current context grows stale. Carry forward only what's needed (your CLAUDE.md + the task).
Caveman Mode example:
Before: "Hey Claude, could you please take a look at the authentication module and see if you can figure out why the login is failing for users?"
After: "auth broken — users can't login — check auth/login.py"
Token count: 32 vs 9. Same information.
Measuring Progress

Track your token budget

Use the /usage command in Claude Code to see current session token consumption. A well-managed backend session should stay under 15k tokens for a focused task. If you're consistently above 25k, review which levers you're not applying.

Session typeTarget tokensWarning zone
Focused bug fix< 8k> 15k
Feature implementation< 15k> 25k
Architecture review< 20k> 35k
Multi-file refactor< 25k> 45k
When you hit the warning zone, don't push through — start a new session. Carry forward: your CLAUDE.md, the specific task, and the last 3–5 relevant decisions. Leave everything else behind.
Compaction — /clear vs /compact

Two built-in commands for a bloated window

When a session grows stale you have two built-in tools. Reach for the right one: /clear when you're done with the current thread, /compact when you need to keep going but the window is full.

CommandWhat it doesUse when
/clearWipes the conversation entirely — a clean slate. CLAUDE.md and project files reload; the chat history does not.Switching to a new task. Cheapest possible context.
/compactSummarises the conversation so far into a compact digest and continues from it — keeps the thread, drops the token weight.Mid-task, window filling up, but you still need what was decided.
Auto-compactionClaude Code compacts automatically as you approach the context limit, so a long session degrades gracefully instead of failing.Always on — but don't rely on it; a deliberate /clear between tasks is leaner.
Rule of thumb: new task → /clear. Same task, full window → /compact. A summary always loses some detail, so push durable facts to CLAUDE.md / docs/ before you compact.
Third-Party Tools

RTK, repomix, and Graphite

Beyond the built-in levers, a few external tools cut tokens or keep large changes reviewable. Use them when the built-ins aren't enough.

ToolWhat it doesWhen to reach for it
RTK (Rust Token Killer)A pre-tool hook that strips noise (comments, blank lines, lockfiles) from what Claude reads. Covered as Lever 4 above.Every session — it pays for itself immediately.
repomixPacks a whole repo (or a subset) into a single, token-counted file, so you can hand Claude a curated snapshot instead of letting it crawl the tree.Onboarding Claude to a large/monorepo codebase, or sharing repo context with an external model.
GraphiteStacked-PR tooling: splits one big change into a stack of small, individually-reviewable PRs.When AI-assisted work produces a large diff — keep review (and blame) sane by stacking it.
These are optional. Master the six built-in levers and /clear / /compact first — most sessions never need more. Reach for repomix and Graphite specifically when the codebase or the diff is large.
Check your understanding
1. What does "Caveman Mode" refer to?
Correct.Not quite. Caveman Mode means stripping prompts to the minimum — drop articles, filler, pleasantries. "Fix auth bug login.py line 42" beats a full paragraph every time.
2. Why is a verbose CLAUDE.md especially costly?
Correct.Not quite. CLAUDE.md enters every session. A 1,500-token bloat × 20 messages = 30,000 wasted tokens. Keep it tight.
3. What token reduction was achieved by applying the 6 levers on a standard backend task?
Correct.Not quite. Applying all 6 levers reduced context from 35k to 9k tokens — a 74% reduction on the same task with equivalent output quality.