Rtk Token Optimizer: Install, Source and Security

Rtk Token Optimizer

Published by coding-dev-tools in rtk-improved

Review recommended3 installs

What this skill does

>-

Add Rtk Token Optimizer to your agent

Review the source and files first. When you are ready, copy the prompt instruction or use the CLI command supported by your environment.

Install with a prompt

Paste this into a compatible coding agent:

add this skill "rtk-token-optimizer" from https://github.com/coding-dev-tools/rtk-improved

Install with the CLI

Run this command in a controlled environment after reviewing the repository:

npx skills add https://github.com/coding-dev-tools/rtk-improved --skill rtk-token-optimizer

Skill instructions

RTK Token Optimizer — Universal Agent Integration

What it is

RTK (Rust Token Killer) is a single Rust binary that filters shell command output before it reaches the context window — dropping noise (progress bars, passing tests, decorative formatting, repeated log lines) while keeping signal (errors, stack traces, diff hunks, exit codes). When it can't parse a command's output it falls back to the full raw text, so it never silently eats data. Typical savings are 60–90% on noisy commands, at <10 ms overhead.

Done right this is a double win: fewer tokens and a leaner context, which measurably improves model reasoning — every frontier model degrades as irrelevant context grows ("context rot" / "lost in the middle"). Done wrong — over-compressing output you actually needed — it hides detail and triggers re-runs that cost more than they saved.

This integration supports 13 AI coding agents with a unified selective, signal-preserving policy.

Supported Agents

AgentIntegration Typertk init flag
Command Code CLIAGENTS.md + references--command-code
Claude CodePreToolUse hookdefault
GitHub CopilotPreToolUse hook--copilot
CursorPreToolUse hook--agent cursor
Gemini CLIBeforeTool hook--gemini
Codex CLIAGENTS.md + RTK.md--codex
Cline / Roo Code.clinerules--agent cline
Windsurf.windsurfrules--agent windsurf
Kilo CodeRules file--agent kilocode
Google AntigravityRules file--agent antigravity
OpenCodeTypeScript plugin--opencode
HermesPython plugin--agent hermes
PiTypeScript extension--agent pi

Decision rule: compress noise, preserve signal

  • 🟢 Compress freely — large, noisy, low-stakes output you skim: rtk ls, rtk git status, rtk git log, rtk docker ps, rtk pip list.
  • 🟡 Default mode only — big runs where you need the failures: rtk cargo test, rtk err <cmd>. Plain rtk keeps errors/diffs — don't add --ultra-compact.
  • 🔴 Keep full fidelity (run raw) — diffs/patches you'll apply, JSON or --format output you'll parse, secrets, small outputs, and files you'll edit (use the native Read tool).

Full tiered table: references/commands.md.

Fidelity ladder

Use the least compression that still answers the question:

raw / native Read  →  rtk <cmd> (keeps signal, default)  →  --ultra-compact / -l aggressive / rtk smart (lossy, skim-only)

Start as far left as the task needs. Escalate compression only for big, boring output; escalate fidelity (drop back to raw or rtk proxy <cmd>) the moment a compressed view is missing something — once, deliberately, not by re-running blindly.

When NOT to use RTK

  • Diffs/patches you'll apply, JSON/--format you'll parse, secrets, small outputs — run raw.
  • Files you'll edit — use the native Read tool (lossless; bypasses RTK anyway).
  • It filters command output, not conversation messages; | and << bypass the hook.

Measure net savings

rtk gain shows gross savings; rtk discover finds good new targets (and low-savings outliers worth dropping); on failure RTK's tee fallback keeps the full output. Optimize net tokens (savings minus re-runs), not the headline number. Full reference: references/analytics.md.

Compatibility & limitations

  • Exit codes. RTK aims to pass the wrapped command's exit code through, but it isn't guaranteed for every command/version. When a pass/fail verdict matters (tests, gates), trust the raw exit code or re-run raw / rtk proxy <cmd>.
  • Piped output can be silently wrong, not just decorated. On a non-TTY pipe RTK can substitute its compressed summary for the real content — e.g. a redirected grep writing a line count summary instead of the matching lines (RTK #1282, a correctness bug). Run anything you'll parse or redirect raw. Separately, RTK has emitted ANSI color codes into piped/non-TTY output before (RTK #1409, fixed); set NO_COLOR=1 defensively if you see escape codes leak through.
  • -u is not a working flag. RTK's own README still lists -u as a short form of --ultra-compact, but it was removed upstream (it collided with git push -u) and isn't restored — using it fails outright (RTK #2369, open). Use the long form --ultra-compact.
  • Streaming. RTK buffers to filter, so don't wrap -f/follow or growing logs.
  • PATH. In a non-interactive shell rtk may not be found; the integration treats it as optional and falls back to raw commands.
  • Native tools. Your agent's built-in file/search tools are lossless, give line numbers, and don't pass through RTK — prefer them over rtk read/grep/find.
  • Permissions. rtk (and rtk proxy) can execute arbitrary wrapped commands — allow-list it deliberately.
  • Hooks on Windows. RTK's filters work on Windows, but its auto-rewrite hook has gaps there (RTK discussion #671).

Prerequisite

RTK on PATH (rtk --version). If missing:

  • macOS: brew install rtk
  • Linux/macOS: curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
  • Windows: download rtk-x86_64-pc-windows-msvc.zip from the releases page and put rtk.exe on PATH.

RTK is optional; never block work to install it.

Files included

  • CHANGELOG.md
  • .gitignore
  • CODE_OF_CONDUCT.md
  • .github/workflows/ci.yml
  • AGENTS.md
  • SKILL.md
  • .github/PULL_REQUEST_TEMPLATE.md
  • .gitattributes
  • CONTRIBUTING.md
  • .github/CODEOWNERS
  • BENCHMARK.md
  • SECURITY.md
  • README.md
  • LICENSE
  • agents/claude-code/rtk-awareness.md
  • agents/codex/RTK.md
  • agents/command-code/analytics.md
  • agents/cline/rules.md
  • agents/command-code/AGENTS.md
  • agents/command-code/commands.md
  • agents/antigravity/rules.md
  • agents/gemini/GEMINI.md
  • agents/copilot/rtk-awareness.md
  • agents/cursor/rtk-awareness.md
  • agents/hermes/rtk-awareness.md
  • agents/kilocode/rules.md
  • agents/windsurf/rules.md
  • agents/opencode/rtk-awareness.md
  • agents/pi/rtk-awareness.md
  • install.sh
  • install.ps1
  • references/analytics.md
  • references/commands.md
  • patches/rtk-upstream-changes.patch

More skills