OpenCode to VSCode Bridge
Author: Vlado Vrbanec — vlado.vrbanec@mvv.hr
Purpose: Agent awareness of the user's visual working environment. The AI agent can see which tabs are open, cursor position, selection range, dirty (unsaved) state per file, and manipulate the editor directly. This lets the agent reason about what the user sees and work contextually within their editor.
Works in terminal or Windows GUI client applications.
Agent can call all 16 predefined editor tools + 18 slash commands.
Plugin supports up to 5 open VSCode sessions simultaneously, with automatic switching when changing sessions.
⚡Does not work under Linux.
Components
| Component |
Location |
| VSCode Extension |
HTTP bridge server inside VSCode |
| HTTP Bridge Server |
Loads automatically and is available on first available port between 49152 and 49156 |
| OpenCode Plugin |
Plugin is automatically installed when VSCode extension is installed. |
|
Is automatically reinstalled if version is changed. |
|
When OpenCode is loaded, connect to port if session folder is the same as in VSCode workspace. |
|
Connect to port of another VSCode instance if OpenCode session is changed. |
|
This way one OpenCode GUI or terminal can be connected to multiple VSCode instances. |
Terminal or TUI Electron app ?
OpenCode can run as a terminal application (CLI) or as a GUI application built with Electron/Tauri.
We recommend using the GUI for better user experience.
GUI can run multiple tabs, multiple sessions, and multiple workspaces.
Reconnections to VSCode session with the same workspace is automatically handled.
Download: https://opencode.ai/download/stable/windows-x64-nsis
Architecture
| Component |
Role |
OpenCode plugin (vscode-bridge.js) |
Sends tool calls via HTTP to VSCode extension |
VSCode extension (server.ts) |
Receives requests, interacts with editor |
| Connection |
localhost:PORT (127.0.0.1 only, ports 49152-49156) |
|
*Automatic selection, connection, and reconnection. |
| Plugin tools |
info, selection, open, command, edit_range, insert_at_line, clear_marks, edit_file, edit_create, source, files, workspace_files |
|
*All managed by AI Agent, not user ! |
| Built-in tools |
read/write/edit → filesystem (preferred for plain file ops) |
ℹ️ Tools are used by the AI agent, not the user. For file reading and editing, the agent can use OpenCode's built-in tools or extension tools.
ℹ️ Agent will automatically figure out used endpoints and parameters.
Slash commands (from version 0.0.3)
User-facing shortcuts. Type /vscNaziv in the OpenCode chat to run an editor-aware task. Registered by the plugin at startup — no configuration needed.
| Command |
What it does |
/vscDebugTab |
Debug the file open in the active VSCode editor tab |
/vscDebugSelection |
Debug the code currently selected in the VSCode active editor |
/vscReviewTab |
Code review of the file open in the active VSCode editor tab |
/vscReviewSelection |
Code review of the selected code in the VSCode active editor |
/vscExplainTab |
Explain what the file open in the active VSCode editor tab does |
/vscExplainSelection |
Explain the code currently selected in the VSCode active editor |
/vscExplainFunction |
Explain the selected function and how it is used in the application |
/vscExplainProject |
Explain current project and show prompt to save explanation to a file |
/vscFindUsages |
Find all usages of the selected function/class/variable across the workspace |
/vscRefactorTab |
Refactor the file open in the active VSCode editor tab |
/vscRefactorSelection |
Refactor the selected code in the VSCode active editor |
/vscTestTab |
Generate unit tests for the file open in the active VSCode editor tab |
/vscTestSelection |
Generate unit tests for the selected code in the VSCode active editor |
/vscDocTab |
Add documentation comments to the file open in the active VSCode editor tab |
/vscDocSelection |
Add documentation comments to the selected code in the VSCode active editor |
/vscAddTabToContext |
Read the active tab and add its structured summary to the working context |
/vscAddAllTabsToContext |
Read all open tabs and create a workspace state map |
/vscMapToContext |
Map the project structure and key files for context |
Definitions: inject/vsc-commands.json. Set "enabled": false to disable.
⚡ Quick Install
ℹ️ If not installed from side panel:
Install from marketplace.
OpenCode to VSCode Bridge — VS Code Marketplace
OpenCode plugin setup (required)
The OpenCode plugin is automatically installed when you start the VSCode extension.
⚡ If OPENCODE is installed after extension, please reinstall VSCode extension.
✨ Usage
When component is installed, start or restart opencode.
The plugin automatically connects to the VSCode bridge when you open a workspace folder.
Ask the agent a few questions:
ℹ️ Doesn't need to be exact, agent will understand the context.
ℹ️ Instructions to the agent can be in any language, not just English; however, the agent will pick up context at the beginning of the session in English faster.
Agent will probably 'think' in English but will understand your language, and answer in your language.
⚡ If you realize that the agent does not understand the editor context immediately, write "vsc, " at the beginning of the first few instructions, since this is a clear trigger word.
- Which file is opened in editor?
- What is the current cursor position?
- What is the current selection?
- What is the current line number?
- What is the current column number?
- What is the selected text?
- Please debug file opened in editor.
- ... and other questions
When the AI agent knows the context, we can ask without specifying the file name:
- Check file for errors.
- Insert "This text" at cursor position.
- Please create comment for function MyExampleFunction.
- Please check selected lines for errors.
- Translate selected text to Italian
And other instructions in natural language.
Agent will automatically try to obey instructions.
With time you will learn which instructions are more clear to the agent.
⚡If VSCode extension is not active, or used folder is not the same, agent will respond with an predefined error message.
Status Bar
The extension adds a status bar indicator at the bottom-right of VSCode: 
| Indicator |
Meaning |
$(broadcast) OCB: <port> |
Bridge active, listening on port |
$(broadcast) OCB |
Bridge starting (no port yet) |
$(check) OCB: patched |
OpenCode GUI is patched with bridge |
$(error) OCB |
Bridge failed to start |
Click on the status bar item to open the Actions Menu:
| Action |
What it does |
$(terminal) Open Terminal |
Creates integrated terminal in workspace folder and runs opencode |
$(debug) Patch OpenCode GUI |
Injects bridge code into OpenCode desktop app.asar — enables GUI additions ( *VSCode bridge is enabled withouth injection ) |
$(discard) Restore OpenCode GUI |
Restores original app.asar backup, removing bridge injection |
$(dashboard) Open OpenCode GUI |
Launches OpenCode desktop application via explorer.exe |
$(info) About |
Opens extension README |
Keyboard shortcut: Ctrl+Shift+Alt+O — shows connection info (port, PID, workspace, discovery path).
Note: Patching the OpenCode GUI (app.asar) is not required for the plugin to work. The plugin connects to the VSCode bridge over HTTP regardless. Patching enables additional features: a status banner inside the OpenCode GUI showing connection state, and a dropdown with server/port info.
Configuration
VSCode settings (settings.json):
{
"opencodeBridge.enabled": true,
"opencodeBridge.openCodeGuiPath": ""
}
| Setting |
Default |
Description |
opencodeBridge.enabled |
true |
Enable/disable the OpenCode VSCode Bridge |
opencodeBridge.openCodeGuiPath |
"" |
Full path to OpenCode desktop GUI executable. Leave empty for auto-detect. |
Notes
- Each OpenCode GUI and terminal instance automatically pairs with VSCode running in the same workspace.
- The process will be repeated if session is changed.
- LIMITATION. OpenCode GUI is launched via
explorer.exe (Windows shell) rather than direct spawn. Reason: Electron/Tauri apps don't show their window when spawned directly from a VSCode extension due to Windows session/window station isolation. explorer.exe ensures the GUI opens in the correct user session. Caveat: if the GUI is already running in another session (RDP, fast user switching), explorer will activate that instance instead of launching a new one in the current session.
- Bridge runs on localhost only (127.0.0.1) — no external network access.