Skip to content

rtk init generates incompatible plugin format for OpenCode v2 #3898

Closed as duplicate

Description

@jchuder

Environment

  • RTK: v0.48.0
  • Platform: macOS 26.6 on Arm64
  • Tool: OpenCode CLI 2.0.0-beta.7 (and later)

Problem

OpenCode 2.0 changes its plugin interface and configuration layout.

The current command rtk init -g --opencode generates the legacy plugin format for OpenCode 1.0.

Because of this difference, OpenCode 2.0 fails to load the generated plugin.

Evidence

OpenCode 1.0 loads plugins from legacy plugin directories and scripts.

OpenCode 2.0 expects plugins in the root configuration or .opencode/plugins/.

When users run rtk init -g --opencode with OpenCode 2.0 installed:

  1. The generated plugin script uses the OpenCode 1.0 plugin hook signature.
  2. OpenCode 2.0 logs an initialization failure or ignores the plugin.

Expected behavior

  1. rtk init --opencode generates a plugin structure that is compatible with OpenCode 2.0.
  2. The generator detects the installed OpenCode version or provides a flag (for example: --opencode-v2).
  3. RTK keeps backward compatibility for OpenCode 1.0 users.

Checklist

  • I searched the existing issues.
  • I removed secrets and private data.

Activity

  1. Asura7170 commented on Sep 26, 2026

    @Asura7170

    Confirming still broken on rtk 0.48.0 + OpenCode v2.0.17 (stable, Windows).

    rtk init -g --opencode generates the V1 shape (export const RtkOpenCodePlugin, @opencode-ai/plugin, $ helper, "tool.execute.before" as an object key). The v2 loader rejects it: Plugin must export a default definition with an id and an effect or setup function.

    Locally verified fix — plain v2 module, loads cleanly and rewrites fire:

    export default {
      id: "rtk",
      async setup(ctx: any) {
        await ctx.tool.hook("execute.before", async (event: any) => {
          const command = event?.input?.command;
          if (typeof command !== "string" || !command) return;
          // read stdout even on non-zero exit (see below)
          event.input = { ...event.input, command: rewritten };
        });
      },
    };

    Two things worth knowing for the fix:

    • No $ in v2 — use node:child_process.execFile("rtk", ["rewrite", command]) (also avoids shell interpolation).
    • rtk rewrite exits 3 on success with valid stdout (rtk rewrite "git status" → rtk git status, exit 3), so the hook must read stdout from the error object too, and pass through silently on real failure.

    Suggest shipping one of the open PRs (#3899, #4187, #4197). Happy to test any of them against v2.0.17.

  2. jchuder commented on Sep 27, 2026

    @jchuder
    Author

    Update: #4187 now provides a more complete fix for this issue than my original PR #3899.

    I have closed #3899 in favor of #4187. Further work on this issue will be tracked there.

    #4187 also covers the additional cases reported here, including OpenCode 2.x, rtk rewrite exit code 3, Windows support, and runtime tests.

  3. Asura7170 commented on Sep 27, 2026

    @Asura7170

    Small follow-up: I can confirm the windowsHide: true in #4187 is necessary, not cosmetic. Without it, every rtk rewrite spawn pops a visible console window on Windows (OpenCode runs as a console-less background service, and Node defaults windowsHide to false). Verified the same flag in my local v2 port on 2.0.17 - flash gone, rewrites still fire. Thanks for consolidating on #4187.

  4. changed the title [-]rtk init generates incompatible plugin format for OpenCode 2.0[/-] [+]rtk init generates incompatible plugin format for OpenCode v2[/+] on Sep 30, 2026
  5. rtk-wshm-sync-bot commented on Sep 30, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    rtk init --opencode generates legacy OpenCode 1.0 plugin format that OpenCode 2.0 fails to load; fix already in progress via PR #4187.

    📁 Relevant files
    • src/init/opencode.rs

    Suggested Actions

    1. Review and merge PR feat(hook/opencode): support OpenCode V2, Desktop, and Windows (#3463, #3326) #4187 which claims to fix this (also refs feat: add opencode v2 plugin support (opencode2) #3463, rtk init --opencode plugin silently does nothing on Desktop ($ is not a function) and on Windows (which not found) #3326)
    2. Verify PR feat(hook/opencode): support OpenCode V2, Desktop, and Windows (#3463, #3326) #4187 preserves OpenCode 1.0 backward compatibility as requested
    3. Confirm version-detection or --opencode-v2 flag behavior matches issue's expected behavior section
    4. Ask reporter to test against PR feat(hook/opencode): support OpenCode V2, Desktop, and Windows (#3463, #3326) #4187 branch once available

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

  6. KuSh commented on Oct 3, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #3463, which tracks the same problem: rtk init --opencode writes the OpenCode 1.x plugin shape, which the OpenCode 2.x loader rejects. #3463 has the implementation sketch and the discussion, so please follow up there.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions