opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(vscode): add attach mode for connecting to existing server

Open Destreyf opened this issue 4 months ago • 11 comments

Summary

  • Add configuration settings for attach mode (opencode.attach.enabled, .host, .port)
  • When enabled, run opencode attach instead of spawning a new instance
  • Support both http:// and https:// protocols in host configuration
  • Enables session sharing between terminal/web and VSCode in cloud workspaces (e.g., Coder)

Changes

  • sdks/vscode/package.json: Add contributes.configuration section
  • sdks/vscode/src/extension.ts: Read config, conditional attach command, protocol-aware URL building
  • sdks/vscode/README.md: Document new settings including HTTPS support

Usage

Enable attach mode in VS Code settings:

{
  "opencode.attach.enabled": true,
  "opencode.attach.host": "localhost",
  "opencode.attach.port": 4096
}

For HTTPS connections:

{
  "opencode.attach.host": "https://myserver.com",
  "opencode.attach.port": 443
}

Destreyf avatar Dec 20 '25 15:12 Destreyf

/review

rekram1-node avatar Dec 20 '25 17:12 rekram1-node

@rekram1-node I should have definitely had a little more attention before I submitted this. It caught a legitimate potential bug.

I've updated it with the suggested fix, it's slightly different syntax than the way the original did it, but it should accomplish the same outcome.

If you want me to adjust the formatting let me know.

Destreyf avatar Dec 20 '25 21:12 Destreyf

this is mostly just the builtin /review command nothing super crazy glad it works!

rekram1-node avatar Dec 21 '25 03:12 rekram1-node

/review

rekram1-node avatar Dec 21 '25 03:12 rekram1-node

/review

(does this work for non contributers, i doubt it)

Destreyf avatar Dec 22 '25 00:12 Destreyf

it only works for admins!

rekram1-node avatar Dec 22 '25 03:12 rekram1-node

/review

rekram1-node avatar Dec 22 '25 03:12 rekram1-node

lgtm

github-actions[bot] avatar Dec 22 '25 03:12 github-actions[bot]

it only works for admins!

I figured as much, I am actually using your guy's exact review workflow in a project of mine, and will be adding it to the rest of my repo's. I saw "Owner" as a filter but wasn't certain on who counted as that fronm my brief skim.

The primary motivator for this update to the vscode extension is I am running Coder workspaces and I run a copy of opencode as a background task, so being able to attach to it is super helpful from within vscode.

My normal workflow currently is to "attach" to the server outside of the vscode extension, but this makes it much easier to have a one click launch, the actual endpoint for us is always going to be localhost:4096, but having it configurable could be beneficial if you're running something like cloudflare agents to host a copy of opencode, or really anytime you could want to attach to a running instance.

LMK if there's any concerns.

Destreyf avatar Dec 22 '25 05:12 Destreyf

The way the extension currently works is when the extension opens a terminal with a random port, so it can communicate for the append.

I don't see an easy endpoint for doing this same thing, so the solution I am testing is using the terminal.sendText with the shouldExecute set to false.

This really only impacts if a user is opening multiple opencode windows inside of the editor.

If we need to have a larger discussion around this I am happy to put this on hold.

Destreyf avatar Dec 22 '25 23:12 Destreyf

wait so what does that have to do w/ the extra setting? I don't know if im following

rekram1-node avatar Dec 23 '25 04:12 rekram1-node