Skip to main content
OCT 2026 Latest guide updates. Latest: Mistral Large 4 AI FinOps Lean & AI Changelog →
T20 Intermediate Technical

Token Optimization

Reducing token consumption without losing quality

PDF editions · Guide v3.44.1 · Updated

PDF
← All cards

RTK: Upstream filtering

RTK (Rust Token Killer) intercepts command outputs before they enter Claude’s context. It is not a post-hoc summary, it is a filter that eliminates structurally redundant noise.

Terminal window
# Installation
brew install rtk
# or: cargo install --git https://github.com/rtk-ai/rtk
# Inspect configuration changes before installing the integration
rtk init --dry-run
rtk init

Measure output reduction

Compare equivalent commands on the same repository state, inspect failures, and use rtk gain for local estimates. Smaller shell output is only one contributor to token usage; it does not establish an equal reduction in the total bill. RTK estimates token counts rather than running the model’s tokenizer. See the RTK savings explanation.

Essential RTK commands

Terminal window
rtk git status # Condensed git
rtk git log # Clean log output
rtk cargo test # Filtered Rust tests
rtk vitest run # Condensed JS tests
rtk gh pr view 123 # Optimized GitHub PR
rtk gain # Savings dashboard

Compact: Freeing up context

/compact summarizes conversation history. The recovered space varies and details can be lost; preserve decisions and next steps in files and inspect /context before continuing.

/compact # Summarize the current session

The difference from /clear: compact preserves session continuity, clear starts from scratch.

Limit reads and search scope

Claude Code does not document a native .claudeignore mechanism. Name the relevant directories in requests. Where access must be blocked, use permission rules in .claude/settings.json, for example:

{
"permissions": {
"deny": ["Read(./node_modules/**)", "Read(./dist/**)"]
}
}

Review shell and MCP access separately. These rules are access restrictions, not a ranking hint for search. See permission patterns.

Efficient prompt rules

Target, don’t load:

  • “Check the login function in auth.ts:45-60” rather than “Check auth.ts for issues”
  • Reference symbols (calculateTotal) rather than entire files
  • Avoid pasting large JSON blobs or raw logs into the prompt

What consumes the most:

ActionWhat to measure
Reading a large fileReturned text size
MCP callTool schemas and returned result
Long conversationHistory retained in context
Test runOutput returned, including failures

Combined strategy

Filter verbose shell output, compact when useful, and restrict reads to relevant sources. Verify the resulting output still contains the evidence needed to complete the task.

Disclosure: the author of this guide is a core contributor to RTK.

Whole-task measurements of RTK alone differ by study: JetBrains measured +7.6% median cost per task at low reasoning effort and +0.1% at high effort, Dasein +13% total cost, THOL +7.1% with an interval that crosses zero, and Codepointer’s replay -0.5% of spend. RTK’s maintainers dispute the JetBrains design and report -4.8% on 13 dev tasks (p = 0.305) in their own re-run. Details: https://cc.bruniaux.com/token-savings/

Enter your email to read the full card and get the complete PDF bundle.

All content is free and open-source. We just ask for your email.

PDF: