11---
22name : rtk-token-optimizer
33description : >-
4- Compress shell command output to cut LLM token usage 60-90% by prefixing
5- commands with `rtk`. Use whenever running shell commands in Command Code —
6- git, cargo, npm/pnpm, pytest/jest, docker, kubectl, gh, grep, find, ls, cat,
7- build and lint tools — so large outputs are filtered before entering context.
4+ Cut LLM token usage on noisy shell output by routing large, low-stakes
5+ commands (listings, status, logs, dependency installs, test/build runs)
6+ through RTK — while keeping full fidelity for diffs, structured/JSON output,
7+ errors you're debugging, and anything you'll parse or edit. Use when running
8+ shell commands in Command Code that produce big, repetitive output.
89license : Apache-2.0
910compatibility : >-
10- Requires the RTK binary (>= 0.42.0) installed and on PATH. Verify with
11- `rtk --version`. Install from https://github.com/rtk-ai/rtk
11+ Requires the RTK binary (>= 0.42.0) on PATH. Verify with `rtk --version`.
12+ Install from https://github.com/rtk-ai/rtk. RTK is optional — run commands
13+ normally if it isn't installed.
1214metadata :
1315 author : Coding-Dev-Tools
14- version : " 0.1 .0"
16+ version : " 0.2 .0"
1517 homepage : https://github.com/rtk-ai/rtk
1618allowed-tools : Bash(rtk:*) Bash(git:*) Bash(cargo:*) Bash(ls:*) Bash(cat:*) Bash(grep:*) Bash(find:*) Bash(diff:*) Bash(docker:*) Bash(kubectl:*) Bash(gh:*) Bash(glab:*) Bash(pnpm:*) Bash(npm:*) Bash(pip:*) Bash(bundle:*) Bash(ruff:*) Bash(tsc:*) Bash(eslint:*) Bash(pytest:*) Bash(go:*) Bash(jest:*) Bash(vitest:*) Bash(dotnet:*) Bash(aws:*) Bash(psql:*) Bash(prisma:*) Bash(wget:*)
1719---
@@ -20,67 +22,91 @@ allowed-tools: Bash(rtk:*) Bash(git:*) Bash(cargo:*) Bash(ls:*) Bash(cat:*) Bash
2022
2123## What it is
2224
23- [ RTK] ( https://github.com/rtk-ai/rtk ) (Rust Token Killer) is a CLI proxy that
24- filters and compresses shell command output before it reaches the context
25- window — removing noise, grouping similar items, truncating redundancy, and
26- deduplicating repeated lines. Typical savings are 60-90% on common dev
27- commands. RTK ships as a single self-contained Rust binary that adds minimal
28- per-command overhead.
25+ [ RTK] ( https://github.com/rtk-ai/rtk ) (Rust Token Killer) is a single Rust binary
26+ that filters ** shell command output** before it reaches the context window —
27+ dropping noise (progress bars, passing tests, decorative formatting, repeated log
28+ lines) while keeping signal (errors, stack traces, diff hunks, exit codes). When
29+ it can't parse a command's output it falls back to the full raw text, so it never
30+ silently eats data. Typical savings are 60–90% on noisy commands, at <10 ms
31+ overhead.
2932
30- ## How it works
33+ Done right this is a ** double win** : fewer tokens * and* a leaner context, which
34+ measurably improves model reasoning — every frontier model degrades as irrelevant
35+ context grows ("context rot" / "lost in the middle"). Done wrong —
36+ over-compressing output you actually needed — it hides detail and triggers
37+ re-runs that cost more than they saved. The rest of this skill is how to stay on
38+ the winning side.
3139
32- ```
33- You run: git status
34- RTK rewrites: rtk git status
35- RTK filters: smart filtering · grouping · truncation · deduplication
36- Result: ~200 tokens enter context instead of ~2,000
40+ ## Install — two ways
41+
42+ ### 1. Auto-rewrite hook (recommended)
43+
44+ Let a ` PreToolUse ` hook rewrite Bash commands to their ` rtk ` equivalents
45+ automatically, so you never prefix by hand and nothing gets forgotten. RTK ships
46+ this for natively-supported agents:
47+
48+ ``` bash
49+ rtk init -g # installs the PreToolUse rewrite hook, then restart the agent
3750```
3851
39- ## Core rule
52+ RTK natively targets Claude Code, Copilot, Cursor, Gemini, Cline, and more.
53+ Command Code also supports ` PreToolUse ` hooks — register one that pipes the Bash
54+ command through RTK's rewrite (see the Command Code hooks docs and `rtk init
55+ --help`). With a hook installed you ** run normal commands** , and only need the
56+ fidelity rules below for the cases where you want to * bypass* compression.
4057
41- Prefix supported shell commands with ` rtk ` . Run ` rtk git status ` instead of
42- ` git status ` , ` rtk cargo test ` instead of ` cargo test ` , ` rtk read file.rs `
43- instead of ` cat file.rs ` .
58+ ### 2. Manual prefixing (no hook)
4459
45- Most-used commands:
60+ Without a hook, prefix commands yourself per the tiers in
61+ [ references/commands.md] ( references/commands.md ) . Reliable, but you have to
62+ remember it — and ` | ` pipes and ` << ` heredocs bypass the rewrite.
4663
47- | Instead of | Use |
48- | ---| ---|
49- | ` git status ` / ` git diff ` | ` rtk git status ` / ` rtk git diff ` |
50- | ` ls -la ` | ` rtk ls ` |
51- | ` cat file ` | ` rtk read file ` |
52- | ` grep -r "x" . ` | ` rtk grep "x" . ` |
53- | ` cargo test ` / ` pytest ` / ` npm test ` | ` rtk cargo test ` / ` rtk pytest ` / ` rtk jest ` |
54- | ` docker ps ` | ` rtk docker ps ` |
64+ ## Decision rule: compress noise, preserve signal
5565
56- Full command list: [ references/commands.md] ( references/commands.md ) .
57- Savings analytics: [ references/analytics.md] ( references/analytics.md ) .
66+ - 🟢 ** Compress freely** — large, noisy, low-stakes output you skim:
67+ ` rtk ls ` , ` rtk git status ` , ` rtk git log ` , ` rtk docker ps ` , ` rtk pip list ` .
68+ - 🟡 ** Default mode only** — big runs where you need the failures: `rtk cargo
69+ test` , ` rtk err <cmd >` . Plain ` rtk` keeps errors/diffs — don't add ` -u`.
70+ - 🔴 ** Keep full fidelity (run raw)** — diffs/patches you'll apply, JSON or
71+ ` --format ` output you'll parse, secrets, small outputs, and files you'll edit
72+ (use the native Read tool).
5873
59- ## Prerequisite
74+ Full tiered table: [ references/commands.md ] ( references/commands.md ) .
6075
61- RTK must be on PATH. If ` rtk --version ` fails, install it:
76+ ## Fidelity ladder
6277
63- - ** macOS:** ` brew install rtk `
64- - ** Linux/macOS:** ` curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh `
65- - ** Windows:** download ` rtk-x86_64-pc-windows-msvc.zip ` from the [ releases page] ( https://github.com/rtk-ai/rtk/releases ) and put ` rtk.exe ` on PATH.
78+ Use the * least* compression that still answers the question:
6679
67- ## Ultra-compact mode
80+ ```
81+ raw / native Read → rtk <cmd> (near-lossless, default) → -u / -l aggressive / rtk smart (lossy, skim-only)
82+ ```
6883
69- Add ` -u ` / ` --ultra-compact ` for maximum savings: ` rtk git status -u ` .
84+ Start as far left as the task needs. Escalate compression only for big, boring
85+ output; escalate * fidelity* (drop back to raw or ` rtk proxy <cmd> ` ) the moment a
86+ compressed view is missing something — once, deliberately, not by re-running
87+ blindly.
7088
7189## When NOT to use RTK
7290
73- - RTK filters ** command output** , not conversation messages.
74- - Piped commands (` | ` ) and heredocs (` << ` ) bypass the rewrite.
75- - No auto-rewrite hook in Command Code — prefix each command with ` rtk ` explicitly.
91+ - Diffs/patches you'll apply, JSON/` --format ` you'll parse, secrets, small
92+ outputs — run raw.
93+ - Files you'll edit — use the native Read tool (lossless; bypasses RTK anyway).
94+ - It filters command output, not conversation messages; ` | ` and ` << ` bypass the
95+ hook.
7696
77- ## Verify savings
97+ ## Measure net savings
7898
79- ``` bash
80- rtk gain # session summary
81- rtk gain --graph # 30-day savings chart
82- ```
99+ ` rtk gain ` shows gross savings; ` rtk gain --failures ` shows what passed through
100+ raw; ` rtk discover ` finds good new targets. Optimize ** net** tokens (savings
101+ minus re-runs), not the headline number. Full reference:
102+ [ references/analytics.md] ( references/analytics.md ) .
103+
104+ ## Prerequisite
105+
106+ RTK on PATH (` rtk --version ` ). If missing:
107+
108+ - ** macOS:** ` brew install rtk `
109+ - ** Linux/macOS:** ` curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh `
110+ - ** Windows:** download ` rtk-x86_64-pc-windows-msvc.zip ` from the [ releases page] ( https://github.com/rtk-ai/rtk/releases ) and put ` rtk.exe ` on PATH.
83111
84- Savings vary by command and output size; ` rtk gain ` reports your actual
85- numbers. See [ references/analytics.md] ( references/analytics.md ) for the full
86- analytics reference.
112+ RTK is optional; never block work to install it.
0 commit comments