Conversation
…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.
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.
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.