Token Optimization (RTK)
Compress the output of terminal commands before the agent reads it — typically 60–90% fewer tokens on builds, tests and installs.
Token Optimization uses RTK, a free, open-source command-line tool (Apache 2.0, a single binary), to shrink the output of the terminal commands your agent runs. Test runs, builds, type checks, git and package installs print hundreds of lines the model doesn't need: RTK filters, groups and de-duplicates that output before the agent reads it. On common development commands that typically saves 60–90% of the tokens, so long sessions stay within the context window longer and cost less.
Nothing changes in what you see or approve: the chat shows the original command, permission checks run on the original command, and only the output the model reads is compressed.
Install RTK
Easiest (no terminal): open Settings → AI → Performance and click Install next to Token Optimization. Fabric Agents downloads the official RTK release for your computer (macOS, Windows or Linux) from RTK's GitHub releases, checks it against the release's published checksum, and installs it into ~/.fabric-agent/bin — no administrator rights, nothing installed system-wide. It takes a few seconds, and Token Optimization is switched on for you — that's all you need to do. If your RTK is out of date, the same place offers Update now.
To remove a copy Fabric installed, delete ~/.fabric-agent/bin/rtk (rtk.exe on Windows).
Or install it yourself (version 0.44.0 or newer), then click Re-check:
| Platform | Command |
|---|---|
| macOS / Linux (Homebrew) | brew install rtk |
| macOS / Linux (install script) | curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh |
| Windows | winget install rtk-ai.rtk |
| With Rust installed | cargo install --git https://github.com/rtk-ai/rtk |
| Any platform | Download a binary from the RTK releases |
Check it worked in a terminal:
rtk --versionA copy installed by Fabric Agents is used by the app even if another rtk is on your PATH.
Turn it on
If you used Install, it's already on. If you installed RTK yourself:
- Open Settings → AI → Performance.
- Under Token Optimization, click Re-check — the switch appears once RTK is found. (Learn more opens this page.)
- Switch Token Optimization on.
From then on it applies to every command the agent runs, in all sessions — there is nothing else to do. To stop, switch it off.
Once commands have gone through RTK, the same panel shows how much it saved — for example Saved 1.2M tokens across 340 commands · 74% avg efficiency. You can see the same numbers in a terminal with rtk gain (add --graph or --daily for history).
How it works
- Before running a Bash command, Fabric Agents asks RTK for a compressed form of it (
rtk rewrite) and runs that; RTK passes the command through unchanged when it has nothing to improve. - The command you see in the chat and the permission check both use your original command.
- The agent is told RTK is active, so it knows output may be grouped or summarised. When it needs exact output it runs the command without RTK — by prefixing it with
command(command grep …) or calling the binary by its full path (/usr/bin/grep …). You can ask for that too. - Commands starting with
commandorbuiltin, or run by full path, are never rewritten. If RTK fails or takes longer than 0.2 seconds to answer, the command runs unchanged.
Excluding commands
If you want some commands' output always unchanged, list their names in rtkExcludeCommands in ~/.fabric-agent/config.json:
{
"rtkExcludeCommands": ["grep", "cat"]
}Updates and troubleshooting
- "rtk … is outdated" — RTK versions before 0.44.0 can corrupt some command output (for example lines containing
:ingrepresults), so Fabric Agents pauses Token Optimization until you update. Click Update now to let Fabric install the latest version, or Update… for the command to run yourself. - Install failed — the message says why: no internet or GitHub unreachable (try again), a download that didn't match its checksum (nothing is installed), or no RTK build for your computer (RTK ships for macOS, Windows x64/ARM and Linux x64/ARM64).
- Installed but not detected — make sure
rtk --versionworks in a new terminal (the binary must be on yourPATH), then click Re-check. Restart Fabric Agents if you changed yourPATH. - To stop using it, switch Token Optimization off. Output goes back to uncompressed immediately; uninstalling RTK has the same effect.
- When not to use it: if you need the agent to see every line of output (for example, when debugging a tool's exact formatting), turn it off for that session or exclude the command.