Skip to content

OpenCode V2: plugin fails to load (V1 plugin API) and rtk hook opencode is unreleased #4470

Closed as duplicate

Description

@jacquagnui

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, and v0.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:

  1. A default export alone is not enough to import @opencode/plugin from the global plugin directory: it fails with Cannot find package '@opencode/plugin'. The V2 loader accepts a plain export default { id, setup } object, though.
  2. rtk hook opencode does not exist in v0.51.0 (rtk hook --help: claude, trae, codex, cursor, gemini, copilot, droid, antigravity, vibe, check). The develop plugin already delegates to it, so it cannot work with any released binary yet.
  3. rtk rewrite <cmd> prints the rewritten command on stdout but exits with status 3. Naive execFile handling 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.before is ctx.tool.hook("execute.before", …); for shell tools, ctx.shell.hook("create.before") exposes a mutable event.command, which is the cleaner extension point.
  • Since rtk hook opencode is not released yet, the V2 path can keep the rtk rewrite fallback (with the permission caveat documented in hooks/opencode/README.md).

References

Happy to open a PR with a V2-compatible plugin if that helps.

Activity

  1. rtk-wshm-sync-bot commented on Oct 6, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 90%

    Summary

    OpenCode's V2 plugin API rejects the V1-style rtk.ts plugin at load time, so no rewriting occurs; also rtk hook opencode is referenced on develop but not shipped in any release.

    📁 Relevant files
    • hooks/opencode/rtk.ts
    • hooks/opencode/README.md

    Suggested Actions

    1. Update hooks/opencode/rtk.ts to support V2 export default { id, setup } with V1 fallback as proposed
    2. Release rtk hook opencode (referenced on develop but absent from v0.51.0) or keep the rtk rewrite fallback document…
    3. Cross-check with rtk init -g --opencode installs 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)
    4. Accept the offered PR from the reporter; confirm exit code 3 from rtk rewrite is intentional and document it

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. KuSh commented on Oct 10, 2026

    @KuSh
    Collaborator

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugopencodepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions