Skip to content

Custom tools via symlinks fail to resolve @opencode-ai/plugin module #11001

Closed

Description

@wagnert

Description

When a custom tool in .opencode/tools/ is a symlink pointing to another location, Bun resolves the symlink and tries to import @opencode-ai/plugin relative to the symlink target path instead of the .opencode/ directory where node_modules actually lives.

Steps to Reproduce

  1. Create a tool file at /some/path/my-tool.ts:
import { tool } from "@opencode-ai/plugin"

export default tool({
  description: "Test tool",
  args: {},
  async execute(args, context) {
    return "Hello"
  },
})
  1. Create a symlink in .opencode/tools/:
ln -s /some/path/my-tool.ts .opencode/tools/my-tool.ts
  1. Ensure @opencode-ai/plugin is installed in .opencode/node_modules/

  2. Start OpenCode

Expected Behavior

The tool loads successfully, resolving @opencode-ai/plugin from .opencode/node_modules/.

Actual Behavior

Error: Cannot find module '@opencode-ai/plugin' from '/some/path/my-tool.ts'

Bun follows the symlink and tries to resolve the module relative to the symlink target (/some/path/), where no node_modules exists.

Root Cause

In packages/opencode/src/tool/registry.ts, line 44:

const mod = await import(match)

When match is a symlink, Bun resolves it to the real path before importing, causing module resolution to fail.

Possible Solutions

  1. Read the file content and use a data URL import instead of importing the path directly
  2. Copy the file to a temp location before importing
  3. Use fs.realpathSync() to detect symlinks and handle them differently
  4. Document that symlinks are not supported for custom tools

Workaround

Copy tool files directly into .opencode/tools/ instead of using symlinks.

Environment

  • OpenCode version: 1.1.39
  • OS: macOS
  • Bun version: (current)

Activity

  1. github-actions commented on Jan 28, 2026

    @github-actions
    Contributor

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

    These issues relate to module resolution problems with @opencode-ai/plugin, though they may involve different root causes (symlinks, ESM imports, NixOS packaging, etc.). Feel free to ignore if your specific symlink case doesn't match.

  2. koichiio commented on Apr 15, 2026

    @koichiio
    Contributor

    @wagnert
    Was this fixed or did you find any other solutions?

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions