rtk-shell is a transparent shell wrapper designed to optimize token consumption for LLM-based agents. It acts as a lightweight intermediary between your agent and your system's shell, intelligently condensing command output by integrating with rtk.
LLM agents frequently run commands like ls -al, git status, or find .. The standard output of these commands is often verbose and filled with data that isn't strictly necessary for the agent to understand the state of your project. This "token bloat" leads to higher costs and slower response times.
rtk (Rust Token Killer) is a high-performance CLI proxy that reduces LLM token consumption by 60-90% by filtering and summarizing verbose command outputs into agent-friendly formats.
While rtk provides an opencode plugin, it relies on high-level tool hooks to intercept and rewrite commands. This approach has limitations—specifically, it often misses commands executed by sub-agents or complex internal shell calls.
rtk-shell solves this by:
- Operating at the Shell Level: By acting as the actual
SHELLused by the agent, it provides a more robust, universal interception that covers 100% of terminal activity, including sub-agents. - Intelligent Analysis: It uses the robust
brush-parserto build an AST of every command to ensure wrapping is only applied when safe. - Preserving Context: It ensures that standard behavior for pipes, redirections, and machine-parsed output is never broken.
rtk-shell is not a full shell itself; it's a smart proxy. When you run a command through it:
- Deep Parsing: It parses your bash command into an Abstract Syntax Tree (AST).
- Safe-to-Wrap Logic: It only injects
rtkif the command'sstdoutis going directly to the terminal. If you're piping output (ls | grep) or redirecting to a file (git status > log.txt),rtk-shellsteps out of the way and executes the command unmodified. - Path Awareness: It strictly ignores commands called with absolute or relative paths (like
/usr/bin/ls) to ensure system scripts aren't accidentally modified. - Recursion Protection: It includes multiple layers of protection (environment variables and path canonicalization) to prevent infinite loops.
Ensure you have Rust installed, then run:
cargo build --releaseThe resulting binary will be located at target/release/rtk-shell.
To use it with an agent like opencode, invoke it with the SHELL environment variable set:
SHELL=/path/to/rtk-shell opencodeAlternatively, you can test it directly:
./rtk-shell -c "ls -al"rtk-shell intelligently wraps a wide variety of tools supported by rtk, including:
- File System:
ls,tree,find,wc - VCS:
git(status, diff, log, etc.),gh(api, pr list, etc.) - Dev Tools:
cargo,go,npm,pnpm,pip,docker,kubectl - Linters/Testers:
ruff,pytest,tsc,mypy - Networking:
curl,wget
This project is licensed under the MIT License. See the LICENSE file for details.