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
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rusqlite = { version = "0.31", features = ["bundled"] }
toml = "0.8"
chrono = "0.4"
thiserror = "1.0"
which = "7"
tempfile = "3"

[dev-dependencies]
Expand Down
59 changes: 59 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ rtk gain # MUST show token savings, not "command not found"

⚠️ **WARNING**: `cargo install rtk` from crates.io might install the wrong package. Always verify with `rtk gain`.

### Windows Installation

RTK compiles natively for Windows. Download from GitHub Releases or:

```bash
cargo install --path .
```

Configure Claude Code `settings.json`:

```json
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "rtk hook claude"
}]
}]
}
}
```

No bash, node, or bun required — `rtk hook claude` is a native Windows binary.
The exec.rs shell selection (`cfg!(windows)`) automatically uses `cmd /C` on Windows
and `sh -c` on Unix for passthrough commands.

## Project Initialization

### Recommended: Global Hook-First Setup
Expand Down Expand Up @@ -111,6 +139,37 @@ rtk init # Creates ./CLAUDE.md with full RTK instructions (137 lines)

**Token savings**: Instructions loaded only for this project

### Gemini CLI Setup

**Best for: Gemini CLI users wanting the same token optimization**

```bash
rtk init --gemini
# → Registers "rtk hook gemini" in ~/.gemini/settings.json
# → Prompts: "Patch settings.json? [y/N]"
# → If yes: patches + creates backup (~/.gemini/settings.json.bak)

# Automated alternatives:
rtk init --gemini --auto-patch # Patch without prompting
rtk init --gemini --no-patch # Print manual instructions instead

# Verify installation
rtk init --show # Shows both Claude and Gemini hook status
```

**Manual setup** (if `rtk init --gemini` isn't available):
```json
// Add to ~/.gemini/settings.json
{
"hooks": {
"BeforeTool": [{
"matcher": "run_shell_command",
"hooks": [{ "type": "command", "command": "rtk hook gemini" }]
}]
}
}
```

### Upgrading from Previous Version

If you previously used `rtk init -g` with the old system (137-line injection):
Expand Down
70 changes: 66 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[Website](https://www.rtk-ai.app) | [GitHub](https://github.com/rtk-ai/rtk) | [Install](INSTALL.md)

rtk filters and compresses command outputs before they reach your LLM context, saving 60-90% of tokens on common operations.
rtk filters and compresses command outputs before they reach your LLM context, saving 60-90% of tokens on common operations. Works with **Claude Code** and **Gemini CLI**.

## ⚠️ Important: Name Collision Warning

Expand Down Expand Up @@ -624,19 +624,81 @@ chmod +x ~/.claude/hooks/rtk-suggest.sh

The suggest hook detects the same commands as the rewrite hook but outputs a `systemMessage` instead of `updatedInput`, informing Claude Code that an rtk alternative exists.

## Gemini CLI Integration

RTK also supports [Gemini CLI](https://github.com/google-gemini/gemini-cli) via its **BeforeTool** hook protocol. The same safety engine that powers the Claude Code hook is used for Gemini, providing consistent command rewriting and blocking across both agents.

### Quick Install (Automated)

```bash
rtk init --gemini
# → Patches ~/.gemini/settings.json with BeforeTool hook
# → Prompts: "Patch settings.json? [y/N]"
# → Creates backup (~/.gemini/settings.json.bak) if file exists

# Options:
rtk init --gemini --auto-patch # Patch without prompting (CI/CD)
rtk init --gemini --no-patch # Skip patching, print manual JSON snippet

# Verify installation
rtk init --show
```

### Manual Install

Add the following to `~/.gemini/settings.json`:

```json
{
"hooks": {
"BeforeTool": [
{
"matcher": "run_shell_command",
"hooks": [
{
"type": "command",
"command": "rtk hook gemini"
}
]
}
]
}
}
```

### How It Works

When Gemini CLI is about to execute a shell command, it sends a JSON payload to `rtk hook gemini` on stdin. RTK's safety engine evaluates the command and responds with:

- **Allow + rewrite**: Rewrites the command to its `rtk run -c '...'` equivalent
- **Block**: Returns `"deny"` with a reason explaining which native tool to use instead
- **Passthrough**: Commands already using `rtk` pass through unchanged

The `matcher` field (`run_shell_command`) identifies Gemini's shell execution tool (analogous to Claude Code's `Bash` matcher). Non-shell tool events pass through without inspection.

### Uninstalling Gemini Hook

```bash
rtk init --gemini --uninstall
# → Removes RTK hook entry from ~/.gemini/settings.json
# → Preserves other hooks and settings
```

The global `rtk init -g --uninstall` also removes Gemini hooks alongside Claude Code hooks.

## Uninstalling RTK

**Complete Removal (Global Only)**:
```bash
rtk init -g --uninstall

# Removes:
# - ~/.claude/hooks/rtk-rewrite.sh
# - RTK hook from ~/.claude/settings.json
# - RTK hook from ~/.gemini/settings.json
# - ~/.claude/RTK.md
# - @RTK.md reference from ~/.claude/CLAUDE.md
# - RTK hook entry from ~/.claude/settings.json

# Restart Claude Code after uninstall
# Restart Claude Code / Gemini CLI after uninstall
```

**Restore from Backup** (if needed):
Expand Down
Loading