Skip to content

fix(cli): Run bun install after writing npm dependencies in ocx add#132

Open
beppe2880 wants to merge 1 commit intokdcokenny:mainfrom
beppe2880:fix/worktree-missing-deps
Open

fix(cli): Run bun install after writing npm dependencies in ocx add#132
beppe2880 wants to merge 1 commit intokdcokenny:mainfrom
beppe2880:fix/worktree-missing-deps

Conversation

@beppe2880
Copy link
Contributor

@beppe2880 beppe2880 commented Feb 11, 2026

Problem

ocx add writes npmDependencies / npmDevDependencies to package.json but never
runs bun install. Plugins that import external packages (e.g. jsonc-parser, zod)
fail at runtime because the modules are not on disk.

This causes OpenCode to hang on startup with:
Cannot find package 'jsonc-parser' from '~/.opencode/plugin/worktree.ts'

Fixes #131

Fix

Run bun install in the package directory immediately after writing package.json,
so dependencies are available before OpenCode tries to load the plugin.

A warning is logged if the install fails (e.g. no network), allowing the user to
install manually.


Summary by cubic

Automatically run bun install after ocx add writes package.json so plugin npm dependencies are installed. Prevents startup hangs and “Cannot find package …” errors.

  • Bug Fixes
    • Run bun install in the package directory (.opencode or cwd) right after writing npmDependencies/npmDevDependencies.
    • Show a spinner and log a warning if installation fails, allowing manual install.
    • Add runBunInstall helper using Bun.spawn with exit code checks.
    • Add tests to verify node_modules is created and dependencies (e.g., lodash) are installed.

Written for commit 6800faa. Summary will update on new commits.

@beppe2880 beppe2880 changed the title fix(cli): run bun install after writing npm dependencies in ocx add fix(cli): Run bun install after writing npm dependencies in ocx add Feb 11, 2026
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.06%. Comparing base (ed74da6) to head (6800faa).

Files with missing lines Patch % Lines
packages/cli/src/commands/add.ts 0.00% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
- Coverage   48.34%   48.06%   -0.28%     
==========================================
  Files          47       47              
  Lines        4944     4972      +28     
==========================================
  Hits         2390     2390              
- Misses       2554     2582      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@kdcokenny
Copy link
Owner

OpenCode (at least used to) install all of these automatically using their built-in bun bundle. Please verify that this behaviour has changed.

@beppe2880
Copy link
Contributor Author

Hey @kdcokenny, verified — the behaviour hasn't changed, but it only installs under specific conditions.

OpenCode's needsInstall() only checks if @opencode-ai/plugin is present at the correct version. If it is → false, no bun install, regardless of other missing deps.

Reproduction steps

# 1. Get OpenCode v1.1.52
mkdir -p /tmp/oc-bin && cd /tmp/oc-bin
gh release download v1.1.52 --repo sst/opencode --pattern "opencode-linux-x64.tar.gz" --clobber
tar xzf opencode-linux-x64.tar.gz

# 2. Fresh project with .opencode config
mkdir -p /tmp/oc-repro && cd /tmp/oc-repro && git init
mkdir -p .opencode && echo '{}' > .opencode/opencode.jsonc

# 3. Open OpenCode, send any message, close it
# This creates .opencode/node_modules with @opencode-ai/plugin
/tmp/oc-bin/opencode

# 4. Install worktree
ocx init && ocx registry add https://registry.kdco.dev --name kdco
ocx add kdco/worktree -f

# 5. State: package.json has jsonc-parser, node_modules doesn't

# 6. Restart OpenCode → hangs on blank screen
# Logs show: Cannot find package 'jsonc-parser' from '.opencode/plugin/worktree.ts'
/tmp/oc-bin/opencode

needsInstall() logic:

  1. node_modules/ doesn't exist? → install
  2. package.json doesn't exist? → install
  3. @opencode-ai/plugin missing from dependencies? → install
  4. @opencode-ai/plugin version matches OpenCode version? → skip (return false)

It never checks any other dependency. So when ocx add writes jsonc-parser to package.json after the first run, OpenCode sees @opencode-ai/[email protected] is already there and says "we're good" — jsonc-parser is a ghost in package.json with no matching files in node_modules.

This one drove me nuts — I hit the bug on my desktop, then switched to my laptop (for unrelated reasons) to write a clean repro and it just worked. Couldn't reproduce a reproducibility bug (on NixOS of all things). Turns out on the laptop node_modules didn't exist yet so needsInstall() returned true and installed everything. Only hits if you've opened OpenCode before running ocx add.

I'm also going to open a PR on OpenCode to make needsInstall() check all declared dependencies, not just @opencode-ai/plugin.

@kdcokenny
Copy link
Owner

Hey @kdcokenny, verified — the behaviour hasn't changed, but it only installs under specific conditions.

OpenCode's needsInstall() only checks if @opencode-ai/plugin is present at the correct version. If it is → false, no bun install, regardless of other missing deps.

Reproduction steps

# 1. Get OpenCode v1.1.52
mkdir -p /tmp/oc-bin && cd /tmp/oc-bin
gh release download v1.1.52 --repo sst/opencode --pattern "opencode-linux-x64.tar.gz" --clobber
tar xzf opencode-linux-x64.tar.gz

# 2. Fresh project with .opencode config
mkdir -p /tmp/oc-repro && cd /tmp/oc-repro && git init
mkdir -p .opencode && echo '{}' > .opencode/opencode.jsonc

# 3. Open OpenCode, send any message, close it
# This creates .opencode/node_modules with @opencode-ai/plugin
/tmp/oc-bin/opencode

# 4. Install worktree
ocx init && ocx registry add https://registry.kdco.dev --name kdco
ocx add kdco/worktree -f

# 5. State: package.json has jsonc-parser, node_modules doesn't

# 6. Restart OpenCode → hangs on blank screen
# Logs show: Cannot find package 'jsonc-parser' from '.opencode/plugin/worktree.ts'
/tmp/oc-bin/opencode

needsInstall() logic:

  1. node_modules/ doesn't exist? → install
  2. package.json doesn't exist? → install
  3. @opencode-ai/plugin missing from dependencies? → install
  4. @opencode-ai/plugin version matches OpenCode version? → skip (return false)

It never checks any other dependency. So when ocx add writes jsonc-parser to package.json after the first run, OpenCode sees @opencode-ai/[email protected] is already there and says "we're good" — jsonc-parser is a ghost in package.json with no matching files in node_modules.

This one drove me nuts — I hit the bug on my desktop, then switched to my laptop (for unrelated reasons) to write a clean repro and it just worked. Couldn't reproduce a reproducibility bug (on NixOS of all things). Turns out on the laptop node_modules didn't exist yet so needsInstall() returned true and installed everything. Only hits if you've opened OpenCode before running ocx add.

I'm also going to open a PR on OpenCode to make needsInstall() check all declared dependencies, not just @opencode-ai/plugin.

This is super interesting! Thanks for the research!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] worktree plugin installed without dependencies, OpenCode hangs on startup

2 participants