Skip to content

feat(desktop): add --port and --hostname CLI arguments for sidecar configuration#22004

Open
hokonoko wants to merge 1 commit intoanomalyco:devfrom
hokonoko:feat/desktop-cli-port-hostname
Open

feat(desktop): add --port and --hostname CLI arguments for sidecar configuration#22004
hokonoko wants to merge 1 commit intoanomalyco:devfrom
hokonoko:feat/desktop-cli-port-hostname

Conversation

@hokonoko
Copy link
Copy Markdown

@hokonoko hokonoko commented Apr 11, 2026

Issue for this PR

Relates to #7629, #18906, #20271

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The OpenCode desktop app always spawns its sidecar server on a random OS-assigned port with 127.0.0.1 as hostname. The only way to override the port was the OPENCODE_PORT environment variable (compile-time or runtime). There was no way to change the hostname at all.

This PR adds --port and --hostname CLI arguments to the desktop app binary, so users can control the sidecar's listen address at launch time. This unblocks use cases like:

  • Exposing the desktop server to other devices on the network (--hostname 0.0.0.0)
  • Running on a predictable port for firewall rules or reverse proxies (--port 4096)
  • Scripting the desktop app with a known server address

How it works:

main.rs parses CLI args via parse_cli_args_from() into a CliOptions struct (port, hostname, warnings). The struct is passed through run_with_options()initialize(). Port/hostname overrides are applied when spawning the sidecar; invalid values produce a tracing::warn! log and fall back to defaults so the app never fails to start.

The existing run() entry point is preserved (no arguments) for #[cfg_attr(mobile, tauri::mobile_entry_point)] compatibility.

When a secondary instance is launched with --port/--hostname while a primary instance is already running, the single-instance handler logs an info message noting that these overrides are ignored.

Priority order:

  1. CLI --port / --hostname (highest)
  2. OPENCODE_PORT env var (port only, existing behavior)
  3. Random port / 127.0.0.1 (default)

How did you verify your code works?

  • cargo check --lib passes with no new warnings
  • cargo test --bin opencode-desktop — 15/15 unit tests pass covering: --port N, --port=N, --hostname ADDR, --hostname=ADDR, invalid/missing values, boundary values (0, 1, 65535), combined flags, unknown flags ignored
  • Manual verification of the tracing::warn output for invalid values in initialize()

Screenshots / recordings

N/A — this is a CLI argument change with no UI impact.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@hokonoko hokonoko requested a review from adamdotdevin as a code owner April 11, 2026 06:47
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant