opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: await dependency installation before loading custom tools

Open elithrar opened this issue 1 week ago • 3 comments

Fixes an issue where custom tools fail to load with "Cannot find module '@opencode-ai/plugin'" errors due to a tool loading vs. dependency installation "race".

This builds on #6302 by ensuring dependency installation completes before attempting to load custom tools that depend on those packages without impacting OpenCode startup time - e.g. we don't block app startup, just tool loading (which is already on-demand).

notably, this implementation ensures that tools wait only for their own directory's dependencies (minimal blocking).

problem: After #6302, OpenCode runs bun install for each config directory to install dependencies. However, if node_modules already exists, the installation runs asynchronously in the background without waiting. When custom tools are loaded immediately after, they fail to import @opencode-ai/plugin or other dependencies because the install hasn't finished yet.

fix: Track the install promise for each config directory and await it before loading tools from that directory:

  • Config directories start installing dependencies in parallel (non-blocking)
  • When the tool registry loads tools from a directory, it awaits that directory's install promise
  • This ensures tools only import after their dependencies are ready

elithrar avatar Jan 04 '26 18:01 elithrar