Skip to content
/

rtk (Real Token Killer)

rtk-token-killer · rtk-ai/rtk · ★ 55k · last commit 2026-04-10

Primitive shape 1 total
Hooks 1
00

Summary

rtk-token-killer — Summary

One-liner: Rust binary that acts as a command proxy, intercepting CLI tool output before it reaches Claude Code's context window and compressing it 60-90% through smart filtering, grouping, truncation, and deduplication.

Identity

Field Value
Slug rtk-token-killer
GitHub https://github.com/rtk-ai/rtk
Stars 54,590
License Apache-2.0
Language Rust
Version analyzed 0.40.0
Maintainer status Active
Contributors 30

What It Does

rtk (Real Token Killer) is a Rust-based CLI command proxy that sits between Claude Code's Bash tool and the underlying shell commands. When a developer runs rtk init -g, it installs a PreToolUse hook into Claude Code's hook system. That hook intercepts every Bash command Claude attempts to execute and rewrites it to the rtk <cmd> equivalent, which runs the real command but filters, condenses, and deduplicates the output before returning it to Claude.

The result is 60-90% token reduction on command output while preserving all decision-relevant information. Token savings are tracked in SQLite and surfaced via analytics commands.

Key Capabilities

  • Command proxy architecture: Each CLI family (git, jest, cargo, npm, kubectl, etc.) has a dedicated filter module in src/cmds/*/
  • PreToolUse hook integration: hooks/claude/rtk-rewrite.sh wraps Bash tool calls; exit codes signal rewrite/no-equivalent/deny/ask
  • Token analytics: rtk gain, rtk gain --graph, rtk gain --daily, rtk gain --history, rtk gain --all --format json
  • Session tracking: rtk session shows current session savings
  • Discoverability: rtk discover shows which commands in the current repo can be optimized
  • Custom filters: .rtk/filters.toml per-project configuration
  • Multi-tool init: rtk init -g (Claude Code/Copilot), --gemini flag, --codex flag, or --agent cursor/windsurf/cline/kilocode/antigravity/hermes
  • Package managers: brew install rtk, cargo install rtk, prebuilt binaries

Scope

Single-purpose utility. No orchestration, no AI calls, no multi-agent patterns. Pure output compression pipeline with hook-based integration.

01

Purpose Workflow

rtk-token-killer — Purpose & Workflow

Problem Solved

Every Claude Code session burns tokens on verbose CLI output: git status prints 40 lines, npm test spits 800 lines of Jest runner boilerplate, cargo build scrolls through dependency compilation logs. Claude reads all of it. Most of it is noise.

rtk intercepts this output stream at the PreToolUse boundary and compresses it before Claude sees it — achieving 60-90% token reduction without losing decision-relevant content.

Workflow

Claude attempts: bash("git status")
        ↓
PreToolUse hook (rtk-rewrite.sh)
        ↓
rtk rewrite "git status"
  → exit 0: "rtk git status"    (rewrite found)
  → exit 1: passthrough         (no equivalent)
  → exit 2: blocked             (deny rule)
  → exit 3: human approval      (ask rule)
        ↓
rtk git status
  → run real git status
  → filter: remove untracked preamble noise
  → group: consolidate similar lines
  → truncate: cap at threshold
  → dedupe: remove repeated patterns
        ↓
Compressed output returned to Claude
        ↓
SQLite tracking: original bytes, compressed bytes, command, timestamp

Workflow Phases

  1. initrtk init -g writes the hook file to ~/.claude/hooks/ and registers it in Claude Code's config; also installs init for other agents via flags
  2. intercept — PreToolUse hook catches every Bash call, queries rtk for rewrite
  3. compress — rtk runs the real command, applies filter module, returns condensed output
  4. track — SQLite records the before/after byte counts per command
  5. analyzertk gain aggregates savings, rtk discover finds optimization opportunities

Supported Command Families

Each family has a dedicated filter module under src/cmds/:

Module Commands compressed
git/ status, log, diff, blame, show, stash
js/ npm test, jest, vitest, npm install, yarn, pnpm
rust/ cargo build, cargo test, cargo clippy
python/ pytest, pip install, mypy
go/ go test, go build, go vet
jvm/ mvn, gradle
dotnet/ dotnet build, dotnet test
ruby/ rspec, bundle install
system/ ls, find, grep, read, diff
cloud/ docker, kubectl, aws, gcloud

Setup Path

# Install
brew install rtk            # macOS
cargo install rtk           # cross-platform

# One-time init
rtk init -g                 # Claude Code + Copilot
rtk init -g --gemini        # Gemini CLI
rtk init -g --codex         # Codex
rtk init --agent cursor     # Cursor IDE

# Ongoing analytics
rtk gain                    # total savings
rtk discover                # optimization opportunities in current repo
02

Commands Skills

rtk-token-killer — Commands & Skills

Claude Code Commands

rtk ships a .claude/commands/ directory but its primary integration path is the PreToolUse hook, not slash commands. The hook is auto-installed via rtk init -g.

No user-facing /project:* slash commands documented.

Claude Code Skills

None shipped as skill markdown files. The project has a .claude/ directory structure for hook registration, not for behavioral guidance files.

Hook Integration (Primary Interface)

The core integration is a single PreToolUse hook:

File: hooks/claude/rtk-rewrite.sh

#!/bin/bash
# rtk PreToolUse hook — intercepts Bash tool calls
# Exit codes:
#   0 = rewrite found (output: replacement command)
#   1 = no equivalent (passthrough)
#   2 = deny rule matched (block)
#   3 = ask rule matched (request human approval)

CMD="$1"
rtk rewrite "$CMD"

The hook delegates entirely to rtk rewrite "$CMD" — a single Rust function that is the source of truth for all rewrite decisions.

Registration: rtk init -g writes the hook registration into Claude Code's hooks config. The hook fires on every PreToolUse event where tool_name == "Bash".

rtk CLI Subcommands

These are rtk's own CLI surface, not Claude Code commands:

Command Purpose
rtk init -g Install hook globally for Claude Code + Copilot
rtk init -g --gemini Install for Gemini CLI
rtk init -g --codex Install for Codex
rtk init --agent <name> Install for cursor/windsurf/cline/kilocode/antigravity/hermes
rtk rewrite <cmd> Core proxy: check if cmd has an rtk equivalent
rtk gain Show total token savings summary
rtk gain --graph ASCII chart of savings over time
rtk gain --daily Per-day savings breakdown
rtk gain --history Full savings history
rtk gain --all --format json JSON export of all savings data
rtk session Current session savings
rtk discover Find optimizable commands in current repo
rtk <cmd> [args] Direct compressed command execution

Custom Filter Configuration

.rtk/filters.toml (per-project):

[deny]
patterns = ["rm -rf /", "curl.*sudo"]

[ask]
patterns = ["git push --force"]

[truncate]
max_lines = 50

[dedupe]
enabled = true
03

Mcp Tools

rtk-token-killer — MCP & Tools

MCP Server

None. rtk does not ship an MCP server and does not register as an MCP server.

Integration Mechanism

rtk integrates with Claude Code exclusively through the PreToolUse hook pattern, not the MCP protocol. The distinction matters:

  • MCP servers expose tools Claude can call
  • rtk's hook intercepts tools Claude has already decided to call and rewrites the command before execution

This makes rtk a transparent proxy layer, not an additional tool surface.

Tool Ecosystem Coverage

rtk installs hooks across multiple AI coding tools via a single binary:

Tool Init command Hook mechanism
Claude Code rtk init -g PreToolUse hook
GitHub Copilot rtk init -g (same hook, shared config)
Gemini CLI rtk init -g --gemini Gemini pre-exec hook
Codex rtk init -g --codex Codex pre-exec hook
Cursor rtk init --agent cursor .cursorrules injection
Windsurf rtk init --agent windsurf Windsurf hook
Cline rtk init --agent cline Cline hook
Kilocode rtk init --agent kilocode Kilocode hook
Antigravity rtk init --agent antigravity Agent hook
Hermes rtk init --agent hermes Agent hook

No AI Calls

rtk makes zero LLM/AI API calls. All compression is deterministic Rust code — pattern matching, regex, heuristic line grouping. No model is invoked during the proxy path.

Homepage

https://rtk-ai.app — product landing page with feature overview and install instructions.

05

Quality Gates

rtk-token-killer — Quality Gates

Validation Approach

rtk's quality model is focused on correctness of compression — the filter modules must not strip decision-relevant information from command output.

Deny and Ask Rules

The .rtk/filters.toml system provides two safety gates:

  • deny rules: Patterns that match a command prevent execution entirely. Default deny list blocks destructive operations (e.g., rm -rf /, force-push to protected branches).
  • ask rules: Patterns trigger a human approval prompt before the command runs. Designed for operations that are not always wrong but warrant human review (e.g., git push --force).

These are quality gates in the agent safety sense — preventing Claude from accidentally executing destructive commands during autonomous sessions.

Token Tracking as Quality Signal

The SQLite analytics database (src/core/tracking.rs) records:

  • Original output byte count
  • Compressed output byte count
  • Command string
  • Timestamp
  • Session ID

This data feeds rtk gain and serves as an empirical quality signal: if compression ratio drops suddenly for a command family, the filter module may have regressed.

No TDD Evidence

No test suite is documented in the gathered data. The Rust codebase uses standard Cargo tooling but no specific TDD enforcement mechanism was observed.

Security Considerations

  • The PreToolUse hook runs before every Bash command in Claude Code sessions — this is a privileged position in the execution chain
  • The deny/ask rule system is the primary security surface
  • Custom .rtk/filters.toml allows per-project security policies, useful in team environments where certain operations should always require human review

Exit Code Guarantees

The rtk rewrite command's 4-exit-code protocol is a behavioral contract for hook authors. Any hook consuming rtk must handle all four exit codes correctly or the deny/ask safety model breaks.

09

Uniqueness

rtk-token-killer — Uniqueness

differs_from_seeds

rtk has no direct analog among the 11 seeds. All seed frameworks address the input side of Claude's context — what CLAUDE.md, skills, and commands tell Claude to do. rtk addresses the output side — what command results Claude sees. This is a different and complementary axis.

Specifically:

  • superpowers, BMAD-METHOD, spec-driver: behavioral guidance via skills and CLAUDE.md
  • taskmaster-ai, spec-driver: task/workflow management via structured input specs
  • Any seed with hooks: hooks in seeds are used for routing logic or pre/post actions — not for output compression
  • None of the seeds use hooks to intercept and rewrite command output before Claude reads it

rtk's closest conceptual relative in the batch is claude-overlay (which also uses bash hooks), but claude-overlay configures model routing while rtk compresses tool output. They operate on different parts of the same hook lifecycle.

Positioning

  • Primary differentiator: Output-side context management. The only tool in the catalog that reduces token consumption by filtering command output at the PreToolUse boundary before it enters Claude's context window.
  • Secondary differentiator: Cross-tool breadth from a single binary. rtk init supports 10 different AI coding agents (Claude Code, Copilot, Gemini CLI, Codex, Cursor, Windsurf, Cline, Kilocode, Antigravity, Hermes) via a single Rust binary.
  • Tertiary differentiator: Empirical token analytics. rtk gain surfaces concrete token savings data with historical trends and JSON export — treating token spend as a measurable engineering metric.
  • Target user: Developers in heavy AI coding sessions who notice context window pressure from verbose tool output, and want to address it at infrastructure level without changing their development workflow.

Observable Failure Modes

  1. Filter module coverage gaps: Commands not in any src/cmds/*/ module pass through uncompressed (exit 1). As the ecosystem evolves, new frameworks' test outputs won't be compressed until a module is written.
  2. Information loss risk: Overly aggressive compression could strip output that Claude actually needs for debugging. Configuring truncation thresholds requires judgment.
  3. Name collision on crates.io: Two different rtk crates exist; cargo install rtk may install the wrong one. Homebrew is the safe install path.
  4. No watch mode for filter config: Changes to .rtk/filters.toml take effect immediately but there's no live reload or validation — misconfigured deny rules could silently block commands.
  5. Rust binary distribution friction: Non-Homebrew users must either use cargo or download prebuilt binaries; no npm/pip/deb install path for non-Rust developers.

Most Surprising Finding

54,590 GitHub stars — the most popular tool in this 33-batch catalog by a large margin (ccs-switch at 2,410 is the second in this batch). The combination of a simple hook-based approach, Rust performance, and measurable token savings appears to have resonated with the developer community at scale despite being a narrow single-purpose utility.

04

Agent Patterns

rtk-token-killer — Agent Patterns

Primary Pattern: Transparent Output Proxy

rtk's design is built around a single agent pattern: the transparent command proxy. Claude never knows rtk is running. From Claude's perspective, it issued a Bash command and got back the results. The PreToolUse hook intercepts at the infrastructure layer.

Claude → [PreToolUse hook] → rtk rewrite → rtk <cmd> → compressed output → Claude

This is distinct from:

  • MCP tools: Claude explicitly decides to call them
  • Skills/CLAUDE.md: Claude reads them and changes its behavior
  • System prompts: Claude is told to use a different approach

rtk is invisible to Claude's reasoning loop. It improves context quality without requiring any change in Claude's planning.

Hook Exit Code Protocol

The rtk rewrite command uses exit codes as a signal protocol with the hook:

Exit code Meaning Hook action
0 Rewrite found Replace command with rtk equivalent
1 No equivalent Passthrough — run original command unchanged
2 Deny rule matched Block execution, return error to Claude
3 Ask rule matched Pause for human approval before proceeding

This gives users fine-grained control: compress what you can, block what you don't want, ask about sensitive operations.

Analytics Feedback Loop

Secondary pattern: developers use rtk gain to understand which commands are burning the most tokens. This creates a feedback loop for prompt engineering — knowing that cargo test accounts for 40% of token spend informs decisions about test strategy in AI sessions.

Multi-Agent Support

rtk init --agent <name> installs the hook for non-Claude agents (Cursor, Windsurf, Cline, Kilocode). The same Rust binary and filter modules work across all agents. This is not orchestration — it is cross-tool infrastructure.

No Multi-Agent Orchestration

rtk does not orchestrate agents, spawn subagents, or manage agent-to-agent communication. It is a single-tool infrastructure utility.

Rust Architecture

The proxy is a Rust binary using:

  • clap — CLI argument parsing and subcommand routing
  • serde + serde_json — filter config deserialization
  • rusqlite — SQLite tracking database
  • ignore — .gitignore-aware file traversal for rtk discover
  • walkdir — directory traversal
  • colored — terminal output formatting
  • dirs — cross-platform home directory resolution
  • chrono — timestamp handling for analytics

Source organization: src/cmds/ contains one subdirectory per command family; src/core/tracking.rs handles SQLite persistence.

06

Memory Context

rtk-token-killer — Memory & Context

Persistent State

rtk maintains one persistent store: a SQLite database for token savings analytics.

Store Location Purpose
SQLite tracking DB ~/.rtk/tracking.db (inferred) Per-command savings history
Filter config .rtk/filters.toml Per-project deny/ask/truncate rules

No Session Memory

rtk does not maintain conversation state, context about previous Claude sessions, or memory of prior commands beyond the analytics tracking. Each command execution is independent.

What the Database Contains

The SQLite database (src/core/tracking.rs) records:

  • Command string (normalized)
  • Original output size in bytes
  • Compressed output size in bytes
  • Timestamp
  • Session identifier

This data is read-only for the user via rtk gain commands. It is not used by the proxy path itself — analytics are a separate read path.

Context Reduction Architecture

The fundamental purpose of rtk is reducing the context window burden of tool output. By compressing 60-90% of command output before it enters Claude's context, rtk addresses the context window as a constrained resource.

This is a system-level approach to context management: instead of managing what Claude remembers (conversation context compression), rtk manages what Claude receives (output filtering at source).

Cross-Session Portability

The SQLite database accumulates savings data across all sessions. rtk gain --history shows cumulative savings since install. This makes rtk's analytics persistent across Claude Code restarts, unlike in-session context.

No Caching of Command Outputs

rtk does not cache command results. Each command re-runs the real underlying command. The compression is applied to fresh output on every invocation.

07

Orchestration

rtk-token-killer — Orchestration

Multi-Agent Pattern

None. rtk is single-purpose infrastructure — it does not orchestrate agents or coordinate between multiple AI tools.

Execution Model

one-shot per command: the hook fires, rtk processes the command, returns output, exits. There is no persistent process, no daemon, no server.

Isolation Mechanism

None — rtk writes to a user-level SQLite database and a user-level hook config. No sandboxing or isolation between projects.

Multi-Model Usage

None. rtk makes no AI or LLM calls whatsoever. All logic is deterministic Rust.

Cross-Tool Portability

High — the same Rust binary installs hooks for 10 different AI coding agents via rtk init flags. This is the broadest cross-tool hook install surface observed in the batch.

Prompt Chaining

None — rtk does not modify prompts. It modifies command output that flows back to the model, not the input prompt.

Consensus Mechanism

None.

Architecture Summary

rtk is deliberately minimal in its scope. The entire orchestration pattern is:

hook fires → single binary call → stdout → hook exits

No spawned subprocesses beyond the underlying command, no network calls, no IPC. The simplicity is intentional — the tool must add near-zero latency on every Claude Bash invocation.

08

Ui Cli Surface

rtk-token-killer — UI & CLI Surface

CLI Binary

  • Binary name: rtk
  • Language: Rust
  • Is thin wrapper: No — full Rust runtime with filter modules, SQLite tracking, and hook management
  • Install:
    • brew install rtk (macOS Homebrew)
    • cargo install rtk
    • Prebuilt binaries from GitHub releases
# Init
rtk init -g                     # Claude Code + Copilot
rtk init -g --gemini            # Gemini CLI
rtk init -g --codex             # Codex
rtk init --agent cursor         # Cursor
rtk init --agent windsurf       # Windsurf

# Proxy commands (used by hook)
rtk rewrite "<cmd>"             # Returns exit code + rewrite
rtk git status                  # Run compressed git status
rtk jest                        # Run compressed jest
rtk cargo test                  # Run compressed cargo test

# Analytics
rtk gain                        # Total savings summary
rtk gain --graph                # ASCII savings chart
rtk gain --daily                # Per-day breakdown
rtk gain --history              # Full history
rtk gain --all --format json    # JSON export
rtk session                     # Current session savings
rtk discover                    # Find optimizable commands in repo

Local UI

None — CLI only.

Homepage

https://rtk-ai.app — product marketing page with feature highlights.

Observability

  • Terminal output: colored stats on compression ratio per command
  • rtk gain --graph: ASCII bar chart of token savings over time
  • rtk session: live session savings counter
  • JSON export: rtk gain --all --format json for external dashboard integration

MCP Server

None shipped. The hook is the integration mechanism, not MCP.

IDE Integration

Via rtk init --agent <name> for Cursor, Windsurf, Cline, Kilocode, Antigravity, Hermes — installs agent-specific hook configurations, not IDE plugins.

Name Collision Warning

There are two different rtk projects on crates.io. The token-killing rtk is from rtk-ai/rtk on GitHub. The other is an unrelated Rust crate. The Homebrew tap is the unambiguous install path.

Related frameworks

same archetype · same primary tool · same memory type

Context Mode ★ 16k

Keeps raw tool output data out of the context window via sandbox execution and SQLite+FTS5 session indexing, reducing context…

lean-ctx ★ 2.2k

A full-session context runtime that compresses file reads (10 modes), shell output (60+ patterns), and session memory (CCP) to…

Nemp Memory ★ 101

Persists AI agent context across sessions as 100%-local plain JSON files with zero dependencies, zero cloud, and agent identity…

CogniLayer v4 ★ 28

Provides AI coding agents with typed semantic memory, tree-sitter code intelligence, and a multi-agent coordination protocol to…

cursor-coding-agent-os (Mugiwara555343) ★ 3

Lean/Verbose dual-mode Agent OS fork for solo developers on token budgets.

Code-Mode Library ★ 1.5k

Replaces traditional tool-calling with TypeScript code execution in a sandbox, collapsing N sequential tool calls into 1 code…