OpenCode VSCode Bridge
Author: Vlado Vrbanec — vlado.vrbanec@mvv.hr
Bidirectional communication between OpenCode AI agent and VSCode editor.
Works in terminal or WIN GUI client application.
Can call all 14 predefined editor tools + custom commands (all VSCode API commands).
What the agent can do
- See which files are open, cursor position, selection, dirty/unsaved state
- Execute any VSCode command (save, format, undo, close tabs, toggle terminal...)
- Open files in the editor
- Read and edit files through VSCode (with Ctrl+Z undo support)
- List all project files by glob pattern (including hidden/ignored files)
Components
| Component |
Location |
| VSCode Extension |
extension/ — HTTP bridge server inside VSCode |
| HTTP Bridge Server |
Loads automatically and is available on first |
|
available port between 49152 and 49201 |
| OpenCode Plugin |
plugins/vscode-bridge.js |
|
Auto-connect and reconnect to port if session folder |
|
is the same as in VSCode Workspace. |
|
+ 14 predefined editor tools are registered. |
|
Installed with VSCode extension to opencode folder. |
Architecture
OpenCode desktop app / terminal
|
|-- OpenCode plugin (vscode-bridge.js)
| +-- injects context + trigger words at session start
| triggers: "vscode", "editor", "selection", "cursor", "tab"...
|
+-- OpenCode tools (vscode-bridge.js) --HTTP--> VSCode extension (this)
| |
| info, selection, open, command | localhost:PORT
| edit_range, edit_file, source, files | 127.0.0.1 only
| workspace_files |
| |
+-- Built-in tools (read/write/edit) --> filesystem
(preferred for file operations)
Rule: For file reading and editing, use OpenCode's built-in tools.
Use the bridge only to check editor state (dirty tabs, selection) and to execute
editor commands (save, format, undo, terminal, etc.).
Quick Install
Creates extension/opencode-to-vscode-bridge-x.x.x.vsix.
2. Install in VSCode if is not instaled from marketplace
Ctrl+Shift+P → Extensions: Install from VSIX... → select .vsix file.
3. OpenCode plugin setup (required)
The OpenCode plugin is automatically installed when you start the VSCode extension.
Please restart OpenCode terminal or Gui app after installation.
Usage
When components are 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:
- 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?
- Which is selected text?
- Please debug file opened in editor.
When file is mentioned in context, we can ask without specifying the file name:
And other instructions in natural language.
Agent will automatically query the editor for this information.
If VSCode extension is not active, or used folder is not the same, agent will respond with an error message.
Used language can be any language not just English.
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.