Skip to content

feat(core): add server.enabled config option to restore HTTP server#8562

Open
rmk40 wants to merge 1 commit intoanomalyco:devfrom
rmk40:feat/server-enabled-config
Open

feat(core): add server.enabled config option to restore HTTP server#8562
rmk40 wants to merge 1 commit intoanomalyco:devfrom
rmk40:feat/server-enabled-config

Conversation

@rmk40
Copy link
Contributor

@rmk40 rmk40 commented Jan 14, 2026

Summary

Adds a server.enabled config option and --enable-server CLI flag that explicitly enable the HTTP server for the TUI, restoring the pre-982b71e behavior for users who need external connections (desktop app, SDK, etc).

Fixes #8561

Usage

Config (opencode.json):

{
  "server": {
    "enabled": true
  }
}

CLI:

opencode --enable-server

Both use the default port-0 fallback (try 4096, then random) on 127.0.0.1 — the same resilient behavior as before the server was disabled by default.

Changes

  • config.ts: Add enabled: z.boolean().optional() to Server schema
  • network.ts: Add --enable-server CLI option, resolve enabled from CLI flag or config, return in resolveNetworkOptions()
  • thread.ts: Add networkOpts.enabled || to shouldStartServer condition

Why

Since 982b71e ("disable server unless explicitly opted in"), users who need the HTTP server have no clean way to enable it:

  • port: 0 fails (schema rejects non-positive)
  • hostname: "127.0.0.1" doesn't trigger server (matches default)
  • mdns: true works but has unwanted side effects
  • There was no config-only path to start the server on default host/port

This provides a clear, self-documenting opt-in via both config and CLI with no side effects.

Testing

Tested locally — setting "server": { "enabled": true } in opencode.json or passing --enable-server correctly starts the HTTP server with the default port-0 fallback behavior.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

rmk40 added a commit to actualyze-ai/opencode-monitor that referenced this pull request Jan 17, 2026
- Change config from http.enabled/port to server.hostname: localhost
- Add explanation that localhost differs from default 127.0.0.1
- Reference upstream PR anomalyco/opencode#8562 for cleaner server.enabled option
- Update README.md and INSTALL.md
@thdxr thdxr force-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@escaton
Copy link

escaton commented Feb 10, 2026

Hi @rmk40 are there any blockers to merge this?

@rmk40 rmk40 force-pushed the feat/server-enabled-config branch from 1897f25 to 17e88cc Compare February 12, 2026 04:46
@rmk40
Copy link
Contributor Author

rmk40 commented Feb 12, 2026

Shouldn't be and I've confirmed there's no way to replicate the desired behavior (which was also prior behavior) of starting the server on localhost, assigning port to 4096 and falling back to dynamic assignment. Basically it takes specifying port to get the server to start on localhost, which will fail if the port isn't available. Yet, starting on say 0.0.0.0 without specifying port works and will try 4096 and fall back to others accordingly.

@rmk40 rmk40 force-pushed the feat/server-enabled-config branch from 17e88cc to b413c7c Compare February 13, 2026 01:55
Adds a `server.enabled` config option that explicitly enables the HTTP
server for the TUI, restoring the pre-982b71e behavior for users who
need external connections (desktop app, SDK, etc).

Usage in opencode.json:
  { "server": { "enabled": true } }

This provides a clear opt-in mechanism without relying on side effects
like setting hostname to 'localhost' or enabling mDNS.

Refs: 982b71e (disable server unless explicitly opted in)
@rmk40 rmk40 force-pushed the feat/server-enabled-config branch from b413c7c to 7f8884d Compare February 13, 2026 02:44
@rmk40
Copy link
Contributor Author

rmk40 commented Feb 13, 2026

Worth noting for anyone evaluating workarounds: --hostname and --hostname 127.0.0.1 on the CLI do start the server today, because shouldStartServer includes a raw process.argv.includes("--hostname") check that fires regardless of the value passed.

The gap this PR addresses is the config-only path. If you set "server": { "hostname": "127.0.0.1" } in opencode.json (no CLI flag), the server won't start because:

  • process.argv.includes("--hostname")false (no CLI flag present)
  • networkOpts.hostname !== "127.0.0.1"false (matches default)

There's no config-only way to say "start the server on the default host/port" without side effects like enabling mDNS or binding to 0.0.0.0. That's what server.enabled (and the new --enable-server CLI flag) provide — a clear opt-in with no side effects, using the same resilient port-0 fallback (try 4096, then random).

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.

Add server.enabled config option to explicitly enable HTTP server

2 participants