Skip to main content
Code Guide
T20 Intermediate Technical

Token Optimization

Reducing token consumption without losing quality

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-ai/tap/rtk
# or: cargo install rtk
# Initialize in a project (sets up the hook automatically)
rtk init

Measured Savings

CommandWithout RTKWith RTKReduction
git log13,994 chars1,076 chars92%
git status100 chars24 chars76%
vitest run~50,000 chars~5,000 chars90%
pnpm list~8,000 chars~2,400 chars70%

A 30-minute session with 10-15 git commands drops from ~150K to ~41K tokens, a 72% reduction on that item alone.

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 the conversation history and frees roughly 40-50% of used context, without losing the thread of the session. Use it proactively at 70% usage, not as an emergency measure at 90%.

/compact # Summarize the current session

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

.claudeignore: Excluding Noise

node_modules/
.next/
dist/
*.lock
coverage/

Without this file, Claude may read thousands of irrelevant files during a global search, consuming context unnecessarily.

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:

ActionEstimated tokens
Reading a large file (2000 lines)~5K+
MCP call (Serena, Context7)~2K per call
Long conversation without /compactAccumulation
Tests with full unfiltered output3K-10K

Combined Strategy

RTK reduces the cost of bash commands (preventive). /compact frees up context mid-session (curative). .claudeignore avoids unnecessary reads (structural). These three levers are complementary and apply in parallel.

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: