opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[Enhancement] Desktop app and terminal should connect to existing server instead of starting a new one when port is already in use

Open ShubDVS opened this issue 3 days ago • 1 comments

Description

When configuring OpenCode with a custom server configuration specifying a port and hostname, there's a conflict when running multiple OpenCode instances.

Current Behavior

Given this server configuration:

"server": {
  "port": 4096,
  "hostname": "0.0.0.0",
  "mdns": true
}
  1. Running opencode serve starts the backend server at 0.0.0.0:4096
  2. Opening the OpenCode desktop app or terminal subsequently also attempts to start a server on the same 0.0.0.0:4096
  3. This results in an error because the port is already in use

Expected Behavior

When a user has explicitly configured a specific host and port, OpenCode should:

  1. First check if a backend server is already running on the configured host:port
  2. If a server is already running → connect to it directly
  3. If no server is running → start a new server

Proposed Solutions

Option A: Automatic detection

When both hostname and port are explicitly configured, OpenCode should automatically detect an existing server and connect to it instead of attempting to start a new instance.

Option B: New config flag

Add a new configuration option (e.g., "connectOnly": true or "reuseServer": true) that when enabled:

  • Prevents starting a new server if one is already running on the configured address
  • All subsequent OpenCode instances connect to the existing server

Environment

  • OpenCode version: 1.1.11
  • OS: Windows

ShubDVS avatar Jan 10 '26 12:01 ShubDVS