Free · open source
GPLv3, royalty-free or commercial — your choice$0forever
- Hooks, MCP server and API proxy
- Lossless archive with rtok expand
- Local stats and doctor
Token-reduction CLI for AI coding agents — hooks, an MCP server and an API proxy in one Rust binary.
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/pyrlyn/rtok/releases/latest/download/rtok-installer.sh | sh
Token savings are estimates from a chars-per-token heuristic until matched against provider usage. No live A/B cost reduction has been established yet.
See it run
$ rtok agents install claude --dry-run + PreToolUse Bash rtok hook PreToolUse + PreToolUse Read rtok hook PreToolUse + PostToolUse * rtok hook PostToolUse … 8 additions $ rtok run -- cargo test [rtok 7f3a91 · 412 lines · expand: rtok expand 7f3a91] $ rtok graph index . indexed 5 files · 551 rows · 0 skipped · 5 read $ rtok plugins id enabled surfaces measure on cli,proxy cmd on hook,cli archive on proxy,mcp …
Code graph over MCP
rtok graph index . builds a symbol index that agents query as symbol, callers, impact, outline and explore instead of a grep-and-read chain.Reversible by design
Context, compressed Illustrative
Δtok −0 / 240 tokens
Scroll to compress, scroll back to expand. An illustration of the idea, not a measurement: in rtok a saving only counts when a Measurement row in the ledger records it, and archived payloads come back whole with rtok expand <id>.
Overview
rtok reduces the context that AI coding agents must carry. It is one Rust binary with three
surfaces: Claude Code hooks, an MCP server, and an API proxy. Each reduction is measured, and
shortened payloads stay retrievable by id.
Ten methods, one process, one ledger. A saving that is not a row in that ledger does not exist — including rtok's own.
Features
rtok agents install claude writes rtok's hooks and MCP entry into Claude Code, backing up the settings file first; --dry-run prints the diff and touches nothing. Cursor, Codex, OpenCode, pi, Kimi, Copilot, Aider, Windsurf, Zed, VS Code and more are registered the same way.
rtok run -- <cmd> keeps the exit code, archives the raw output and prints a compact summary with an id to expand it.
Archived payloads come back with rtok expand <id>, whole or by line range or regex match. Hooks fail open: on any error the agent gets its input unmodified.
rtok graph index . builds a symbol index that agents query as symbol, callers, impact, outline and explore instead of a grep-and-read chain.
rtok proxy captures provider-reported usage and can replace old tool results with stable archive pointers while preserving the cached prefix.
rtok stats reads transcripts and proxy usage; rtok doctor prices the hooks, MCP servers and skills you already run.
measure, cmd, read, archive, proxy, inject, guard, memory, graph and toon — each can be switched off in the one config file.
rtok otel flush exports calls, logs and metrics as OTLP/HTTP JSON to Jaeger, Grafana, SigNoz or Maple. rtok web and rtok tui show the same data locally.
Install
macOS (Apple silicon) and Linux x86-64, installed into ~/.cargo/bin:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/pyrlyn/rtok/releases/latest/download/rtok-installer.sh | sh
With ketch, straight from the GitHub Release archives:
ketch install pyrlyn/rtok
Homebrew, npm or PyPI (the packages carry the same native binary):
brew install pyrlyn/tap/rtok
npm i -g rtok-cli
uv tool install rtok-cli
From source:
git clone https://github.com/pyrlyn/rtok && cd rtok
mise install
mise exec -- cargo install --path .
rtok --version
Install the Claude Code integration, preview first, then check it:
rtok agents install claude --dry-run
rtok agents install claude
rtok doctor
More examples below.
Usage examples
Run a command through rtok and read the archived output back later:
rtok run -- cargo test
rtok expand 7f3a91 --lines 120-180
rtok expand 7f3a91 --grep "panicked" --context 3
Index a tree for the code graph and list the plugins:
rtok graph index .
rtok plugins
rtok config set plugins.toon.enabled false
Run the proxy and measure:
rtok proxy --mode passthrough
rtok stats --since 7d
rtok stats --save-baseline before-rtok
rtok stats --compare before-rtok
See where every setting came from:
rtok config show --sources
Links
You can use rtok under any of the following licenses, at your choice:
Pricing
Pro is a placeholder$0forever
$9 / moper seat
Placeholder — the Pro waitlist is not open yet.
Free and open source. Star it, file an issue, or send a pull request.