Reduce Claude Code token consumption through bidirectional compression,
intelligent skill tiering, model routing, and multi-backend memory.
Quick Start · Components · Memory · Evidence · Architecture · Credits
Claude Code consumes significant tokens per session. Major cost sinks:
| Source | Impact |
|---|---|
| CLI output (build/test/diff) floods context | Thousands of tokens per command |
| 150+ skill descriptions in system prompt | ~10K tokens/turn |
| Opus for all tasks, including simple searches | Top-tier model cost on trivial work |
| Maximum thinking budget on simple queries | Unnecessary thinking tokens |
| No cross-session knowledge persistence | Repeated context loading |
| Component | What It Does | Savings | Evidence |
|---|---|---|---|
| RTK | CLI output compression (smart filters per command) | 67-97% ✓ | Measured: 132 commands, 125.6K→4.3K tokens |
| LLMLingua | Input prompt compression via BERT (optional hook) | 2-5x † | Upstream claim, not independently measured |
| Skill Tiering | 23 always-on + 158 on-demand via skill-loader | ~8K tokens/turn ~ | Estimated: 181→23 skill descriptions |
| Model Routing | Sonnet/Haiku subagents for lightweight tasks | ~60% cost ~ | Estimated from public model pricing |
| Thinking Budget | effortLevel control (high default) |
~50% ~ | Estimated: high vs max effort |
| Hooks | Safety guard + test output filter | varies | 27 golden tests passing |
| .claudeignore | Exclude build artifacts, lock files, models | — | Prevents context pollution |
Evidence key: ✓ = measured locally · ~ = estimated from public data · † = upstream claim, not verified
|
Windows (PowerShell) git clone https://github.com/qiuxinyuan321/endurance-plan.git
cd endurance-plan
.\install.ps1 |
Linux / macOS / WSL git clone https://github.com/qiuxinyuan321/endurance-plan.git
cd endurance-plan
chmod +x install.sh && ./install.sh |
The installer automatically:
- Copies hooks and registers them in
settings.json - Registers MCP servers in
.claude.json - Deploys
.claudeignore - Runs skill tiering with backup
Restart Claude Code after installation.
Binary tool that wraps CLI commands and compresses output before it enters the context window.
rtk npm test # Compressed: only failures + summary
rtk err cargo build # Show only errors
rtk summary git log # AI-compressed summary
rtk gain # Show compression statisticsMeasured: 132 commands, 96.6% overall compression (125.6K→4.3K tokens). Per-command range: 20-100% depending on output type. See benchmark/results/rtk.json.
- Tier 1 (23 skills): Core coding, memory, search, communication, tools — always loaded
- Tier 2 (158 skills): Loaded on-demand by
skill-loaderwhen keywords match
Tiering Commands
python scripts/tier-skills.py # Apply tiering (creates backup first)
python scripts/tier-skills.py --dry-run # Preview changes
python scripts/rollback.py # Restore from backup| Agent | Model | Use Case |
|---|---|---|
research |
Sonnet | Codebase exploration, file search, doc lookup |
quick-task |
Sonnet | Simple code changes, formatting |
test-runner |
Haiku | Run tests, report pass/fail |
Python-based, injection-safe hooks (all JSON output via json.dumps):
| Hook | Type | What It Does |
|---|---|---|
safety-guard.py |
PreToolUse | Blocks rm -rf /, fork bombs; warns on --force |
filter-test-output.py |
PreToolUse | Filters test output to failures + summary |
compress-input.py |
PostToolUse | LLMLingua-2 compression for large file reads (optional) |
All hooks have golden tests (27 test cases).
LLMLingua Input Compression (Optional)
pip install llmlingua # ~500MB model download on first runNote: Each hook invocation loads the 500MB model from scratch (~1-2s latency). This is a known limitation of the hook architecture. A daemon-based approach is planned for future versions.
graph LR
A["Core<br/>MEMORY.md<br/><200 lines"] --> B["Recall<br/>Topic Files<br/>On-demand"]
B --> C["Vector<br/>AIVectorMemory<br/>Semantic Search"]
C --> D["Graph<br/>MemoryGraph<br/>Relationships"]
D --> E["Code Intel<br/>mnemex<br/>AST Index"]
style A fill:#4CAF50,color:#fff
style B fill:#2196F3,color:#fff
style C fill:#9C27B0,color:#fff
style D fill:#FF9800,color:#fff
style E fill:#F44336,color:#fff
| Tier | Backend | Best For | Dependency |
|---|---|---|---|
| Core | MEMORY.md (always loaded) | Quick index, <200 lines | None |
| Recall | Topic markdown files | Structured notes, on-demand Read | None |
| Vector | AIVectorMemory | Semantic search + issue tracking | Python + pip |
| Graph | MemoryGraph | Causal chains + multi-hop reasoning | Python + pip |
| Code Intel | mnemex | AST index + code references | bun + Ollama |
Memory Routing Guide
| Need | Tool |
|---|---|
| Store cross-session knowledge | AIVectorMemory remember |
| Semantic similarity search | AIVectorMemory recall |
| Track bugs/issues | AIVectorMemory track |
| Decompose tasks | AIVectorMemory task |
| Record causal relationships | MemoryGraph store_memory + create_relationship |
| Multi-hop reasoning | MemoryGraph get_related_memories |
| Code definitions/references | mnemex define / references / search |
Fallback: If MCP servers are unavailable, memory operations degrade to Recall tier (file-based). Operations never fail silently.
All claims are tracked in benchmark/CLAIMS.md with evidence status.
| Metric | Value | Method | Notes |
|---|---|---|---|
| RTK compression (overall) | 96.6% ✓ | Measured | 132 commands, single user workload |
| RTK compression (per-command median) | ~70% ✓ | Measured | Excluding 1 outlier (111K find output) |
| LLMLingua compression | 2-5x † | Upstream claim | Not independently measured |
| Skill tiering savings | ~8K tokens/turn ~ | Estimated | 181→23 skill descriptions |
| Model routing savings | ~60% cost ~ | Estimated | Opus→Sonnet/Haiku pricing delta |
| Thinking budget savings | ~50% ~ | Estimated | effortLevel high vs max |
| Hook test coverage | 27/27 ✓ | Measured | Golden test suite |
| Platform | Support Level | RTK | Hooks | MCP | Skills |
|---|---|---|---|---|---|
| Windows 10/11 | Full | ✓ | ✓ | ✓ | ✓ |
| Linux | Partial — no RTK | ✗ | ✓ | ✓ | ✓ |
| macOS | Partial — no RTK | ✗ | ✓ | ✓ | ✓ |
| WSL | Full via Windows host | ✓ | ✓ | ✓ | ✓ |
RTK is a Windows-only binary. On other platforms, all components except RTK work normally.
~/.claude/
├── CLAUDE.md # RTK + model routing + thinking budget + memory governance
├── settings.json # effortLevel, hooks registration
├── hooks/
│ ├── safety-guard.py # Block/warn dangerous commands
│ ├── filter-test-output.py # Filter test output
│ └── compress-input.py # LLMLingua compression (optional)
├── agents/
│ ├── research.md # Sonnet - codebase exploration
│ ├── quick-task.md # Sonnet - simple changes
│ └── test-runner.md # Haiku - test execution
└── skills/
└── skill-loader/ # On-demand skill routing
~/.claude.json # MCP server registrations (auto-configured)
~/.claudeignore # Build artifact exclusion (auto-deployed)
MCP Servers:
├── aivectormemory # Vector memory + issue/task
├── memorygraph # Graph memory + relationships
└── mnemex # Code intelligence (optional, needs Ollama)
Rollback
python scripts/rollback.py # Restore skill manifests from backup
rm ~/.local/bin/rtk.exe # Remove RTK
pip uninstall aivectormemory memorygraphMCP # Remove memory backends
# Hooks and MCP configs can be manually removed from settings.json / .claude.json- AIVectorMemory — Vector memory + issue tracking
- MemoryGraph — Graph-based relationship memory
- LLMLingua — Token-level prompt compression
- OpenHands — Safety hook architecture inspiration
- Claude Code CLI
- Python 3.10+
- Windows 10/11 (full support) or Mac/Linux (partial — no RTK)
MIT