Reduce LLM Token Costs for Dev Commands with rtk CLI Proxy
Job to be done: Reduce LLM token consumption for developer commands
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
When debugging your final year project's Python code with Google Gemini in the terminal, use `rtk` to compress `ls -l` or `git status` outputs, saving tokens and extending your free AI usage.
- Entrepreneur
As a solo founder building your e-commerce platform's backend, use `rtk` with your GitHub Copilot CLI to reduce token costs when asking for help with `git diff` or `cargo test` outputs, stretching your development budget further.
- 9-5 employee
As a software engineer, integrate `rtk` into your terminal to automatically compress `kubectl get pods` or `docker ps` outputs before sending them to your company's OpenAI-powered coding assistant, reducing monthly API spend.
What you’ll get
You’ll get a command-line proxy that automatically filters and compresses the output of common developer commands (like ls, git status, cargo test) before sending them to your AI coding assistant. This significantly reduces the number of tokens consumed by your Large Language Model (LLM) by 60-90%, leading to lower API costs and potentially faster responses. This approach works by intelligently reducing verbosity, making your AI interactions more efficient.
Tools you need
- rtk (free): The core CLI proxy tool that optimizes LLM token usage.
- Homebrew (free): A package manager for macOS and Linux, recommended for easy installation of
rtk. - curl (free): A command-line tool for downloading files, used for quick installation on Linux/macOS.
- sh (free): A command-line interpreter (shell) used to execute installation scripts.
- Cargo (free): Rust’s package manager, an alternative installation method for
rtk. - Claude AI (freemium): An AI assistant that
rtkcan proxy for, offering coding help. - GitHub Copilot (paid): An AI pair programmer that
rtkcan proxy for, enhancing coding efficiency. - Google Gemini (freemium): Google’s AI assistant that
rtkcan proxy for, useful for coding tasks. - OpenAI (paid): Provides powerful AI models (like GPT-4) that
rtkcan proxy for, used in various AI coding tools. - Cursor (freemium): An AI-powered code editor that
rtkcan integrate with.
Steps
-
Open your terminal: On macOS, find “Terminal” in Applications > Utilities. On Linux, it’s usually called “Terminal” or “Konsole”. On Windows, run these steps inside WSL (Windows Subsystem for Linux), because the install commands below rely on Homebrew, curl, and shell startup files that the plain Command Prompt and PowerShell do not provide.
-
Install rtk using Homebrew (macOS/Linux): If you have Homebrew installed, this is the easiest way. If not, proceed to the next step for a quick install.
brew install rtkYou should see output indicating
rtkis being downloaded and installed. If Homebrew isn’t installed, you’ll get an error; in that case, use thecurlmethod below. -
Alternatively, quick install rtk (Linux/macOS): If you don’t use Homebrew or prefer a direct install, use this command. It downloads and runs an installation script.
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | shYou’ll see messages about
rtkbeing installed, typically to~/.local/bin. -
Add rtk to your system PATH (if needed): If the quick install placed
rtkin~/.local/binand your system doesn’t automatically find commands there, you need to add it to your PATH.echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # For Bash users # OR echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # For Zsh usersAfter running this, close and reopen your terminal, or run
source ~/.bashrc(or~/.zshrc) to apply the change immediately. You won’t see direct output, but the command will be added to your shell’s configuration file. -
Verify rtk installation: Check that
rtkis correctly installed and working.rtk --versionYou should see the installed
rtkversion (e.g., “rtk 0.28.2”). Then, check its token savings capabilities:rtk gainYou should see a table or summary of estimated token savings. If you get an error like “command not found”, revisit step 4. If it shows stats,
rtkis ready. -
Initialize rtk for your AI coding assistant:
rtkneeds to know which AI tool it should proxy for. The default is for Claude Code/Copilot.rtk init -gIf you use a different tool, specify it:
rtk init -g --gemini # For Google Gemini CLI # OR rtk init -g --codex # For OpenAI Codex (or other OpenAI-based tools) # OR rtk init -g --agent cursor # For Cursor editor # OR rtk init -g --agent windsurf # For WindsurfYou should see a confirmation message indicating that
rtkhas been initialized for your chosen agent. This sets up the global proxy. -
Use your AI coding assistant as usual: Once
rtkis initialized, it works in the background. Continue using your preferred AI coding assistant (e.g., Claude Code, GitHub Copilot, Gemini CLI) for your development tasks. You won’t seertkdirectly, but it will automatically intercept and optimize the output of common commands (likels,git status,cargo test) before they reach your AI’s context, reducing token usage. The expected result is that your AI assistant will receive more concise information, potentially leading to faster and more cost-effective interactions.
Original source
This workflow is based on the rtk-ai/rtk project, an open-source CLI proxy designed to optimize Large Language Model token consumption for developers. The project is hosted on GitHub by rtk-ai.
Notes & variations
- Free-tier viability: The
rtktool itself is completely free and open-source, running locally on your device. However, it acts as a proxy for various AI coding assistants (like Claude AI, GitHub Copilot, Google Gemini, OpenAI), many of which operate on a freemium or paid model. Whilertksignificantly reduces the token consumption (and thus potential cost and data for API calls) of these LLMs, you will still need to consider the pricing and data plans of the specific AI assistant you choose to use withrtk. Some LLMs offer free tiers or credits that can be leveraged. - Common mistake: Be aware of a name collision with “Rust Type Kit” if you’re installing via
cargo install. Ifrtk gainfails, you might have installed the wrong package. In that case, usecargo install --git https://github.com/rtk-ai/rtkinstead. - Installation alternatives: Besides Homebrew and the quick install script, you can also install
rtkusingcargo install --git https://github.com/rtk-ai/rtkif you have Rust and Cargo installed, or by downloading pre-built binaries directly from the GitHub releases page for your operating system (macOS, Linux, Windows). - Windows users: For the best experience and full functionality of
rtk’s hook system, it is highly recommended to use Windows Subsystem for Linux (WSL). If running natively on Windows, extract thertk.exefrom the zip and place it in your PATH (e.g.,C:\Users\your_username\.local\bin). Runrtkfrom Command Prompt, PowerShell, or Windows Terminal; do not double-click the.exefile. - Tip for better results: Regularly check
rtk gainto monitor your token savings and ensurertkis actively optimizing your LLM interactions. The savings vary by project size and command frequency, but consistent use will lead to significant reductions over time.