anomalyco / anomalyco/opencode

Web client fails to fetch when URL contains credentials and throws BrowserAttachments context error

Open
#49,086 0 comments 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Sep 15, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

When accessing the OpenCode web client with HTTP basic authentication credentials in the URL (for example http://username:password@127.0.0.1:<port>/), two issues occur:

  1. fetch() throws:
TypeError: Failed to execute 'fetch' on 'Window': Request cannot be constructed from a URL that includes credentials

Because clearAuthToken() in packages/app/src/entry.tsx only handles ?auth_token= query parameters and uses a relative path in history.replaceState(), any credentials present in location.username and location.password remain in window.location. Under modern WHATWG Fetch specifications, browsers reject any request constructed from a URL with embedded credentials. Additionally, embedded credentials in the URL are not extracted into auth, causing requests to fail with 401.

  1. If a session or route is loaded where BrowserAttachmentsProvider is not active (or outside desktop context), useBrowserAttachments() unconditionally throws:
Error: BrowserAttachments context must be used within a context provider

instead of falling back to a disabled/no-op attachment state on Web.

Steps to reproduce
  1. Run OPENCODE_SERVER_PASSWORD=secret opencode serve (or opencode web).
  2. Open http://opencode:secret@127.0.0.1:4096/ directly in Google Chrome or Safari.
  3. Observe TypeError: Failed to execute 'fetch' on 'Window' and/or Error: BrowserAttachments context must be used within a context provider.
OpenCode version

v2.0.3

Operating System

macOS / Linux / Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.