Skip to main content
Glama
OpenCode Remote Bridge

OpenCode Remote Bridge

by sandro9800
README.md
<div align="center">

# 🌉 OpenCode Remote Bridge

**Control your local [OpenCode](https://opencode.ai/) from anywhere, through any MCP client.**

An authenticated [Model Context Protocol](https://modelcontextprotocol.io/) server that exposes OpenCode sessions, files, terminal and Git over Streamable HTTP, published on a persistent [zrok](https://zrok.io/) public name.

[![CI](https://github.com/sandro9800/opencode-remote-bridge-clean/actions/workflows/ci.yml/badge.svg)](https://github.com/sandro9800/opencode-remote-bridge-clean/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
![Node](https://img.shields.io/badge/node-%E2%89%A520-339933?logo=node.js&logoColor=white)
![MCP](https://img.shields.io/badge/MCP-Streamable%20HTTP-blue)

</div>

> [!WARNING]
> This bridge gives whoever holds the bearer token **read/write/delete access to files and command execution** on the host machine. It is not a hardened sandbox. Only connect clients you trust, keep the token secret, and review your OpenCode permissions.

---

## Table of contents

- [Features](#features)
- [How it works](#how-it-works)
- [Requirements](#requirements)
- [Quick start](#quick-start)
- [Connect an AI client](#connect-an-ai-client)
- [Autonomous Goal Runner](#autonomous-goal-runner)
- [MCP tools](#mcp-tools-17)
- [Commands](#commands)
- [Configuration](#configuration)
- [Termux + Debian (PRoot)](#termux--debian-proot)
- [Security](#security)
- [Troubleshooting](#troubleshooting)
- [Development](#development)
- [License](#license)

## Features

- 🔐 **Bearer-token auth** with timing-safe comparison
- 🌐 **MCP Streamable HTTP** transport, works with Cursor, VS Code, Claude Code and more
- 💬 **OpenCode sessions**: create, prompt (sync or async), inspect, abort, delete
- 📁 **Filesystem tools**: read, write, list, search, delete
- 💻 **Terminal**: run commands through an OpenCode session and its permissions
- 🌿 **Git**: status and diff
- 🤖 **Autonomous Goal Runner**: orchestrator, worker and reviewer loop until the goal is verified
- 🚀 **One-command manager** for OpenCode, the bridge and a persistent zrok share
- 🧩 Preserves your other MCP servers (e.g. Composio) when updating the OpenCode config

## How it works

```mermaid
flowchart LR
    A[MCP client<br/>Cursor / VS Code / Claude Code] -- HTTPS + Bearer token --> B[zrok public name]
    B --> C[Bridge :8787<br/>/mcp]
    C --> D[OpenCode API :4096]
    D --> E[(Your project<br/>files, shell, Git)]
```

Both OpenCode and the bridge bind to `127.0.0.1`. Only zrok exposes the bridge publicly.

## Requirements

| Requirement | Notes |
|---|---|
| Debian / Ubuntu | Debian in Termux/PRoot is supported |
| Node.js 20+ and npm | Node 22 recommended |
| OpenCode CLI | available as `opencode` |
| zrok v2 CLI | available as `zrok2`, with an enabled account |
| Python 3, OpenSSL, curl, Git | used by the installer and manager |
| Free local ports | **4096** (OpenCode) and **8787** (bridge) |

<details>
<summary><b>Install system requirements (Debian/Ubuntu)</b></summary>

Run as root, or prefix with `sudo`.

```bash
# Basics
apt-get update
apt-get install -y ca-certificates curl git openssl python3

# Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs

# OpenCode CLI
curl -fsSL https://opencode.ai/v2/install | bash
export PATH="$HOME/.opencode/bin:$PATH"   # add to ~/.bashrc if needed

# zrok v2
curl -sSf https://get.openziti.io/install.bash | bash -s zrok2
```

References: [OpenCode docs](https://opencode.ai/docs/) · [zrok reserved names](https://netfoundry.io/docs/zrok/how-tos/shares/manage-reserved-names/)

</details>

## Quick start

### 1. Set up zrok (one time)

```bash
zrok2 enable YOUR_ZROK_ENABLE_TOKEN
zrok2 create name -n public YOUR_UNIQUE_NAME
zrok2 list names
```

Your endpoint will be `https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp`. Every installation needs its own reserved name. Never publish your enable token.

### 2. Install the bridge

```bash
git clone https://github.com/sandro9800/opencode-remote-bridge-clean.git
cd opencode-remote-bridge-clean
chmod +x mcp scripts/install.sh
./scripts/install.sh
```

The installer installs dependencies and creates a private `.bridge-token` (git-ignored, restricted permissions).

### 3. Set your zrok name

Open the `mcp` script and set, near the top:

```bash
ZROK_RESERVED_NAME="public:YOUR_UNIQUE_NAME"
```

### 4. Start

```bash
./mcp start     # OpenCode API + bridge + zrok share
./mcp client    # open OpenCode with the bridge configured
```

Keep `./mcp start` running while an external assistant is connected. Read your token locally with `cat .bridge-token`.

## Connect an AI client

Any client that supports **remote HTTP MCP** with custom headers works.

- **URL:** `https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp`
- **Header:** `Authorization: Bearer YOUR_BRIDGE_TOKEN`

<details>
<summary><b>Cursor</b></summary>

```json
{
  "mcpServers": {
    "opencode-remote-bridge": {
      "url": "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
      "headers": { "Authorization": "Bearer YOUR_BRIDGE_TOKEN" }
    }
  }
}
```

</details>

<details>
<summary><b>VS Code</b> (<code>.vscode/mcp.json</code>)</summary>

```json
{
  "inputs": [
    {
      "type": "promptString",
      "id": "bridge-token",
      "description": "OpenCode Remote Bridge token",
      "password": true
    }
  ],
  "servers": {
    "opencode-remote-bridge": {
      "type": "http",
      "url": "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
      "headers": { "Authorization": "Bearer ${input:bridge-token}" }
    }
  }
}
```

</details>

<details>
<summary><b>Claude Code</b></summary>

```bash
claude mcp add --transport http opencode-remote-bridge \
  https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp \
  --header "Authorization: Bearer YOUR_BRIDGE_TOKEN"
```

Command-line arguments can end up in shell history. Prefer a safer credential method where available.

</details>

<details>
<summary><b>Stdio-only clients</b> (via <code>mcp-remote</code>)</summary>

```json
{
  "mcpServers": {
    "opencode-remote-bridge": {
      "command": "npx",
      "args": [
        "-y", "mcp-remote",
        "https://YOUR_UNIQUE_NAME.shares.zrok.io/mcp",
        "--header", "Authorization: Bearer YOUR_BRIDGE_TOKEN"
      ]
    }
  }
}
```

</details>

> [!NOTE]
> MCP connects an assistant to OpenCode's tools. It does **not** copy skills or agents between products. OpenCode skills, agents and `AGENTS.md` must live in the environment running this bridge.

## Autonomous Goal Runner

Submit one high-level goal and three OpenCode sessions work on it:

| Role | Job |
|---|---|
| **Orchestrator** | Breaks the goal into tasks and decides what remains |
| **Worker** | Performs each task with your configured tools, skills and agents |
| **Reviewer** | Independently inspects the project and checks the original goal is really done |

The loop runs in the background until the reviewer verifies completion, you cancel it, an error occurs, or the iteration limit is hit (default 20, configurable 1 to 100). State is saved in `.goal-runner/goals.json` with restrictive permissions.

**Goal tools:** `list_goal_models` · `start_goal` · `get_goal_status` · `list_goals` · `control_goal` (pause / resume / cancel)

Example prompt for your MCP client:

```text
Start a goal: make this project production-ready. Use auto model selection,
work in the current project, and run tests. Keep working until an independent
review verifies every acceptance criterion.
```

**Models:** set any role to `auto`, or use an exact `providerID/modelID` from `list_goal_models`. The runner uses OpenCode's live provider catalog (cloud, local and custom providers, including NVIDIA NIM once configured in OpenCode). See [OpenCode providers](https://opencode.ai/docs/providers/) and the [NVIDIA API Catalog](https://build.nvidia.com/).

**Limits:**

- The worker inherits your OpenCode instance's permissions.
- The reviewer is a separate session, not a formal proof. Check important changes yourself.
- In-flight goals are not auto-resumed after a restart. Use `list_goals`, then resume.
- Automatic cross-provider fallback is not yet enabled.
- Avoid running several goals in the same working directory.

## MCP tools (17)

| Category | Tools |
|---|---|
| **Sessions** | `opencode_health`, `list_sessions`, `get_session_messages`, `create_session`, `send_prompt`, `send_prompt_async`, `get_session_status`, `abort_session`, `delete_session`* |
| **Filesystem** | `read_file`, `write_file`, `list_files`, `search_files`, `delete_file`* |
| **Terminal** | `run_command` (via an OpenCode session and its permissions) |
| **Git** | `git_status`, `git_diff` |

\* Destructive: requires `confirm: "DELETE"`.

Goal Runner tools are listed [above](#autonomous-goal-runner).

## Commands

| Command | Action |
|---|---|
| `./mcp start` | Start all services |
| `./mcp stop` | Stop managed services |
| `./mcp restart` | Restart all services |
| `./mcp status` | Show service state and zrok URL |
| `./mcp logs` | Show recent logs |
| `./mcp client` | Open isolated OpenCode client |

Logs and PIDs: `~/.local/state/opencode-remote-bridge/` · Client profile: `~/.config/opencode-remote-bridge/`

## Configuration

The `./mcp` manager uses the default ports (4096 and 8787), so keep them when using it. When running the server directly with `npm start`, these environment variables apply (see `.env.example`):

| Variable | Default | Meaning |
|---|---|---|
| `BRIDGE_HOST` | `127.0.0.1` | MCP bind interface |
| `BRIDGE_PORT` | `8787` | MCP port |
| `OPENCODE_URL` | `http://127.0.0.1:4096` | Local OpenCode API |
| `BRIDGE_TOKEN_FILE` | `.bridge-token` | Private token file |

Keep the bridge bound to localhost when using zrok.

## Termux + Debian (PRoot)

```bash
pkg update && pkg upgrade
pkg install proot-distro git
proot-distro install debian
proot-distro login debian --shared-tmp
```

Then follow the Debian steps above inside the shell. Android battery management can kill background processes, so exclude Termux from battery optimization.

## Security

- Use a unique, unpredictable bearer token per installation.
- Never commit or share `.bridge-token`, client configs or credentials.
- OpenCode and the bridge bind to localhost; zrok provides the public ingress.
- Anyone with the token can invoke **every** exposed tool.
- There is no per-tool authorization or sandboxing. Run it on a machine and in a project you are comfortable exposing.

## Troubleshooting

| Problem | Fix |
|---|---|
| Port in use | Stop the conflicting service on 4096 / 8787 |
| zrok share won't start | Check `zrok2 status`, `zrok2 list names`, `./mcp logs` |
| `401 Unauthorized` | Verify the `Authorization` header and token (unauthenticated requests return 401 by design) |
| OpenCode unavailable | Check the `opencode` CLI and `./mcp logs` |
| Termux stops services | Keep Termux alive; disable battery optimization |

## Development

```bash
npm install
npm run check
npm start
```

CI runs JavaScript and shell syntax checks on pushes and pull requests.

```text
src/
  config.js
  server.js
  lib/          # OpenCode API, output, path helpers
  middleware/   # Bearer authentication
  tools/        # OpenCode, filesystem, terminal, Git tools
scripts/
  install.sh
mcp             # service manager
.github/workflows/ci.yml
```

## License

[MIT](LICENSE)