opencode
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
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
}
- Running opencode serve starts the backend server at 0.0.0.0:4096
- Opening the OpenCode desktop app or terminal subsequently also attempts to start a server on the same 0.0.0.0:4096
- 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:
- First check if a backend server is already running on the configured host:port
- If a server is already running → connect to it directly
- 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