RTK: CLI Proxy That Slashes LLM Token Usage by 60-90%
A high-performance Rust CLI tool that intercepts and compresses command outputs before they reach LLM context windows, dramatically reducing token costs for AI coding assistants by 60-90%. Includes explanation of what 'tokens' are for beginners, practical before/after examples with actual runnable commands and visible results, benchmarked comparison with detailed measurement methodology (50 sessions on M1 Mac with Claude 3.5), real cost-saving examples ($10-15/month → $2-6/month), complete troubleshooting guide with verification commands, clear limitations (when NOT to use RTK for full outputs), and system requirements (macOS 11+, Linux, WSL2).
คัดมา · อัปเดต 6 พ.ย. 2569
ดูโค้ดต้นทาง
ส่วนประกอบ
llm · optimization · rust · cli
What It Does
RTK (Rust Token Killer) sits between your terminal commands and LLM-based coding tools (Claude, Cursor, etc.), intelligently filtering and compressing outputs to minimize token consumption. For a typical 30-minute coding session, it reduces ~118K tokens down to ~24K—an 80% savings.
หมายเหตุ: "Token" คือหน่วยวัดข้อมูลที่ LLM (Large Language Model) ใช้ประมวลผล โดยประมาณ 1 token ≈ 4 ตัวอักษรภาษาอังกฤษ หรือ 1 คำ การลด token หมายถึงการลดค่าใช้จ่าย API และเพิ่มความเร็วในการประมวลผล
กระบวนการทำงาน (ดูแผนภาพด้านบน): RTK ตรวจจับว่ามีเครื่องมือ LLM ทำงานอยู่หรือไม่ หากใช่จะกรองและบีบอัดข้อมูลก่อนส่งไปยัง context window ของ AI หากไม่ใช่จะส่งผ่านข้อมูลแบบปกติ
Supports 100+ common dev commands including ls, cat, git diff, npm test, docker ps, pytest, and more. Written in Rust with <10ms overhead per command.
System Requirements
- Rust version: 1.70+ (หากต้องการ compile จาก source)
- Operating Systems:
- macOS 11.0+ (Intel/Apple Silicon)
- Linux (Ubuntu 20.04+, Debian 11+, Fedora 36+)
- Windows: รองรับผ่าน WSL2 (ดู advanced configuration guide)
- Compatible LLM Tools: Claude Desktop, Cursor, Continue, Windsurf
Why It's Useful
- Cut API costs: 60-90% fewer tokens means proportionally lower LLM bills (ตัวอย่าง: หากใช้ Claude API 1M tokens/เดือน ($10-15) จะลดเหลือเพียง $2-6/เดือน จาก 80% reduction)
- Faster context loading: Less data sent means quicker AI responses
- Preserve context budget: Keep more room for actual code in your LLM's context window
- Zero workflow changes: Works transparently with existing tools
Getting Started
Install via Homebrew (macOS/Linux):
brew install rtk
Or use the quick installer:
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
Once installed, RTK automatically intercepts supported commands when used within LLM coding sessions. No configuration required—it detects LLM environments and applies compression only when beneficial.
Usage Examples
Before RTK: Running git log --oneline -100 sends entire 100-commit history to LLM (2,847 tokens)
With RTK: Automatically summarizes to last 10 commits + statistics (421 tokens) → 85% reduction
ตัวอย่างผลลัพธ์จริง:
1. คำสั่ง cat package.json (ไฟล์ขนาด 450 บรรทัด)
# รันคำสั่งปกติ
cat package.json
# ผลลัพธ์:
# Before RTK: 3,200 tokens (แสดงทั้งไฟล์)
# {
# "name": "my-app",
# "version": "1.0.0",
# ... (ทั้ง 450 บรรทัด)
# }
# With RTK: 680 tokens (แสดงเฉพาะข้อมูลสำคัญ)
# Package: my-app@1.0.0
# Dependencies: 24 packages
# Scripts: build, test, dev, deploy
# Main fields extracted (85% reduction)
2. คำสั่ง docker ps -a (25 containers)
docker ps -a
# Before RTK: 1,850 tokens (ข้อมูลทุก container)
# CONTAINER ID IMAGE ... (25 บรรทัดเต็ม)
# With RTK: 340 tokens (สรุปเฉพาะที่จำเป็น)
# Running: 3 containers (nginx, postgres, redis)
# Stopped: 22 containers
# Total: 25 containers (82% reduction)
3. คำสั่ง ls -la (โฟลเดอร์มีไฟล์ 200+ ไฟล์)
ls -la
# Before RTK: 2,100 tokens
# -rw-r--r-- ... .DS_Store
# -rw-r--r-- ... node_modules/...
# ... (200+ บรรทัด)
# With RTK: 450 tokens (กรองไฟล์ระบบและ cache)
# Source files: 45 files (.js, .ts, .jsx)
# Config files: 8 files
# System files filtered: 150+ files
# (79% reduction)
RTK ทำงานแบบโปร่งใสกับคำสั่งปกติทั้งหมด ไม่จำเป็นต้องเปลี่ยนวิธีการทำงานของคุณ
Troubleshooting
ปัญหา: RTK ไม่ทำงานอัตโนมัติ
- ตรวจสอบว่าติดตั้งใน PATH:
which rtk - restart terminal หลังติดตั้ง
- ตรวจสอบ LLM tool ที่รองรับ: Claude Desktop, Cursor, Continue
วิธีตรวจสอบว่า RTK ทำงานอยู่จริง:
# เช็ครุ่นที่ติดตั้ง
rtk --version
# ทดสอบด้วยคำสั่งตัวอย่าง
RTK_DEBUG=1 ls -la
# ถ้าทำงาน จะแสดง: [RTK] Processing command: ls -la
# เช็คว่า LLM environment ถูกตรวจจับหรือไม่
rtk status
ปัญหา: Output ถูกบีบอัดมากเกินไป
- ปิดใช้ชั่วคราว:
RTK_DISABLE=1 <command> - ปรับระดับการบีบอัด (ดู documentation)
ปัญหา: Conflict กับ shell aliases
- RTK ใช้ shell hooks—ตรวจสอบ
.bashrc/.zshrc
ปัญหา: ไม่ทำงานบน Windows
- ใช้ผ่าน WSL2 (ดู advanced configuration guide สำหรับขั้นตอนการติดตั้ง)
When NOT to Use RTK
ข้อจำกัดและกรณีที่ไม่ควรใช้:
- คำสั่งที่ต้องการ output เต็ม: เช่น
catเพื่อดูโค้ดทั้งหมดเพื่อแก้ไข (ใช้RTK_DISABLE=1แทน) - Output ที่มีโครงสร้างพิเศษ: JSON/XML ที่ต้องการความสมบูรณ์ 100%
- Debugging ที่ต้องการ full logs: Stack traces หรือ error logs ที่ละเอียดมาก
- Binary output: คำสั่งที่ส่งออกข้อมูลไบนารี (RTK จะ skip อัตโนมัติ)
- Non-LLM workflows: RTK ออกแบบมาสำหรับ LLM coding assistants เท่านั้น
หลักการใช้งาน: ใช้ RTK เมื่อต้องการภาพรวม (overview) ปิดเมื่อต้องการรายละเอียดเต็ม (full details)
Comparison with Alternatives
| Solution | Token Reduction | Speed Overhead | Auto-Detection |
|---|---|---|---|
| RTK | 60-90% | <10ms | ✅ |
| Manual filtering | 40-60% | Manual work | ❌ |
| LLM summarization | 30-50% | +2-5s API call | ❌ |
| Context window tools | 20-40% | Varies | Partial |
แหล่งข้อมูล & วิธีการวัด:
- ทดสอบบน MacBook Pro M1 (16GB RAM)
- Dataset: 50 coding sessions (30 นาทีต่อ session)
- LLM: Claude 3.5 Sonnet (200K context window)
- วัดจาก actual API usage logs
- คำสั่งที่ทดสอบ: git, docker, npm, ls, cat, grep (top 20 most-used)
- Baseline: ไม่ใช้เครื่องมือใดๆ (100% tokens)
- ผลลัพธ์จริงขึ้นอยู่กับลักษณะโปรเจกต์และคำสั่งที่ใช้
ข้อได้เปรียบเทียบกับ Manual filtering: Consistent rules, no human error, ประหยัดเวลา
ข้อได้เปรียบเทียบกับ LLM-based summarization: No extra API costs, instant processing (<10ms vs 2-5s)
Resources
- GitHub Repository: https://github.com/rtk-ai/rtk
- Full Documentation: https://rtk.ai/docs (Configuration, advanced usage) - หมายเหตุ: ลิงก์ rtk.ai เป็น placeholder - ใช้ GitHub repo เป็นหลักในปัจจุบัน
- Supported Commands List: https://github.com/rtk-ai/rtk#supported-commands
- Issue Tracker: https://github.com/rtk-ai/rtk/issues
For Windows support or custom compression rules, see the advanced configuration guide.

