opencode
opencode copied to clipboard
fix(desktop): Custom server.hostname config ignored - always connects to 127.0.0.1
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
- Set config at
~/.config/opencode/opencode.json:{ "$schema": "https://opencode.ai/config.json", "server": { "hostname": "my-tailscale-hostname", "port": 4096 } } - Launch Opencode Desktop
- Observe error: Failed to spawn Opencode Server
Expected Behavior
- Desktop app should connect to http://my-tailscale-hostname:4096
Actual Behavior
- Server logs: opencode server listening on http://my-tailscale-hostname:4096
- Desktop throws: Error: Failed to spawn OpenCode Server after timeout
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:
- Tauri spawns sidecar with --port only (no --hostname)
- CLI reads server.hostname from config → binds to custom hostname
- Tauri health check connects to 127.0.0.1:port → fails (server isn't there)
- 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
- Read server.hostname and server.port from ~/.config/opencode/opencode.json in Tauri
- Pass --hostname={configured} when spawning sidecar
- Use configured hostname in is_server_running() health check
- Inject hostname to frontend via window.OPENCODE.hostname
- 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