rtk-token-optimization
High-performance CLI proxy that reduces LLM token consumption by 60-90%. Transparently rewrites 100+ common dev commands (git, gh, cargo, npm, docker, kubectl, aws, etc.) via PreToolUse hook. Single Rust binary, zero dependencies.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- rtk-token-optimization
- source
- https://github.com/rtk-ai/rtk
- license
- Apache-2.0
- trust_tier
- B-proven-community
- description
- High-performance CLI proxy that reduces LLM token consumption by 60-90%. Transparently rewrites 100+ common dev commands (git, gh, cargo, npm, docker, kubectl, aws, etc.) via PreToolUse hook. Single Rust binary, zero dependencies.
02 资源文件 1
- 参考文档agents/openai.yaml303 B
03 SKILL.md 正文
Purpose
Reduce LLM token consumption in Claude Code sessions by 60-90% without changing developer workflow.
All Bash commands are transparently rewritten to their rtk equivalents via a PreToolUse hook.
How It Works
Without rtk: With rtk:
Claude --git status--> shell --> git Claude --git status--> RTK --> git
^ ~2,000 tokens (raw) | ^ ~200 tokens | |
+-------------------------------+ +---- (filtered) ----+-------+
Four strategies applied per command type:
- Smart Filtering - Removes noise (comments, whitespace, boilerplate)
- Grouping - Aggregates similar items (files by directory, errors by type)
- Truncation - Keeps relevant context, cuts redundancy
- Deduplication - Collapses repeated log lines with counts
Supported Commands
| Category | Commands | Typical Savings |
|---|---|---|
| Files | ls, read, find, grep, diff | 70-80% |
| Git | status, diff, log, add, commit, push | 75-92% |
| GitHub CLI | pr list, issue list, run list | 80% |
| Test Runners | cargo test, npm test, pytest, go test, vitest, playwright | 90% |
| Build & Lint | cargo build, tsc, next build, eslint, ruff, clippy | 80-85% |
| Package Managers | pnpm list, pip list, bundle install | 80% |
| Containers | docker ps/logs, kubectl pods/logs | 80% |
| AWS | sts, ec2, lambda, logs, s3, cloudformation | 80% |
| Data | json, env, log, curl, wget | 70-80% |
Token Savings (30-min Session Estimate)
| Operation | Frequency | Standard | rtk | Savings |
|---|---|---|---|---|
| ls / tree | 10x | 2,000 | 400 | -80% |
| cat / read | 20x | 40,000 | 12,000 | -70% |
| grep / rg | 8x | 16,000 | 3,200 | -80% |
| git status | 10x | 3,000 | 600 | -80% |
| git diff | 5x | 10,000 | 2,500 | -75% |
| cargo test / npm test | 5x | 25,000 | 2,500 | -90% |
| Total | ~118,000 | ~23,900 | -80% |
Usage
After installation, rtk works automatically via the PreToolUse hook. No manual changes needed.
Analytics Commands
rtk gain # Summary stats
rtk gain --graph # ASCII graph (last 30 days)
rtk gain --daily # Day-by-day breakdown
rtk discover # Find missed savings opportunities
rtk session # Show RTK adoption across recent sessions
Manual Usage
rtk git status # Compact git status
rtk read file.rs # Smart file reading
rtk test cargo test # Show failures only
rtk lint # ESLint grouped by rule/file
rtk docker ps # Compact container list
Prerequisites
rtkbinary:brew install rtkorcurl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | shjq: required by the hook script
Integration
- Hook:
hooks/rtk-rewrite.sh(PreToolUse:Bash, last in chain) - Config:
~/.config/rtk/config.tomlfor customization - Tee recovery: failed command full output saved to
~/.local/share/rtk/tee/
References
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.