Skip to main content
Glama
opencode VS Code Pipe Bridge

opencode VS Code Pipe Bridge

README.md
# opencode VS Code Pipe Bridge

[![CI](https://github.com/sadguychronicle/opencode-vscode-pipe/actions/workflows/ci.yml/badge.svg)](https://github.com/sadguychronicle/opencode-vscode-pipe/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

Give an external MCP agent (opencode, Claude Desktop, Cursor, or any MCP
client) control of your VS Code window **over a named pipe or Unix domain
socket instead of TCP**.

This exists because `localhost` is not always yours. Transparent proxies,
corporate MITM appliances, and sandbox tools can intercept loopback TCP and
turn a working editor bridge into `502 Bad Gateway` and hangs. Kernel IPC
sidesteps that entirely.

## Why not just use a localhost port?

- Many editor MCP bridges bind `127.0.0.1:<port>`. If anything intercepts
  loopback (e.g. a proxy with "proxy localhost" enabled), the handshake fails.
- Named pipes (Windows) and Unix domain sockets (macOS/Linux) are not TCP and
  are not routed through HTTP proxies.
- The endpoint is token-gated and the token lives in a user-only file, so other
  local users cannot trivially connect.

## How it works

```
┌──────────────┐   stdio JSON-RPC   ┌────────────┐   pipe / socket   ┌───────────────┐
│  MCP client  │ ◄────────────────► │    shim    │ ◄───────────────► │  VS Code ext. │
│  (opencode)  │  newline-delimited │  (Node.js) │   token auth      │ (extension.js)│
└──────────────┘                    └────────────┘                   └───────────────┘
```

- The extension serves MCP on `\\.\pipe\ocvscode-<id>` (Windows) or
  `<runtime-dir>/ocvscode-<id>.sock` (macOS/Linux), where
  `<id> = sha1(normalized workspace path)[0:12]`.
- It writes `%LOCALAPPDATA%\opencode-vscode-pipe\<id>.json` (or
  `$XDG_RUNTIME_DIR/opencode-vscode-pipe/<id>.json`) with the endpoint and a
  random token.
- The shim discovers that file, authenticates, and proxies JSON-RPC. If the
  editor is not running it stays connected in a degraded mode so your agent
  session survives a restart.

See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the protocol details.

## Tools

| Tool | What it does |
| --- | --- |
| `get_workspace_state` | Folders, active file, selection text, open editors |
| `list_commands` | List VS Code command IDs (filterable) |
| `execute_command` | Run any VS Code command (privileged) |
| `get_diagnostics` | Problems from language servers |
| `open_file` | Open a file at a line/column |
| `show_diff` | Diff editor between two files |
| `run_in_terminal` | Send text to an integrated terminal (not captured) |
| `get_document_symbols` | Symbol outline |
| `go_to_definition` | Definition at a position |
| `find_references` | References at a position |
| `get_hover` | Hover / type info |
| `get_code_actions` | Quick fixes and refactors |
| `rename_symbol` | Rename and apply the workspace edit |
| `add_breakpoint` | Add a source breakpoint |
| `list_debug_configurations` | Launch configurations |
| `start_debugging` | Start a debug session by name |
| `stop_debugging` | Stop the active session |

Lines are 1-based; characters are 0-based.

## Requirements

- VS Code 1.80 or newer (desktop).
- Node.js 18+ for the shim (opencode ships with a suitable runtime).

## Install

### From a release

Download the `.vsix` from
[Releases](https://github.com/sadguychronicle/opencode-vscode-pipe/releases),
then either:

```sh
code --install-extension opencode-vscode-pipe.vsix
```

or use **Extensions: Install from VSIX...** in the Command Palette. Reload the
window when prompted.

### From source

```sh
git clone https://github.com/sadguychronicle/opencode-vscode-pipe.git
cd opencode-vscode-pipe
npm run package
code --install-extension dist/opencode-vscode-pipe.vsix
```

## Configure opencode

1. Open the Command Palette and run **opencode Pipe: Copy opencode MCP Config**.
   This copies a ready-to-paste block and writes the shim to a stable path.
2. Paste it under the top-level `mcp` key of your opencode config, for example:

```jsonc
{
  "mcp": {
    "vscode-pipe": {
      "type": "local",
      "command": ["node", "C:\\Users\\<you>\\AppData\\Local\\opencode-vscode-pipe\\shim.js"],
      "enabled": true
    }
  }
}
```

3. Restart opencode and check the connection:

```sh
opencode mcp list
# ✓ vscode-pipe connected
```

The shim is copied into the registry directory on activation, so the path stays
the same across extension updates. On macOS/Linux the path is under
`$XDG_RUNTIME_DIR/opencode-vscode-pipe/shim.js` (or the system temp dir).

## Security

This is remote control for your editor. Read [SECURITY.md](SECURITY.md).

- Local IPC only; no TCP port is opened.
- Token-authenticated; token stored in a user-only (`0600`) file.
- `execute_command` and `run_in_terminal` can run arbitrary code.
- Tool output is untrusted input; beware prompt injection from repositories.
- Disable the extension when you are not using an agent.

## Compatibility

- Windows: named pipes. macOS/Linux: Unix domain sockets.
- The extension declares `extensionKind: ["workspace"]`, so in Remote/SSH/WSL
  windows it runs on the remote. The MCP client must run in the same
  environment as the extension to reach the pipe/socket.
- One endpoint per window, keyed to the first workspace folder.

## Development

```sh
npm run check    # node --check on both entrypoints
npm test         # unit + shim integration tests (node:test)
npm run package  # build dist/*.vsix with @vscode/vsce
```

No runtime dependencies; nothing to bundle.

## Publishing

Tagged releases (`v*`) are packaged in CI. To publish automatically, add
repository secrets:

- `VSCE_PAT` for the VS Code Marketplace
- `OVSX_TOKEN` for [Open VSX](https://open-vsx.org)

The release workflow publishes only the marketplaces whose token is present and
always attaches the VSIX to the GitHub release.

## Limitations

- Only the first workspace folder per window is exposed.
- `run_in_terminal` is fire-and-forget; it does not capture output.
- Language features depend on a language server being active.
- No TCP fallback by design.

## License

[MIT](LICENSE)