---
slug: "pi-rtk-rewrite"
source_type: "readme"
source_url: "https://cdn.jsdelivr.net/gh/viartemev/pi-rtk-rewrite@main/README.md"
repo: "https://github.com/viartemev/pi-rtk-rewrite"
source_file: "README.md"
branch: "main"
---
# pi-rtk-rewrite

<p align="center">
  <b>Automatic RTK command rewrite for Pi bash tool calls</b><br/>
  Make Pi run compact, token-efficient RTK commands without changing your workflow.
</p>

<p align="center">
  <a href="https://github.com/viartemev/pi-rtk-rewrite/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
  <a href="https://github.com/rtk-ai/rtk"><img alt="Powered by RTK" src="https://img.shields.io/badge/powered%20by-rtk-8A2BE2" /></a>
  <a href="https://github.com/badlogic/pi-mono"><img alt="Pi compatible" src="https://img.shields.io/badge/pi-extension-22c55e" /></a>
</p>

---

## ✨ What this package does

`pi-rtk-rewrite` is a **Pi extension package** that intercepts Pi `bash` tool calls and runs:

```bash
rtk rewrite "<original command>"
```

If RTK returns a rewritten command, the extension transparently swaps it before execution.

### Example

- `git status` → `rtk git status`
- `cargo test` → `rtk cargo test`
- `ls -la` → `rtk ls -la`

(when RTK has a supported rewrite rule)

---

## ✅ Why use it

- **Lower token usage** in agent loops
- **Cleaner command output** sent back to the model
- **Zero workflow change** — keep typing normal commands
- **Safe fallback** — if RTK is missing or rewrite fails, original command still runs

---

## 📦 Requirements

- [Pi Coding Agent](https://github.com/badlogic/pi-mono)
- [`rtk`](https://github.com/rtk-ai/rtk) installed and available in `PATH`

Quick check:

```bash
rtk --version
```

---

## 🚀 Installation

### Install from npm

```bash
pi install npm:pi-rtk-rewrite
```

### Install from GitHub

```bash
pi install git:github.com/viartemev/pi-rtk-rewrite
```

or

```bash
pi install https://github.com/viartemev/pi-rtk-rewrite
```

For pinned GitHub install:

```bash
pi install git:github.com/viartemev/pi-rtk-rewrite@v0.2.1
```

Then in a running Pi session:

```text
/reload
```

---

## 🧭 Usage

After install, no extra setup is required.

Just ask Pi to execute normal bash commands. If rewrite exists, extension applies it automatically.

### Default behavior

If the extension is installed, rewrite is enabled. No config file or slash command is needed.

### Per-command opt-out

```bash
RTK_DISABLE_REWRITE=1 ls -la
# or
RTK_DISABLED=1 git status
```

---

## 🔍 Behavior details

The extension follows `rtk rewrite` exit semantics:

- `0` → rewrite applied
- `1` → no rewrite, run original command
- `2` → deny rule matched, run original command
- `3` → ask rule matched, rewrite applied automatically

It only targets Pi **`bash` tool calls**.

---

## 🛠 Local development

```bash
git clone https://github.com/viartemev/pi-rtk-rewrite
cd pi-rtk-rewrite
pi install ./
```

Then in Pi:

```text
/reload
```

---

## 🧪 Quick validation

Inside Pi:

1. Run `git status` → should be rewritten to `rtk git status`
2. Run `echo hello` → usually stays unchanged
3. Run `RTK_DISABLE_REWRITE=1 ls -la` → should stay unchanged

---

## 🤝 Contributing

PRs welcome. See [CONTRIBUTING.md](https://github.com/viartemev/pi-rtk-rewrite/blob/HEAD/CONTRIBUTING.md).

---

## 📄 License

MIT — see [LICENSE](https://github.com/viartemev/pi-rtk-rewrite/tree/HEAD/LICENSE).
