[PR #6787] fix(plugin): prevent duplicate plugin function initialization #12108

Closed
opened 2026-02-16 18:17:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6787

State: closed
Merged: Yes


Fixes #6596 If in plugin file you have two exports:
export const YourPlugin: Plugin = async () => { ... }
export default YourPlugin

// When imported:
const mod = await import(plugin)
Object.entries(mod)
// Returns: "YourPlugin", fn], ["default", fn
// Both point to the SAME function reference

So the plugin function fn gets called twice in the loop, creating two separate hook instances. The seen Set now catches this by checking if we've already processed that exact function reference.

Im building an opencode plugin and noticed the issue, in the video you can see i run bun run dev with the fix and when running oc alias for opencode it calls plugin twice.

https://github.com/user-attachments/assets/d25e123a-dfc4-4b6b-9681-352bbba2bf09

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6787 **State:** closed **Merged:** Yes --- Fixes #6596 If in plugin file you have two exports: export const YourPlugin: Plugin = async () => { ... } export default YourPlugin // When imported: const mod = await import(plugin) Object.entries(mod) // Returns: [["YourPlugin", fn], ["default", fn]] // Both point to the SAME function reference So the plugin function fn gets called twice in the loop, creating two separate hook instances. The seen Set now catches this by checking if we've already processed that exact function reference. Im building an opencode plugin and noticed the issue, in the video you can see i run bun run dev with the fix and when running oc alias for opencode it calls plugin twice. https://github.com/user-attachments/assets/d25e123a-dfc4-4b6b-9681-352bbba2bf09
yindo added the pull-request label 2026-02-16 18:17:02 -05:00
yindo closed this issue 2026-02-16 18:17:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12108