Skip to content

fix(desktop): Custom server.hostname config ignored - always connects to 127.0.0.1 #7971

@AidenGeunGeun

Description

@AidenGeunGeun

Bug Description

When configuring a custom server.hostname in ~/.config/opencode/opencode.json, the OpenCode Desktop app fails to connect even though the server starts successfully on the configured address.

Steps to Reproduce

  1. Set config at ~/.config/opencode/opencode.json:
    {
      "$schema": "https://opencode.ai/config.json",
      "server": {
        "hostname": "my-tailscale-hostname",
        "port": 4096
      }
    }
    
  2. Launch Opencode Desktop
  3. Observe error: Failed to spawn Opencode Server

Expected Behavior

Actual Behavior

Root Cause Analysis

  • Three locations have hardcoded 127.0.0.1:
File Line Issue
packages/desktop/src-tauri/src/lib.rs 166, 182 spawn_sidecar() doesn't pass --hostname to CLI
packages/desktop/src-tauri/src/lib.rs 228-229 is_server_running() checks 127.0.0.1 instead of configured hostname
packages/app/src/app.tsx 43 Frontend URL hardcoded to http://127.0.0.1:{port}

Flow:

  1. Tauri spawns sidecar with --port only (no --hostname)
  2. CLI reads server.hostname from config → binds to custom hostname
  3. Tauri health check connects to 127.0.0.1:port → fails (server isn't there)
  4. Timeout → error thrown

Use Case

Enabling remote access via Tailscale, hosting the OpenCode server on one machine and accessing it from other devices on the Tailscale network.

Proposed Fix

  1. Read server.hostname and server.port from ~/.config/opencode/opencode.json in Tauri
  2. Pass --hostname={configured} when spawning sidecar
  3. Use configured hostname in is_server_running() health check
  4. Inject hostname to frontend via window.OPENCODE.hostname
  5. Update app.tsx to use injected hostname (fallback to 127.0.0.1)

Happy to submit a PR if this approach is acceptable.

Environment
OS: Windows 11
OpenCode Desktop: v1.1.14

Metadata

Metadata

Assignees

Labels

webRelates to opencode on web / desktop

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions