Skip to content

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

Closed as not planned

Description

@ShubDVS

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

Activity

  1. github-actions commented on Jan 10, 2026

    @github-actions
    Contributor

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

    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.

  2. jrmcpeek commented on Mar 2, 2026

    @jrmcpeek

    Ran into this same issue in a linux setup with 1.2.15.

    If the server config block is present, and I run opencode serve to enable remote host connectivity, attempts to run opencode on the machine running opencode serve will simply hang as it loads the opencode.json config file with the server settings.

    It would be great if running the TUI would automatically connect to the running opencode serve instance, but picking a different point for its sidecar rather than hanging would better than the current state.

  3. github-actions commented on May 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions