Skip to content

bjin/rtk-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rtk-shell 🐚

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.


🚀 Why rtk-shell?

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.

What is rtk?

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.

Why not just use the rtk plugin?

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:

  1. Operating at the Shell Level: By acting as the actual SHELL used by the agent, it provides a more robust, universal interception that covers 100% of terminal activity, including sub-agents.
  2. Intelligent Analysis: It uses the robust brush-parser to build an AST of every command to ensure wrapping is only applied when safe.
  3. Preserving Context: It ensures that standard behavior for pipes, redirections, and machine-parsed output is never broken.

🛠️ How It Works

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 rtk if the command's stdout is going directly to the terminal. If you're piping output (ls | grep) or redirecting to a file (git status > log.txt), rtk-shell steps 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.

📦 Installation & Usage

1. Build the Binary

Ensure you have Rust installed, then run:

cargo build --release

The resulting binary will be located at target/release/rtk-shell.

2. Integration with Agents

To use it with an agent like opencode, invoke it with the SHELL environment variable set:

SHELL=/path/to/rtk-shell opencode

Alternatively, you can test it directly:

./rtk-shell -c "ls -al"

✅ Supported Commands

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

📜 LICENSE

This project is licensed under the MIT License. See the LICENSE file for details.

About

a transparent shell wrapper designed to optimize token consumption for LLM-based agents

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages