From f0584c223f73e5fc579da36884b595c91abcfa94 Mon Sep 17 00:00:00 2001 From: Jon Corbin Date: Sun, 8 Mar 2026 03:28:21 -0400 Subject: [PATCH 1/2] fix: open web UI to cwd-encoded URL so initial directory is correct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The web command was opening the browser to a bare URL (e.g. http://localhost:4096/) with no directory context. The server middleware falls back to process.cwd() when neither the x-opencode-directory header nor the directory query param are present, but that only works correctly for the server process itself — the browser-side frontend had no way to know which directory was intended, and on some setups cwd resolves to /. Fix: encode process.cwd() as a URL-safe base64 segment and append it to the initial URL that is opened in the browser (e.g. http://localhost:4096/). The frontend router already parses this segment via DirectoryLayout and includes the directory in all subsequent API calls via the x-opencode-directory header, so the server now receives the correct context from the very first request. --- packages/opencode/src/cli/cmd/web.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/opencode/src/cli/cmd/web.ts b/packages/opencode/src/cli/cmd/web.ts index 0fe056f21f2f..b52bddfd9439 100644 --- a/packages/opencode/src/cli/cmd/web.ts +++ b/packages/opencode/src/cli/cmd/web.ts @@ -5,6 +5,7 @@ import { withNetworkOptions, resolveNetworkOptions } from "../network" import { Flag } from "../../flag/flag" import open from "open" import { networkInterfaces } from "os" +import { base64Encode } from "@opencode-ai/util/encode" function getNetworkIPs() { const nets = networkInterfaces() @@ -38,13 +39,14 @@ export const WebCommand = cmd({ } const opts = await resolveNetworkOptions(args) const server = Server.listen(opts) + const dir = base64Encode(process.cwd()) UI.empty() UI.println(UI.logo(" ")) UI.empty() if (opts.hostname === "0.0.0.0") { // Show localhost for local access - const localhostUrl = `http://localhost:${server.port}` + const localhostUrl = `http://localhost:${server.port}/${dir}` UI.println(UI.Style.TEXT_INFO_BOLD + " Local access: ", UI.Style.TEXT_NORMAL, localhostUrl) // Show network IPs for remote access @@ -54,7 +56,7 @@ export const WebCommand = cmd({ UI.println( UI.Style.TEXT_INFO_BOLD + " Network access: ", UI.Style.TEXT_NORMAL, - `http://${ip}:${server.port}`, + `http://${ip}:${server.port}/${dir}`, ) } } @@ -70,7 +72,7 @@ export const WebCommand = cmd({ // Open localhost in browser open(localhostUrl.toString()).catch(() => {}) } else { - const displayUrl = server.url.toString() + const displayUrl = `${server.url.toString()}${dir}` UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, displayUrl) open(displayUrl).catch(() => {}) } From 639c2561ccd89353859411e308a45983a5a8a1fc Mon Sep 17 00:00:00 2001 From: Jon Corbin Date: Sun, 8 Mar 2026 04:05:03 -0400 Subject: [PATCH 2/2] add dir to mdns path --- packages/opencode/src/cli/cmd/web.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opencode/src/cli/cmd/web.ts b/packages/opencode/src/cli/cmd/web.ts index b52bddfd9439..d47d73df6541 100644 --- a/packages/opencode/src/cli/cmd/web.ts +++ b/packages/opencode/src/cli/cmd/web.ts @@ -65,7 +65,7 @@ export const WebCommand = cmd({ UI.println( UI.Style.TEXT_INFO_BOLD + " mDNS: ", UI.Style.TEXT_NORMAL, - `${opts.mdnsDomain}:${server.port}`, + `${opts.mdnsDomain}:${server.port}/${dir}`, ) }