Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ rtk gain # Should show token savings stats
rtk init -g # Claude Code / Copilot (default)
rtk init -g --gemini # Gemini CLI
rtk init -g --codex # Codex (OpenAI)
rtk init --agent omp # Oh My Pi (OMP, project extension)
rtk init -g --agent omp # Oh My Pi (OMP, user extension)
rtk init -g --agent cursor # Cursor
rtk init --agent windsurf # Windsurf
rtk init --agent cline # Cline / Roo Code
Expand Down Expand Up @@ -350,7 +352,7 @@ rtk git status

## Supported AI Tools

RTK supports 12 AI coding tools. Each integration transparently rewrites shell commands to `rtk` equivalents for 60-90% token savings.
RTK supports 13 AI coding tools. Hook, plugin, and extension integrations transparently rewrite shell commands to `rtk` equivalents; rules-file integrations install guidance that tells the agent to prefer `rtk <cmd>` on supported commands.

| Tool | Install | Method |
|------|---------|--------|
Expand All @@ -360,6 +362,7 @@ RTK supports 12 AI coding tools. Each integration transparently rewrites shell c
| **Cursor** | `rtk init -g --agent cursor` | preToolUse hook (hooks.json) |
| **Gemini CLI** | `rtk init -g --gemini` | BeforeTool hook |
| **Codex** | `rtk init -g --codex` | AGENTS.md + RTK.md instructions |
| **Oh My Pi (OMP)** | `rtk init --agent omp` / `rtk init -g --agent omp` | OMP extension (`tool_call`) — `./.omp/extensions/rtk.ts` or `~/.omp/agent/extensions/rtk.ts` |
| **Windsurf** | `rtk init --agent windsurf` | .windsurfrules (project-scoped) |
| **Cline / Roo Code** | `rtk init --agent cline` | .clinerules (project-scoped) |
| **OpenCode** | `rtk init -g --opencode` | Plugin TS (tool.execute.before) |
Expand Down
4 changes: 3 additions & 1 deletion docs/contributing/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,14 @@ Start here, then drill down into each README for file-level details.
| [`cline/`](../hooks/cline/README.md) | Cline / Roo Code | Rules file (prompt-level, no programmatic hook) |
| [`windsurf/`](../hooks/windsurf/README.md) | Windsurf / Cascade | Rules file (workspace-scoped) |
| [`codex/`](../hooks/codex/README.md) | OpenAI Codex CLI | Awareness document, AGENTS.md integration |
| [`omp/`](../hooks/omp/README.md) | Oh My Pi | TypeScript extension module, project/user `.omp/extensions/` or `~/.omp/agent/extensions/` |
| [`opencode/`](../hooks/opencode/README.md) | OpenCode | TypeScript plugin, zx library, in-place mutation |

---

## 5. Hook System Summary

RTK supports the following LLM agents through hook integrations:
RTK supports the following LLM agent integrations:

| Agent | Hook Type | Mechanism | Can Modify Command? |
|-------|-----------|-----------|---------------------|
Expand All @@ -334,6 +335,7 @@ RTK supports the following LLM agents through hook integrations:
| Cline/Roo Code | Rules file | Prompt-level guidance | N/A (prompt) |
| Windsurf | Rules file | Prompt-level guidance | N/A (prompt) |
| Codex CLI | Awareness doc | AGENTS.md integration | N/A (prompt) |
| Oh My Pi | Extension module | OMP `tool_call` event | Yes (`event.input`) |
| OpenCode | TS plugin | `tool.execute.before` event | Yes (in-place mutation) |

> **Details**: [`hooks/README.md`](../hooks/README.md) has the full JSON schemas for each agent. [`src/hooks/README.md`](../src/hooks/README.md) covers installation, integrity verification, and the rewrite command.
Expand Down
21 changes: 16 additions & 5 deletions docs/guide/getting-started/supported-agents.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Supported Agents
description: How to integrate RTK with Claude Code, Cursor, Copilot, Cline, Windsurf, Codex, OpenCode, Kilo Code, and Antigravity
description: How to integrate RTK with Claude Code, Cursor, Copilot, Cline, Windsurf, Codex, OpenCode, Kilo Code, Antigravity, and Oh My Pi
sidebar:
order: 3
---
Expand All @@ -11,9 +11,9 @@ RTK supports all major AI coding agents across 3 integration tiers. Mistral Vibe

## How it works

Each agent integration intercepts CLI commands before execution and rewrites them to their RTK equivalent. The agent runs `rtk cargo test` instead of `cargo test`, sees filtered output, and uses up to 90% fewer tokens — without any change to your workflow.
Hook, plugin, and extension integrations intercept CLI commands before execution and rewrite them to their RTK equivalent. Rules-file integrations install prompt-level guidance that tells the model to prefer `rtk <cmd>` instead.

All rewrite logic lives in the RTK binary (`rtk rewrite`). Agent hooks are thin delegates that parse the agent-specific JSON format and call `rtk rewrite` for the actual decision.
All transparent rewrite integrations delegate final rewrite decisions to the RTK binary (`rtk rewrite`).

```
Agent runs "cargo test"
Expand All @@ -35,6 +35,7 @@ Agent runs "cargo test"
| Gemini CLI | Rust binary (`BeforeTool`) | Yes |
| OpenCode | TypeScript plugin (`tool.execute.before`) | Yes |
| OpenClaw | TypeScript plugin (`before_tool_call`) | Yes |
| Oh My Pi (OMP) | TypeScript extension (`tool_call`) | Yes |
| Cline / Roo Code | Rules file (prompt-level) | N/A |
| Windsurf | Rules file (prompt-level) | N/A |
| Codex CLI | AGENTS.md instructions | N/A |
Expand Down Expand Up @@ -112,6 +113,16 @@ rtk init --windsurf # creates .windsurfrules in current project
rtk init --codex # creates AGENTS.md or patches existing one
```

### Oh My Pi

```bash
rtk init --agent omp # creates ./.omp/extensions/rtk.ts
rtk init -g --agent omp # creates ~/.omp/agent/extensions/rtk.ts
```

Oh My Pi loads project extensions from `.omp/extensions/` and user extensions from `~/.omp/agent/extensions/`. RTK installs a dedicated `rtk.ts` extension that intercepts `bash` tool calls and delegates rewrite decisions to `rtk rewrite`.


### Kilo Code

```bash
Expand All @@ -137,10 +148,10 @@ Support is blocked on upstream `BeforeToolCallback` ([mistral-vibe#531](https://
| Tier | Mechanism | How rewrites work |
|------|-----------|------------------|
| **Full hook** | Shell script or Rust binary, intercepts via agent API | Transparent — agent never sees the raw command |
| **Plugin** | TypeScript/JS in agent's plugin system | Transparent — in-place mutation |
| **Plugin / extension** | TypeScript/JS in the agent runtime | Transparent — in-place mutation |
| **Rules file** | Prompt-level instructions | Guidance only — agent is told to prefer `rtk <cmd>` |

Rules file integrations (Cline, Windsurf, Codex, Kilo Code, Antigravity) rely on the model following instructions. Full hook integrations (Claude Code, Cursor, Gemini) are guaranteed — the command is rewritten before the agent sees it.
Rules file integrations (Cline, Windsurf, Codex, Kilo Code, Antigravity) rely on the model following instructions. Full hook integrations (Claude Code, Cursor, Gemini) and runtime extension/plugin integrations (OpenCode, Oh My Pi) transparently rewrite commands before execution.

## Windows support

Expand Down
8 changes: 5 additions & 3 deletions hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

## Scope

**Deployed hook artifacts** — the actual files installed on user machines by `rtk init`. These are shell scripts, TypeScript plugins, and rules files that run outside the Rust binary. They are **thin delegates**: parse agent-specific JSON, call `rtk rewrite` as a subprocess, format agent-specific response. Zero filtering logic lives here.
**Deployed hook artifacts** — the actual files installed on user machines by `rtk init`. These are shell scripts, TypeScript plugins/extensions, and rules files that run outside the Rust binary. They are **thin delegates**: parse agent-specific input, call `rtk rewrite` as a subprocess when transparent rewrite is supported, or install agent-native guidance files when it is not.

Owns: per-agent hook scripts and configuration files for 7 supported agents (Claude Code, Copilot, Cursor, Cline, Windsurf, Codex, OpenCode).
Owns: per-agent hook scripts and configuration files for the supported integrations in this repo.

Does **not** own: hook installation/uninstallation (that's `src/hooks/init.rs`), the rewrite pattern registry (that's `discover/registry`), or integrity verification (that's `src/hooks/integrity.rs`).

Relationship to `src/hooks/`: that component **creates** these files; this directory **contains** them.

## Purpose

LLM agent integrations that intercept CLI commands and route them through RTK for token optimization. Each hook transparently rewrites raw commands (e.g., `git status`) to their RTK equivalents (e.g., `rtk git status`), delivering 60-90% token savings without requiring the agent or user to change their workflow.
LLM agent integrations that either intercept CLI commands and route them through RTK, or install prompt-level rules that tell the model to prefer `rtk <cmd>`. Hook, plugin, and extension integrations transparently rewrite raw commands (e.g., `git status`) to their RTK equivalents (e.g., `rtk git status`), delivering 60-90% token savings without requiring the agent or user to change their workflow.

## How It Works

Expand All @@ -39,6 +39,7 @@ Each agent subdirectory has its own README with hook-specific details:
- **[`cline/`](cline/README.md)** — Rules file (prompt-level), `.clinerules` project-local installation
- **[`windsurf/`](windsurf/README.md)** — Rules file (prompt-level), `.windsurfrules` workspace-scoped
- **[`codex/`](codex/README.md)** — Awareness document, `AGENTS.md` integration, `$CODEX_HOME` or `~/.codex/` location
- **[`omp/`](omp/README.md)** — TypeScript extension, OMP `tool_call` rewrite via `./.omp/extensions/rtk.ts` or `~/.omp/agent/extensions/rtk.ts`
- **[`opencode/`](opencode/README.md)** — TypeScript plugin, `zx` library, `tool.execute.before` event, in-place mutation

## Supported Agents
Expand All @@ -53,6 +54,7 @@ Each agent subdirectory has its own README with hook-specific details:
| Cline / Roo Code | Custom instructions (rules file) | Prompt-level guidance | N/A |
| Windsurf | Custom instructions (rules file) | Prompt-level guidance | N/A |
| Codex CLI | AGENTS.md / instructions | Prompt-level guidance | N/A |
| Oh My Pi (OMP) | TypeScript extension (`tool_call`) | In-place mutation | Yes (`event.input`) |
| OpenCode | TypeScript plugin (`tool.execute.before`) | In-place mutation | Yes |

## JSON Formats by Agent
Expand Down
13 changes: 13 additions & 0 deletions hooks/omp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Oh My Pi Hooks

> Part of [`hooks/`](../README.md) — see also [`src/hooks/`](../../src/hooks/README.md) for installation code

## Specifics

- TypeScript extension module, not a shell hook or rules file
- Installs to `./.omp/extensions/rtk.ts` with `rtk init --agent omp`, or to `~/.omp/agent/extensions/rtk.ts` with `rtk init -g --agent omp`
- Intercepts OMP `tool_call` events for the `bash` tool and delegates rewrite decisions to `rtk rewrite`
- Auto-rewrites supported commands without prompting; RTK deny verdicts still block execution
- Startup check: if `rtk` is not on `PATH` when the extension loads, it registers no handler and stays silent (no per-call spawn cost)
- Requires Bun runtime (uses `Bun.which` and `Bun.spawn`); OMP currently ships with Bun
- Multi-extension chaining: OMP dispatches `tool_call` handlers sequentially. If another extension also listens on `tool_call`, downstream handlers will observe the RTK-rewritten `event.input.command`, not the original
81 changes: 81 additions & 0 deletions hooks/omp/rtk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// RTK - Rust Token Killer
// OMP extension: rewrite bash tool calls through `rtk rewrite`.
//
// This is a thin delegating extension. All rewrite logic lives in RTK's Rust
// registry via `rtk rewrite`, which remains the single source of truth.

type ExtensionAPI = {
on(event: "tool_call", handler: (event: any) => Promise<{ block: true; reason: string } | void> | { block: true; reason: string } | void): void;
};

type RewriteDecision =
| { kind: "rewrite"; rewritten: string }
| { kind: "deny"; reason: string }
| { kind: "skip" };

async function readText(stream: ReadableStream<Uint8Array> | null | undefined): Promise<string> {
if (!stream) return "";
return (await new Response(stream).text()).trim();
}

async function rewriteWithRtk(command: string): Promise<RewriteDecision> {
try {
const proc = Bun.spawn(["rtk", "rewrite", command], {
stdout: "pipe",
stderr: "pipe",
});

const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
readText(proc.stdout),
readText(proc.stderr),
]);

switch (exitCode) {
case 0:
case 3:
return stdout ? { kind: "rewrite", rewritten: stdout } : { kind: "skip" };
case 1:
return { kind: "skip" };
case 2:
return {
kind: "deny",
reason: stderr || `Blocked by RTK policy: ${command}`,
};
default:
return { kind: "skip" };
}
} catch {
return { kind: "skip" };
}
}

export default function rtkOmpExtension(pi: ExtensionAPI) {
// Startup check: if rtk is not on PATH, register no handler and stay silent.
// Matches the opencode plugin pattern (`await $\`which rtk\``) and avoids
// paying a spawn cost on every bash tool_call when rtk is unavailable.
if (!Bun.which("rtk")) {
return;
}

pi.on("tool_call", async (event) => {
if (event.toolName !== "bash") {
return;
}

const original = event.input.command;
if (typeof original !== "string" || original.trim() === "") {
return;
}

const decision = await rewriteWithRtk(original);
if (decision.kind === "skip") {
return;
}
if (decision.kind === "deny") {
return { block: true, reason: decision.reason };
}

event.input.command = decision.rewritten;
});
}
9 changes: 5 additions & 4 deletions src/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

The **lifecycle management** layer for LLM agent hooks: install, uninstall, verify integrity, audit usage, and manage trust. This component creates and maintains the hook artifacts that live in `hooks/` (root), but does **not** execute rewrite logic itself — that lives in `discover/registry`.

Owns: `rtk init` installation flows (4 agents via `AgentTarget` enum + 3 special modes: Gemini, Codex, OpenCode), SHA-256 integrity verification, hook version checking, audit log analysis, `rtk rewrite` CLI entry point, and TOML filter trust management.
Owns: `rtk init` installation flows for AgentTarget-based integrations plus Gemini, Codex, and OpenCode special modes, SHA-256 integrity verification, hook version checking, audit log analysis, `rtk rewrite` CLI entry point, and TOML filter trust management.

Does **not** own: the deployed hook scripts themselves (that's `hooks/`), the rewrite pattern registry (that's `discover/`), or command filtering (that's `cmds/`).

Boundary notes:
- `rewrite_cmd.rs` is a thin CLI bridge — it exists to serve hooks (hooks call `rtk rewrite` as a subprocess) and delegates entirely to `discover/registry`.
- `rewrite_cmd.rs` is a thin CLI bridge — it exists to serve hooks and extensions (they call `rtk rewrite` as a subprocess) and delegates entirely to `discover/registry`.
- `trust.rs` gates project-local TOML filter execution. It lives here because the trust workflow is tied to hook-installed filter discovery, not to the core filter engine.

## Purpose
LLM agent integration layer that installs, validates, and executes command-rewriting hooks for AI coding assistants. Hooks intercept raw CLI commands (e.g., `git status`) and rewrite them to RTK equivalents (e.g., `rtk git status`) so that LLM agents automatically benefit from token savings without explicit user configuration.
LLM agent integration layer that installs, validates, and executes command-rewriting hooks for AI coding assistants, plus extension modules and rules files for agents that rely on those surfaces instead of shell hooks.

## Installation Modes

`rtk init` supports 6 distinct installation flows:
`rtk init` supports these installation flows:

| Mode | Command | Creates | Patches |
|------|---------|---------|---------|
Expand All @@ -28,6 +28,7 @@ LLM agent integration layer that installs, validates, and executes command-rewri
| Claude-MD (legacy) | `rtk init --claude-md` | 134-line RTK block | CLAUDE.md |
| Windsurf | `rtk init -g --agent windsurf` | `.windsurfrules` | -- |
| Cline | `rtk init --agent cline` | `.clinerules` | -- |
| Oh My Pi | `rtk init --agent omp` / `rtk init -g --agent omp` | `.omp/extensions/rtk.ts` or `~/.omp/agent/extensions/rtk.ts` | -- |
| Codex | `rtk init --codex` | RTK.md in `$CODEX_HOME` or `~/.codex` | AGENTS.md |
| Cursor | `rtk init -g --agent cursor` | Cursor hook | hooks.json |

Expand Down
2 changes: 2 additions & 0 deletions src/hooks/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pub const OPENCODE_PLUGIN_PATH: &str = ".config/opencode/plugins/rtk.ts";
pub const CURSOR_DIR: &str = ".cursor";
pub const CODEX_DIR: &str = ".codex";
pub const GEMINI_DIR: &str = ".gemini";
pub const OMP_GLOBAL_EXTENSION_PATH: &str = ".omp/agent/extensions/rtk.ts";
pub const OMP_PROJECT_EXTENSION_PATH: &str = ".omp/extensions/rtk.ts";
Loading