Skip to content

fix: open web UI to cwd-encoded URL so initial directory is correct#16577

Open
Jrc356 wants to merge 3 commits intoanomalyco:devfrom
Jrc356:fix/web-cwd
Open

fix: open web UI to cwd-encoded URL so initial directory is correct#16577
Jrc356 wants to merge 3 commits intoanomalyco:devfrom
Jrc356:fix/web-cwd

Conversation

@Jrc356
Copy link

@Jrc356 Jrc356 commented Mar 8, 2026

Issue for this PR

Closes #6336

Type of change

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

What does this PR do?

Updates the WebCommand in the CLI to open at cwd

How did you verify your code works?

I have opencode 1.2.21 installed in my path, opening a project using opencode web --hostname 0.0.0.0 appears to open at root

without --hostname it does open to cwd

with this PR's changes I used

bun dev web

which opened at cwd and then tried

bun dev web --hostname 0.0.0.0

which also opened at cwd!

Checklist

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

If you do not follow this template your PR will be automatically rejected.

Jrc356 added 3 commits March 8, 2026 03:28
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/<base64dir>). 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.
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.

opencode web - thinks it is in root (/) path

1 participant