Repository navigation
Closed as duplicate
Closed as duplicate
Copy link
Labels
Description
Summary
The OpenCode integration installed by rtk init -g --opencode — and the current hooks/opencode/rtk.ts on develop — targets the V1 plugin API. OpenCode 2.x rejects it at load time, so no command gets rewritten.
Environment
- OpenCode
v2.0.22(Linux x64) - RTK
0.47.0, andv0.51.0(latest release) checked
Problem
At startup OpenCode logs:
WARN failed to load plugin target=~/.config/opencode/plugins/rtk.ts
cause="Cause([Fail(PluginModule.LoadError: Plugin must export a default definition
with an id and an effect or setup function. (cause: SchemaError(Missing key at ["default"])))])"
The plugin is a V1 module: named export + "tool.execute.before" hook returned by the plugin function. Per the OpenCode V2 migration guide, "V1 plugin implementations do not run in V2" — V2 expects export default Plugin.define({ id, async setup(ctx) { … } }).
Additional findings:
- A default export alone is not enough to import
@opencode/pluginfrom the global plugin directory: it fails withCannot find package '@opencode/plugin'. The V2 loader accepts a plainexport default { id, setup }object, though. rtk hook opencodedoes not exist in v0.51.0 (rtk hook --help: claude, trae, codex, cursor, gemini, copilot, droid, antigravity, vibe, check). Thedevelopplugin already delegates to it, so it cannot work with any released binary yet.rtk rewrite <cmd>prints the rewritten command on stdout but exits with status 3. NaiveexecFilehandling treats it as an error and drops the rewrite — if that exit code is intentional, it may deserve a note in the docs.
Suggested fix
Ship a plugin that supports both APIs (V1 entrypoints >= 1.18.29 and V2 setup()):
import { execFile } from "node:child_process"
export default {
id: "rtk",
async setup(ctx: any) {
await ctx.shell.hook("create.before", async (event: { command?: string }) => {
const command = event.command
if (!command || command === "rtk" || command.startsWith("rtk ")) return
event.command = await rewriteCommand(command) // rtk hook opencode, fallback rtk rewrite
})
},
// V1 compatibility
async server() {
return { "tool.execute.before": /* … V1 implementation … */ }
},
}Notes:
- The V2 equivalent of
tool.execute.beforeisctx.tool.hook("execute.before", …); for shell tools,ctx.shell.hook("create.before")exposes a mutableevent.command, which is the cleaner extension point. - Since
rtk hook opencodeis not released yet, the V2 path can keep thertk rewritefallback (with the permission caveat documented inhooks/opencode/README.md).
References
- Plugins guide (V2): https://opencode.ai/v2/docs/build/plugins
- V1 → V2 plugin migration: https://opencode.ai/v2/docs/build/plugins/migrate-v1
Happy to open a PR with a V2-compatible plugin if that helps.
Reacted by Vladislav Liboras, Isaias Piña and InKernel
Reacted by Cezar Sampaio, -_-, René and InKernel
Activity
rtk-wshm-sync-bot commentedon Oct 6, 2026
🔍 Automated Triage
bughighSummary
OpenCode's V2 plugin API rejects the V1-style rtk.ts plugin at load time, so no rewriting occurs; also
rtk hook opencodeis referenced on develop but not shipped in any release.📁 Relevant files
hooks/opencode/rtk.tshooks/opencode/README.mdSuggested Actions
export default { id, setup }with V1 fallback as proposedrtk hook opencode(referenced on develop but absent from v0.51.0) or keep thertk rewritefallback document…rtk init -g --opencodeinstalls no plugin when the Claude side fails first #4413 (plugin install skipped when Claude side fails) and OpenCode permission rules: rtk's config loader diverges from OpenCode's config resolution #4422 (OpenCode config resolution divergence)rtk rewriteis intentional and document itTriaged automatically by wshm · This is an automated analysis, not a human review.
KuSh commentedon Oct 10, 2026
Thanks for the detailed report. This is the same OpenCode V2 plugin-loading failure tracked in #3463, which has the longer discussion, a dual V1/V2 patch posted in its comments, and the open PR #4187 that references it, so I am closing this one in favour of #3463. Please add anything that is not covered there, such as the
ctx.shell.hook("create.before")approach, on #3463.