@sherif-fanous/pi-rtk
Pi extension that routes bash commands through rtk (Rust Token Killer) for LLM token savings
Package details
Install @sherif-fanous/pi-rtk from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@sherif-fanous/pi-rtk- Package
@sherif-fanous/pi-rtk- Version
0.3.0- Published
- Mar 18, 2026
- Downloads
- 331/mo · 112/wk
- Author
- sherif-fanous
- License
- MIT
- Types
- extension
- Size
- 8.1 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-rtk
Pi coding agent extension that uses rtk to reduce LLM token usage for shell command execution.
When pi-rtk is loaded, it participates in two Pi shell paths:
- agent-initiated
bashtool calls - user-issued
!<cmd>shell commands whose output is included in model context
In both cases, pi-rtk first attempts to rewrite the command with:
rtk rewrite "<original command>"
If rewrite succeeds, Pi executes the rewritten command. If rewrite fails for any reason, pi-rtk falls back silently so normal Pi shell behavior continues.
Commands entered with !!<cmd> are intentionally not intercepted. They continue through Pi's normal context-excluded shell execution path unchanged.
Prerequisites
- Pi v0.60.0 or later
- rtk, installed and available on your
PATH
If rtk is unavailable, pi-rtk still preserves normal shell behavior by falling back to the original command.
Install
Make sure your Pi installation is v0.60.0 or later before installing this package.
pi install npm:@sherif-fanous/pi-rtk
Or try without installing:
pi -e npm:@sherif-fanous/pi-rtk
To uninstall:
pi remove npm:@sherif-fanous/pi-rtk
How It Works
Agent bash tool calls
pi-rtk registers a replacement bash tool for Pi. Before the tool executes a command, the extension attempts an rtk rewrite and uses the rewritten command when available.
This preserves the normal bash tool interface while routing supported commands through rtk, which can filter and compress output before it reaches the model.
If rtk is unavailable, times out, or cannot rewrite the command, the original command runs unchanged.
Behavior summary
Agent bash tool call
│
▼
pi-rtk replacement bash tool
│
├─ try: rtk rewrite "<command>"
│ │
│ ├─ success -> execute rewritten command
│ └─ failure -> execute original command unchanged
│
▼
same bash tool interface to Pi
User !<cmd> shell commands
pi-rtk also hooks Pi's user_bash event for context-visible user shell commands entered with !<cmd>.
For these commands, the extension probes rewrite eligibility before claiming the event. If rewrite succeeds, it returns custom bash operations so Pi can keep owning the normal execution lifecycle and UI behavior. If rewrite does not succeed, the extension falls through and Pi handles the command normally.
This keeps optimization best-effort, silent, and non-disruptive during normal operation.
Behavior summary
User !<cmd>
│
├─ try: rtk rewrite "<command>"
│ │
│ ├─ success -> return custom bash operations
│ └─ failure -> fall through to normal Pi user_bash handling
│
▼
same user shell experience in Pi
User !!<cmd> shell commands
Commands entered with !!<cmd> are excluded from model context by design, so pi-rtk does not intercept them.
They bypass pi-rtk completely and continue through Pi's normal context-excluded shell handling.
Behavior summary
User !!<cmd>
│
▼
bypass pi-rtk and use normal Pi context-excluded shell handling