fix: wait for dependencies before loading custom tools and plugins#12227
Merged
fix: wait for dependencies before loading custom tools and plugins#12227
Conversation
Fixes a race condition where custom tools with external dependencies in their package.json would crash on import because dependencies weren't installed yet. Changes: - Config.state() now collects dependency installation promises in a deps array - Added Config.waitForDependencies() to await all installations - ToolRegistry calls waitForDependencies() before loading custom tools - Plugin.list() calls waitForDependencies() before loading plugins - Added test to verify tools with external deps (cowsay) load successfully
dmae97
pushed a commit
to dmae97/opencode
that referenced
this pull request
Feb 5, 2026
01luyicheng
pushed a commit
to 01luyicheng/opencode
that referenced
this pull request
Feb 5, 2026
This was referenced Feb 5, 2026
fanjia1024
pushed a commit
to fanjia1024/opencode
that referenced
this pull request
Feb 10, 2026
avion23
pushed a commit
to avion23/opencode
that referenced
this pull request
Feb 13, 2026
3 tasks
schneiderlo
pushed a commit
to schneiderlo/opencode
that referenced
this pull request
Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a race condition where custom tools with external dependencies in their package.json would crash on import because dependencies weren't installed yet.
Problem
When a custom tool file had an import like:
at the top level, and the tool directory had a package.json with cowsay as a dependency, the tool would crash with "Cannot find package 'cowsay'" because dependencies weren't installed before the module was imported.
Solution
depsarray usingiife()waitForDependencies()before loading custom tools (if tools exist)waitForDependencies()before loading plugins (if plugins exist)Changes
packages/opencode/src/config/config.ts: Track deps array and add wait functionpackages/opencode/src/tool/registry.ts: Wait for deps before loading toolspackages/opencode/src/plugin/index.ts: Wait for deps before loading pluginspackages/opencode/test/tool/registry.test.ts: Added test verifying tools with external deps (cowsay) load successfullyTesting
Added a test that creates a tool with cowsay as a dependency and imports it at the top level. The test verifies the tool loads without crashing.