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

Closed
opened 2026-02-16 18:08:27 -05:00 by yindo · 1 comment
Owner

Originally created by @wagnert on GitHub (Jan 28, 2026).

Originally assigned to: @thdxr on GitHub.

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)
Originally created by @wagnert on GitHub (Jan 28, 2026). Originally assigned to: @thdxr on GitHub. ## 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`: ```typescript import { tool } from "@opencode-ai/plugin" export default tool({ description: "Test tool", args: {}, async execute(args, context) { return "Hello" }, }) ``` 2. Create a symlink in `.opencode/tools/`: ```bash ln -s /some/path/my-tool.ts .opencode/tools/my-tool.ts ``` 3. Ensure `@opencode-ai/plugin` is installed in `.opencode/node_modules/` 4. 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: ```javascript 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)
yindo closed this issue 2026-02-16 18:08:27 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 28, 2026):

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

  • #5914: NixOS: custom tools fail because they cannot find imported modules
  • #8006: @opencode-ai/plugin: ESM imports missing .js extension breaks plugin loading
  • #5860: error: Cannot find module '@opencode-ai/plugin' from

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.

@github-actions[bot] commented on GitHub (Jan 28, 2026): This issue might be a duplicate of existing issues. Please check: - #5914: NixOS: custom tools fail because they cannot find imported modules - #8006: @opencode-ai/plugin: ESM imports missing .js extension breaks plugin loading - #5860: error: Cannot find module '@opencode-ai/plugin' from 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7846