cli doesnt connect to vscode #6660

Open
opened 2026-02-16 18:04:53 -05:00 by yindo · 2 comments
Owner

Originally created by @pdeva on GitHub (Jan 17, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

I tried installing Opencode into VSCode by opening it up from the integrated terminal, but it didn't work. So, I manually installed the VSCode extension and tried to start OpenCode from that extension, but even then, when the CLI pops up, it has no connection to my ide/editor.

Plugins

No response

OpenCode version

1.125

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

on macos running vscode on my ubunutu linux box using vscode remote ssh plugin

Terminal

No response

Originally created by @pdeva on GitHub (Jan 17, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description I tried installing Opencode into VSCode by opening it up from the integrated terminal, but it didn't work. So, I manually installed the VSCode extension and tried to start OpenCode from that extension, but even then, when the CLI pops up, it has no connection to my ide/editor. ### Plugins _No response_ ### OpenCode version 1.125 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System on macos running vscode on my ubunutu linux box using vscode remote ssh plugin ### Terminal _No response_
yindo added the bug label 2026-02-16 18:04:53 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 17, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6051: Lost changes and session in vscode - Similar VSCode extension connection and session management issues
  • #7275: [FEATURE]: cleaner and more aware extensions integration with vscode - Related to VSCode extension integration challenges
  • #2220: Cross platform open opencode in VSCode - Related to opening OpenCode from VSCode on different platforms
  • #5094: OpenCode TUI loses connection with server - General connection loss issues between CLI and server

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue might be a duplicate of existing issues. Please check: - #6051: Lost changes and session in vscode - Similar VSCode extension connection and session management issues - #7275: [FEATURE]: cleaner and more aware extensions integration with vscode - Related to VSCode extension integration challenges - #2220: Cross platform open opencode in VSCode - Related to opening OpenCode from VSCode on different platforms - #5094: OpenCode TUI loses connection with server - General connection loss issues between CLI and server Feel free to ignore if none of these address your specific case.
Author
Owner

@LIHUA919 commented on GitHub (Jan 18, 2026):

The root cause of this issue is that in Remote SSH scenarios, the VSCode extension runs on your local macOS machine, but the CLI server runs on the remote Ubuntu machine.

When the extension tries to connect via fetch(http://localhost:${port}/app) (line 78 in extension.ts), it connects to local localhost instead of the remote localhost where the CLI server is listening.

Solution

VSCode provides the vscode.env.asExternalUri() API to handle this exact scenario. It automatically sets up port forwarding for remote environments.

For the OpenCode maintainers

The fix requires modifying sdks/vscode/src/extension.ts:

Current code (line 78):

await fetch(`http://localhost:${port}/app`)

Should be:

const externalUri = await vscode.env.asExternalUri(
  vscode.Uri.parse(`http://localhost:${port}/app`)
);
await fetch(externalUri.toString());

The same change is needed in the appendPrompt function (line 94).

Workaround for users

Until this is fixed, you can manually set up SSH port forwarding:

  1. Find the port displayed in the terminal (the random port number)
  2. Add SSH port forwarding in your SSH config or use:
    ssh -L ${port}:localhost:${port} your-server
    

Reference: Supporting Remote Development and GitHub Codespaces - see the "Forwarding localhost" section

@LIHUA919 commented on GitHub (Jan 18, 2026): The root cause of this issue is that in Remote SSH scenarios, the VSCode extension runs on your **local** macOS machine, but the CLI server runs on the **remote** Ubuntu machine. When the extension tries to connect via `fetch(`http://localhost:${port}/app`)` (line 78 in extension.ts), it connects to **local** localhost instead of the **remote** localhost where the CLI server is listening. ## Solution VSCode provides the `vscode.env.asExternalUri()` API to handle this exact scenario. It automatically sets up port forwarding for remote environments. ### For the OpenCode maintainers The fix requires modifying `sdks/vscode/src/extension.ts`: **Current code (line 78):** ```typescript await fetch(`http://localhost:${port}/app`) ``` **Should be:** ```typescript const externalUri = await vscode.env.asExternalUri( vscode.Uri.parse(`http://localhost:${port}/app`) ); await fetch(externalUri.toString()); ``` The same change is needed in the `appendPrompt` function (line 94). ### Workaround for users Until this is fixed, you can manually set up SSH port forwarding: 1. Find the port displayed in the terminal (the random port number) 2. Add SSH port forwarding in your SSH config or use: ```bash ssh -L ${port}:localhost:${port} your-server ``` Reference: [Supporting Remote Development and GitHub Codespaces](https://code.visualstudio.com/api/advanced-topics/remote-extensions) - see the "Forwarding localhost" section
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6660