From a5d9929c0aa510e79fae517bc959e4ce9ca1a9ac Mon Sep 17 00:00:00 2001 From: itsmylife44 <34112129+itsmylife44@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:59:10 +0100 Subject: [PATCH] feat: support OPENCODE_SERVER_PORT and OPENCODE_SERVER_HOSTNAME env vars (#1157) Add support for customizing the OpenCode server port and hostname via environment variables. This enables orchestration tools like Open Agent to run multiple concurrent missions without port conflicts. Environment variables: - OPENCODE_SERVER_PORT: Custom port for the OpenCode server - OPENCODE_SERVER_HOSTNAME: Custom hostname for the OpenCode server When running oh-my-opencode in parallel (e.g., multiple missions in Open Agent), each instance can now use a unique port to avoid conflicts with the default port 4096. --- src/cli/run/runner.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cli/run/runner.ts b/src/cli/run/runner.ts index 30e46688f..91666660c 100644 --- a/src/cli/run/runner.ts +++ b/src/cli/run/runner.ts @@ -31,8 +31,18 @@ export async function run(options: RunOptions): Promise { } try { + // Support custom OpenCode server port via environment variable + // This allows Open Agent and other orchestrators to run multiple + // concurrent missions without port conflicts + const serverPort = process.env.OPENCODE_SERVER_PORT + ? parseInt(process.env.OPENCODE_SERVER_PORT, 10) + : undefined + const serverHostname = process.env.OPENCODE_SERVER_HOSTNAME || undefined + const { client, server } = await createOpencode({ signal: abortController.signal, + ...(serverPort && !isNaN(serverPort) ? { port: serverPort } : {}), + ...(serverHostname ? { hostname: serverHostname } : {}), }) const cleanup = () => {