Skip to content

OpenCode plugin missing default export — plugin never loaded by plugin loader #2516

Closed

Description

@sacrtap

Summary

The OpenCode plugin generated by rtk init -g --opencode exports only a named export (RtkOpenCodePlugin) but lacks a default export. OpenCode's plugin loader requires a default export to load the plugin module, so the RTK plugin is silently never loaded — the tool.execute.before hook never fires, and all bash commands execute without RTK rewriting.

Environment

  • rtk version: 0.42.4
  • opencode version: 1.17.8
  • OS: macOS (darwin)
  • Install method: Homebrew

Steps to Reproduce

  1. Run rtk init -g --opencode
  2. Check the generated plugin file: ~/.config/opencode/plugins/rtk.ts
  3. Start OpenCode and run git status via the bash tool
  4. Observe: command executes as raw git status, not rtk git status

Root Cause

OpenCode's plugin type definition (@opencode-ai/plugin) specifies:

export type PluginModule = {
    id?: string;
    server: Plugin;
    tui?: never;
};

The plugin loader expects a default export matching the Plugin type. The generated rtk.ts only has:

export const RtkOpenCodePlugin: Plugin = async ({ $ }) => { ... }
// ← missing: export default RtkOpenCodePlugin

Compare with a working plugin in the same directory (openviking-memory.ts), which has both:

export const OpenVikingMemoryPlugin = async (input: PluginInput): Promise<Hooks> => { ... }
export default OpenVikingMemoryPlugin  // ← this makes it load

Impact

  • 100% of OpenCode users who install via rtk init -g --opencode have RTK silently disabled
  • rtk init --show reports [ok] OpenCode: plugin installed — no warning that the plugin won't load
  • Users see no errors; commands just pass through unfiltered

Fix

Add export default RtkOpenCodePlugin to the end of the generated plugin template.

The source template is likely in src/ or hooks/ — wherever rtk init --opencode generates the rtk.ts content.

Verification

After manually adding export default RtkOpenCodePlugin to ~/.config/opencode/plugins/rtk.ts and restarting OpenCode:

  • git status → rewritten to rtk git status ✅
  • git diff → rewritten to rtk git diff ✅
  • docker ps → rewritten to rtk docker ps ✅
  • make test-parallel → rewritten to rtk make test-parallel ✅
  • playwright test → rewritten to rtk playwright test ✅
  • sudo npm run build → rewritten to sudo rtk npm run build ✅ (transparent prefix)

Suggested Improvement

Add a runtime check in rtk init --show that verifies the plugin file contains export default. If missing, warn the user.

Activity

  1. molloyzak13 commented on Jun 19, 2026

    @molloyzak13

    Adding export default RtkOpenCodePlugin to hooks/opencode/rtk.ts should fix this. The file gets embedded at build time and re-written on each rtk init -g --opencode, so it covers both fresh installs and existing setups.

  2. molloyzak13 commented on Jun 19, 2026

    @molloyzak13

    Adding export default RtkOpenCodePlugin to hooks/opencode/rtk.ts should fix this. The file gets embedded at build time and re-written on each rtk init -g --opencode, so it covers both fresh installs and existing setups.

  3. pszymkowiak commented on Jun 25, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    Generated OpenCode plugin template missing export default — RTK is silently disabled for 100% of OpenCode users; PR #2566 already open with a fix.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/init/opencode_plugin_template.ts

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

  4. santiago1393 commented on Jul 19, 2026

    @santiago1393

    Hey team, just tried this in my local and it does not seem to be working as expected. Is there another solution to this problem? thks.

  5. dylldev commented on Oct 4, 2026

    @dylldev

    Heads up on the suggested fix in this thread: adding a bare export default RtkOpenCodePlugin resolves this on OpenCode 1.17.x (V1 loader), but it is no longer sufficient on current OpenCode, and it now fails differently.

    On OpenCode 1.18.34 the TUI/desktop/shared server uses the V2 loader. With a bare default export you get past the first schema check and straight into the next one:

    PluginModule.LoadError: Plugin must export a default definition with an id and an effect or setup function.
      (cause: SchemaError(Missing key at ["default"]["effect"] / ["default"]["setup"]))
    

    The V2 loader requires the default export to carry an id plus setup() (or effect()), and it ignores server() entirely — so a V1 plugin exported as the default loads without error and then silently does nothing. That silent case is what #4311 and the discussion in #3463 cover.

    Verified working shape on 1.18.34 + rtk 0.51.0 (both halves kept, so the V1 opencode run CLI keeps working too):

    import { spawnSync } from "node:child_process"
    import type { Plugin } from "@opencode-ai/plugin"
    
    function rewriteCommand(command: string): string | undefined {
      try {
        const result = spawnSync("rtk", ["rewrite", command], {
          encoding: "utf8", timeout: 2000, maxBuffer: 1024 * 1024,
        })
        const rewritten = (result.stdout ?? "").trim()
        return rewritten && rewritten !== command ? rewritten : undefined
      } catch { return undefined }
    }
    
    async function setup(ctx) {
      await ctx.tool.hook("execute.before", async (event) => {
        const tool = String(event?.tool ?? "").toLowerCase()
        if (tool !== "bash" && tool !== "shell") return
        const input = event?.input
        if (!input || typeof input !== "object") return
        const command = input.command
        if (typeof command !== "string" || !command) return
        const rewritten = rewriteCommand(command)
        if (rewritten) event.input = { ...input, command: rewritten }
      })
    }
    
    export const RtkOpenCodePlugin: Plugin = async ({ $ }) => { /* unchanged V1 path */ }
    
    export default { id: "rtk", setup, server: RtkOpenCodePlugin }

    A plain object works in place of Plugin.define(...) — ~/.config/opencode/plugins/ has no node_modules, and the generated file's only import is type-only, so there is no runtime @opencode/plugin to resolve.

    Full working notes and the three porting gotchas are in #3463. Suggest closing this in favour of that one.

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:clibugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions