Skip to content

feat: add OpenCode plugin support#300

Open
zeval wants to merge 12 commits intortk-ai:feat/rtk-rewritefrom
zeval:feature/opencode-support-11n
Open

feat: add OpenCode plugin support#300
zeval wants to merge 12 commits intortk-ai:feat/rtk-rewritefrom
zeval:feature/opencode-support-11n

Conversation

@zeval
Copy link

@zeval zeval commented Mar 2, 2026

Warning

Depends on #241 which streamlines the rewrite logic so that hooks don't have to repeat code

Summary

Add OpenCode plugin support to RTK. The plugin uses OpenCode's tool.execute.before hook to rewrite Bash/Shell tool commands to rtk ... before execution.

Built on top of PR #241 (rtk rewrite): the OpenCode plugin is a thin 38-line wrapper that delegates all rewrite logic to rtk rewrite.

What's added

  • hooks/opencode-rtk.ts (38 lines) — OpenCode plugin that calls rtk rewrite via shell
  • rtk init -g --opencode — install the plugin to ~/.config/opencode/plugins/rtk.ts
  • rtk init -g — now installs both Claude Code hook AND OpenCode plugin by default
  • rtk init -g --claude / --opencode — install only one integration
  • rtk init --show — reports OpenCode plugin status
  • rtk init -g --uninstall — removes OpenCode plugin alongside Claude Code artifacts
  • Docs: README section, troubleshooting guide

Architecture

Claude Code hook   55-line bash  ─┐
OpenCode plugin    38-line TS    ─┤  rtk rewrite "cmd"
Future hooks       ~15 lines    ─┘  (single source of truth)
                                     └── src/rewrite_cmd.rs
                                     └── src/discover/registry.rs

Both hooks are thin protocol adapters. All rewrite logic lives in Rust.

Design decisions

  • --opencode as opt-in flag: `rtk init -g` installs both by default; `--claude` or `--opencode` installs only one
  • Plugin directory: `~/.config/opencode/plugins/` per OpenCode docs
  • No parity test needed: both hooks delegate to `rtk rewrite`, so there's nothing to drift
  • Known limitation: OpenCode plugin hooks don't intercept subagent tool calls (upstream issue)

Files changed

File Change
`hooks/opencode-rtk.ts` New — 38-line thin wrapper calling `rtk rewrite`
`src/init.rs` Add OpenCode install/update/uninstall/status (+243/-26)
`src/main.rs` Add `--claude`/`--opencode` flags to Init command
`README.md` Add OpenCode setup section
`docs/TROUBLESHOOTING.md` Add OpenCode troubleshooting

Testing

cargo test --all                       # 476 tests pass
cargo run -- init -g --opencode        # installs plugin
cargo run -- init --show               # shows OpenCode status
cargo run -- init -g --uninstall       # removes all artifacts

Closes

@zeval zeval marked this pull request as ready for review March 2, 2026 13:06
@zeval zeval marked this pull request as draft March 2, 2026 14:52
@zeval zeval changed the title feat(init): add OpenCode plugin support + target flags feat(init): add OpenCode plugin support Mar 2, 2026
@zeval zeval marked this pull request as ready for review March 2, 2026 15:38
@zeval zeval changed the title feat(init): add OpenCode plugin support feat: add OpenCode plugin support Mar 2, 2026
zeval added 9 commits March 2, 2026 16:18
--claude-code was redundant (same as default behavior). Now only
--opencode exists as an opt-in; Claude Code is always the default.

Also fixes dead (false, false) branch with unreachable!(), removes
unused _global param from run_opencode_only_mode, and fixes plugin
directory priority to match OpenCode docs (plugin/ primary, plugins/
legacy).
Remove fragile test-opencode-rewrite.js (stripped TS with regex) and
the _rtkRewriteForTest export it consumed. Parity between bash hook
and TS plugin is now verified by a Rust #[ignore] test that shells
out to both hooks with identical inputs.
- Fix plugin directory to plugin/ (singular) per OpenCode docs
- Add note about tool.execute.before hook and subagent limitation
- Remove --claude-code references from README and troubleshooting
OpenCode uses ~/.config/ on all platforms (XDG convention), not the
macOS-native ~/Library/Application Support/. Also corrects directory
name to plugins/ (plural) per OpenCode docs.

Fixes tests to use temp dirs directly instead of env var overrides.
No legacy users exist — this is a new feature. Simplify to a single
path (~/.config/opencode/plugins/rtk.ts) with no fallback logic.

Replaces opencode_plugin_paths() tuple with opencode_plugin_path()
returning a single PathBuf.
Now that PR rtk-ai#241 centralizes rewrite logic in `rtk rewrite`, simplify
the OpenCode plugin from 214 lines of duplicated TS rewrite rules to a
38-line thin wrapper that shells out to `rtk rewrite`.

Also remove the bash/TS parity test from init.rs — no longer needed
since both hooks delegate to the same Rust function.

-355 lines removed, +18 added.
@zeval zeval changed the base branch from master to feat/rtk-rewrite March 2, 2026 16:25
@zeval zeval force-pushed the feature/opencode-support-11n branch from 7fc90d2 to c2d5478 Compare March 2, 2026 16:25
@zeval
Copy link
Author

zeval commented Mar 2, 2026

Rewrote this to respect the work done in #241 since we don't want to keep adding repeated re-write logic. When #241 is merged, this should be ready as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support/installation for OpenCode

1 participant