[PR #11177] fix(config): only install dependencies in project worktree #13677

Closed
opened 2026-02-16 18:18:30 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11177

State: closed
Merged: No


Summary

Prevents creating unwanted .opencode/node_modules directories in arbitrary directories that happen to contain a .opencode folder.

Problem

Previously, when scanning for .opencode directories, OpenCode would install dependencies (package.json, node_modules, bun.lock) in ANY directory that had a .opencode folder, including directories outside the project worktree (e.g., parent directories or unrelated projects).

Solution

Now, dependencies are only installed for .opencode directories that are within the project's worktree boundary. This is done by checking if the directory is within Instance.worktree before calling installDependencies().

Changes

  • Added a check using Filesystem.contains(Instance.worktree, dir) before installing dependencies
  • The check also handles the case where Instance.worktree === "/" (non-git projects)

Testing

The fix ensures that:

  1. Dependencies are still installed for project .opencode directories
  2. Dependencies are NOT installed for arbitrary .opencode directories found in parent paths
  3. Global ~/.opencode directory behavior is preserved (when worktree is /)

Fixes #11147

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11177 **State:** closed **Merged:** No --- ## Summary Prevents creating unwanted `.opencode/node_modules` directories in arbitrary directories that happen to contain a `.opencode` folder. ## Problem Previously, when scanning for `.opencode` directories, OpenCode would install dependencies (`package.json`, `node_modules`, `bun.lock`) in ANY directory that had a `.opencode` folder, including directories outside the project worktree (e.g., parent directories or unrelated projects). ## Solution Now, dependencies are only installed for `.opencode` directories that are within the project's worktree boundary. This is done by checking if the directory is within `Instance.worktree` before calling `installDependencies()`. ## Changes - Added a check using `Filesystem.contains(Instance.worktree, dir)` before installing dependencies - The check also handles the case where `Instance.worktree === "/"` (non-git projects) ## Testing The fix ensures that: 1. Dependencies are still installed for project `.opencode` directories 2. Dependencies are NOT installed for arbitrary `.opencode` directories found in parent paths 3. Global `~/.opencode` directory behavior is preserved (when worktree is `/`) Fixes #11147
yindo added the pull-request label 2026-02-16 18:18:30 -05:00
yindo closed this issue 2026-02-16 18:18:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13677