feat: add OpenCode plugin support#300
Open
zeval wants to merge 12 commits intortk-ai:feat/rtk-rewritefrom
Open
feat: add OpenCode plugin support#300zeval wants to merge 12 commits intortk-ai:feat/rtk-rewritefrom
zeval wants to merge 12 commits intortk-ai:feat/rtk-rewritefrom
Conversation
--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.
7fc90d2 to
c2d5478
Compare
Author
Logs to /tmp/rtk-opencode.log for debugging hook behavior. Remove before merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.beforehook to rewrite Bash/Shell tool commands tortk ...before execution.Built on top of PR #241 (
rtk rewrite): the OpenCode plugin is a thin 38-line wrapper that delegates all rewrite logic tortk rewrite.What's added
hooks/opencode-rtk.ts(38 lines) — OpenCode plugin that callsrtk rewritevia shellrtk init -g --opencode— install the plugin to~/.config/opencode/plugins/rtk.tsrtk init -g— now installs both Claude Code hook AND OpenCode plugin by defaultrtk init -g --claude/--opencode— install only one integrationrtk init --show— reports OpenCode plugin statusrtk init -g --uninstall— removes OpenCode plugin alongside Claude Code artifactsArchitecture
Both hooks are thin protocol adapters. All rewrite logic lives in Rust.
Design decisions
--opencodeas opt-in flag: `rtk init -g` installs both by default; `--claude` or `--opencode` installs only oneFiles changed
Testing
Closes