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
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,47 @@ rtk init --show # Verify hook is installed and executable

**New in v0.9.5**: Hook-first installation eliminates ~2000 tokens from Claude's context while maintaining full RTK functionality through transparent command rewriting.

## OpenCode Support

RTK also supports [OpenCode](https://opencode.ai) as an alternative to Claude Code. The integration uses OpenCode's native plugin system for transparent command rewriting.

### Quick Start (OpenCode)

```bash
# 1. Verify rtk is installed
rtk gain # Must show token stats

# 2. Initialize for OpenCode (global)
rtk init --opencode --global
# → Installs plugin to ~/.config/opencode/plugins/rtk.ts
# → Installs rules to ~/.config/opencode/rules/rtk.md
# → Creates RTK.md reference doc

# 3. Restart OpenCode, then test
git status # Plugin transparently rewrites to: rtk git status

# Alternative: per-project install
rtk init --opencode
# → Installs to .opencode/plugins/ and .opencode/rules/
```

### OpenCode Commands

```bash
rtk init --opencode --global # Install globally for all OpenCode projects
rtk init --opencode # Install for current project only
rtk init --opencode --show # Show current OpenCode RTK configuration
rtk init --opencode --uninstall # Remove local RTK artifacts
rtk init --opencode --uninstall -g # Remove global RTK artifacts
rtk discover --opencode # Scan OpenCode sessions for missed savings
```

### How It Works (OpenCode)

RTK's OpenCode integration uses the [plugin system](https://opencode.ai/docs/plugins). The plugin hooks into the `tool.execute.before` event to intercept bash commands and rewrite them to their rtk equivalents before execution. This is the same approach as Claude Code's PreToolUse hook, but implemented natively in TypeScript using OpenCode's plugin API.

No configuration file patching is needed — OpenCode automatically discovers plugins in its plugins directory.

## Global Flags

```bash
Expand Down Expand Up @@ -342,18 +383,29 @@ FAILED: 2/15 tests

### Installation Modes

#### Claude Code

| Command | Scope | Hook | RTK.md | CLAUDE.md | Tokens in Context | Use Case |
|---------|-------|------|--------|-----------|-------------------|----------|
| `rtk init -g` | Global | ✅ | ✅ (10 lines) | @RTK.md | ~10 | **Recommended**: All projects, automatic |
| `rtk init -g --claude-md` | Global | ❌ | ❌ | Full (137 lines) | ~2000 | Legacy compatibility |
| `rtk init -g --hook-only` | Global | ✅ | ❌ | Nothing | 0 | Minimal setup, hook-only |
| `rtk init` | Local | ❌ | ❌ | Full (137 lines) | ~2000 | Single project, no hook |

#### OpenCode

| Command | Scope | Plugin | Rules | RTK.md | Use Case |
|---------|-------|--------|-------|--------|----------|
| `rtk init --opencode -g` | Global | ✅ | ✅ | ✅ | **Recommended**: All OpenCode projects |
| `rtk init --opencode` | Local | ✅ | ✅ | ✅ | Single project |

```bash
rtk init --show # Show current configuration
rtk init -g # Install hook + RTK.md (recommended)
rtk init -g # Install hook + RTK.md (recommended, Claude Code)
rtk init -g --claude-md # Legacy: full injection into CLAUDE.md
rtk init # Local project: full injection into ./CLAUDE.md
rtk init --opencode -g # Install plugin for OpenCode (global)
rtk init --opencode # Install plugin for OpenCode (local)
```

### Installation Flags
Expand Down Expand Up @@ -657,6 +709,19 @@ cp ~/.claude/settings.json.bak ~/.claude/settings.json

**Local Projects**: Manually remove RTK instructions from `./CLAUDE.md`

**OpenCode Removal**:
```bash
rtk init --opencode -g --uninstall # Global
rtk init --opencode --uninstall # Local project

# Removes:
# - plugins/rtk.ts
# - rules/rtk.md
# - RTK.md

# Restart OpenCode after uninstall
```

**Binary Removal**:
```bash
# If installed via cargo
Expand Down
25 changes: 25 additions & 0 deletions hooks/opencode-rtk-awareness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RTK - Rust Token Killer

**Usage**: Token-optimized CLI proxy (60-90% savings on dev operations)

## Meta Commands (always use rtk directly)

```bash
rtk gain # Show token savings analytics
rtk gain --history # Show command usage history with savings
rtk discover # Analyze OpenCode history for missed opportunities
rtk proxy <cmd> # Execute raw command without filtering (for debugging)
```

## Installation Verification

```bash
rtk --version # Should show: rtk X.Y.Z
rtk gain # Should work (not "command not found")
which rtk # Verify correct binary
```

## Plugin-Based Usage

All other commands are automatically rewritten by the OpenCode RTK plugin.
Example: `git status` → `rtk git status` (transparent, 0 tokens overhead)
Loading
Loading