Skip to content

fix: remove harmful process.chdir() in OpenCodeService - #57

Open
ideabib wants to merge 1 commit into
cashew-labs:mainfrom
ideabib:fix/remove-process-chdir
Open

ideabib wants to merge 1 commit into
cashew-labs:mainfrom
ideabib:fix/remove-process-chdir

Conversation

@ideabib

@ideabib ideabib commented Aug 7, 2026

Copy link
Copy Markdown

Bug\n\nOpenCodeService.initialize() calls process.chdir(workspaceRoot) to make the spawned OpenCode server inherit the workspace as its working directory. This mutates the global process working directory of the entire VS Code extension host, which:\n\n- Affects every other loaded extension\n- Can break VS Code's own file-watching and path resolution\n- Requires fragile restoration in a inally block\n\n## Root cause\n\nThe OpenCode SDK's createOpencode() does not expose a cwd option, and the opencode serve CLI command has no --directory flag, so the only available workaround was process.chdir().\n\n## Fix\n\nRemove the global process.chdir() calls entirely. The server will start in VS Code's own working directory instead of the user's workspace.\n\n## Trade-off\n\nThe server will no longer automatically inherit the workspace as its cwd. This is a behavioral change, but it eliminates the harmful side-effects on the rest of the extension host.\n\n## Recommended follow-up\n\nA proper long-term fix is for the OpenCode SDK (sst/opencode) to accept a cwd option in ServerOptions so extensions can scope the server process without mutating global state.

…ir() mutates the global working directory of the VS Code\nextension host, which affects all other extensions and can cause\nunexpected behavior.\n\nThe OpenCode SDK's createOpencode() does not expose a cwd option,

and the opencode CLI serve command has no --directory flag, so the\nonly way to scope the server to the workspace was via process.chdir().\n\nThis fix removes the global mutation entirely. The server will start\nin VS Code's own working directory. While this means the server won't\nautomatically inherit the workspace as its cwd, it eliminates the\nside-effects on the rest of the extension host.\n\nA proper long-term fix would be for the OpenCode SDK to accept a\ncwd option in ServerOptions so extensions can scope the server without\nmutating global state.
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.

1 participant