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

Open
opened 2026-02-16 17:44:49 -05:00 by yindo · 1 comment
Owner

Originally created by @ShubDVS on GitHub (Jan 10, 2026).

Originally assigned to: @thdxr on GitHub.

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
Originally created by @ShubDVS on GitHub (Jan 10, 2026). Originally assigned to: @thdxr on GitHub. # 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
yindo added the windows label 2026-02-16 17:44:49 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 10, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7085: OpenCode Desktop starts multiple windows when launched once from a script - similar root cause of multiple instances spawning
  • #6051: Lost changes and session in vscode when switching between CLI and extension - related to multiple instances connecting to same project
  • #5256: Adding Authentication to opencode server api - related to authentication for remote server access
  • #2783: Use ZeroMQ or WebSockets for shared event bus - addresses state synchronization between multiple OpenCode processes

While not exact duplicates, these issues all address challenges with running multiple OpenCode instances and server management that your issue proposes to solve through automatic detection and connection reuse.

Feel free to ignore if your specific case differs from these.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue might be a duplicate of existing issues. Please check: - #7085: OpenCode Desktop starts multiple windows when launched once from a script - similar root cause of multiple instances spawning - #6051: Lost changes and session in vscode when switching between CLI and extension - related to multiple instances connecting to same project - #5256: Adding Authentication to opencode server api - related to authentication for remote server access - #2783: Use ZeroMQ or WebSockets for shared event bus - addresses state synchronization between multiple OpenCode processes While not exact duplicates, these issues all address challenges with running multiple OpenCode instances and server management that your issue proposes to solve through automatic detection and connection reuse. Feel free to ignore if your specific case differs from these.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4624