Bug: getPluginName incorrectly deduplicates plugins with same entry filename (index.js) #8602

Open
opened 2026-02-16 18:10:22 -05:00 by yindo · 1 comment
Owner

Originally created by @cpkt9762 on GitHub (Feb 5, 2026).

Originally assigned to: @rekram1-node on GitHub.

多个插件的入口文件都是 index.js 时,getPluginName 函数只提取文件名,导致它们被错误地视为重复插件而被去重

Bug Description

When multiple plugins are resolved to file:// URLs with the same entry filename (e.g., index.js), the getPluginName function incorrectly identifies them as duplicates, causing some plugins to be silently dropped.

Steps to Reproduce

  1. Configure multiple plugins in ~/.config/opencode/opencode.json:
"plugin": [
  "oh-my-opencode@latest",
  "opencode-anthropic-auth@0.0.13",
  "opencode-antigravity-auth@1.4.3",
  "opencode-openai-codex-auth"
]
  1. Both oh-my-opencode and opencode-openai-codex-auth are installed in ~/.config/opencode/node_modules/

  2. Run opencode debug config

  3. Observe that oh-my-opencode is missing from the plugin list

Root Cause

In packages/opencode/src/config/config.ts, the getPluginName function extracts only the filename for file:// URLs:

export function getPluginName(plugin: string): string {
  if (plugin.startsWith("file://")) {
    return path.parse(new URL(plugin).pathname).name  // Returns "index" for both plugins!
  }
  // ...
}

When plugins are resolved via import.meta.resolve, they become:

  • file:///...node_modules/oh-my-opencode/dist/index.js → name: index
  • file:///...node_modules/opencode-openai-codex-auth/dist/index.js → name: index

Since both have the same name index, deduplicatePlugins treats them as duplicates and keeps only one.

Suggested Fix

Extract the package name from the node_modules path:

export function getPluginName(plugin: string): string {
  if (plugin.startsWith("file://")) {
    const pathname = new URL(plugin).pathname
    // Extract package name from node_modules path
    const nodeModulesMatch = pathname.match(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/)
    if (nodeModulesMatch) {
      return nodeModulesMatch[1]
    }
    return path.parse(pathname).name
  }
  // ...
}

This correctly extracts:

  • file:///...node_modules/oh-my-opencode/dist/index.jsoh-my-opencode
  • file:///...node_modules/@scope/pkg/dist/index.js@scope/pkg

Workaround

Reorder plugins so the one you want to keep is listed last:

"plugin": [
  "opencode-anthropic-auth@0.0.13",
  "opencode-antigravity-auth@1.4.3",
  "opencode-openai-codex-auth",
  "oh-my-opencode@latest"
]

Environment

  • OpenCode version: 1.1.49
  • OS: macOS (Apple Silicon)
Originally created by @cpkt9762 on GitHub (Feb 5, 2026). Originally assigned to: @rekram1-node on GitHub. 多个插件的入口文件都是 index.js 时,getPluginName 函数只提取文件名,导致它们被错误地视为重复插件而被去重 ## Bug Description When multiple plugins are resolved to `file://` URLs with the same entry filename (e.g., `index.js`), the `getPluginName` function incorrectly identifies them as duplicates, causing some plugins to be silently dropped. ## Steps to Reproduce 1. Configure multiple plugins in `~/.config/opencode/opencode.json`: ```json "plugin": [ "oh-my-opencode@latest", "opencode-anthropic-auth@0.0.13", "opencode-antigravity-auth@1.4.3", "opencode-openai-codex-auth" ] ``` 2. Both `oh-my-opencode` and `opencode-openai-codex-auth` are installed in `~/.config/opencode/node_modules/` 3. Run `opencode debug config` 4. Observe that `oh-my-opencode` is missing from the plugin list ## Root Cause In `packages/opencode/src/config/config.ts`, the `getPluginName` function extracts only the filename for `file://` URLs: ```typescript export function getPluginName(plugin: string): string { if (plugin.startsWith("file://")) { return path.parse(new URL(plugin).pathname).name // Returns "index" for both plugins! } // ... } ``` When plugins are resolved via `import.meta.resolve`, they become: - `file:///...node_modules/oh-my-opencode/dist/index.js` → name: `index` - `file:///...node_modules/opencode-openai-codex-auth/dist/index.js` → name: `index` Since both have the same name `index`, `deduplicatePlugins` treats them as duplicates and keeps only one. ## Suggested Fix Extract the package name from the `node_modules` path: ```typescript export function getPluginName(plugin: string): string { if (plugin.startsWith("file://")) { const pathname = new URL(plugin).pathname // Extract package name from node_modules path const nodeModulesMatch = pathname.match(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/) if (nodeModulesMatch) { return nodeModulesMatch[1] } return path.parse(pathname).name } // ... } ``` This correctly extracts: - `file:///...node_modules/oh-my-opencode/dist/index.js` → `oh-my-opencode` - `file:///...node_modules/@scope/pkg/dist/index.js` → `@scope/pkg` ## Workaround Reorder plugins so the one you want to keep is listed **last**: ```json "plugin": [ "opencode-anthropic-auth@0.0.13", "opencode-antigravity-auth@1.4.3", "opencode-openai-codex-auth", "oh-my-opencode@latest" ] ``` ## Environment - OpenCode version: 1.1.49 - OS: macOS (Apple Silicon)
Author
Owner

@github-actions[bot] commented on GitHub (Feb 5, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #11159: Plugin deduplication incorrectly removes plugins with index.js entry points
  • #8759: Bug: file:// plugins with same filename incorrectly deduplicated
  • #10115: Only the last plugin loads in OpenCode 1.1.32 - Multiple plugins not supported

All of these issues describe the same root cause: the getPluginName() function in packages/opencode/src/config/config.ts extracts only the filename for file:// URLs instead of the full package name from the node_modules path. Feel free to ignore if your specific case differs from these.

@github-actions[bot] commented on GitHub (Feb 5, 2026): This issue might be a duplicate of existing issues. Please check: - #11159: Plugin deduplication incorrectly removes plugins with index.js entry points - #8759: Bug: file:// plugins with same filename incorrectly deduplicated - #10115: Only the last plugin loads in OpenCode 1.1.32 - Multiple plugins not supported All of these issues describe the same root cause: the `getPluginName()` function in `packages/opencode/src/config/config.ts` extracts only the filename for file:// URLs instead of the full package name from the node_modules path. Feel free to ignore if your specific case differs from these.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8602