Summary
The docs promise that the basic-auth username for serve/web can be overridden with OPENCODE_SERVER_USERNAME (default opencode). In this v2 codebase nothing reads that variable: the username is hardcoded to opencode on both the server and client sides, so setting the variable silently does nothing. A test even sets it, which makes the dead variable look supported.
Evidence (all on main 2d302d6718)
Docs promising the override:
packages/web/src/content/docs/server.mdx:39 — "The username defaults to opencode, or set OPENCODE_SERVER_USERNAME to override it. This applies to both opencode serve and opencode web."
packages/web/src/content/docs/web.mdx:89 — "The username defaults to opencode but can be changed with OPENCODE_SERVER_USERNAME."
packages/web/src/content/docs/cli.mdx:702 — env table: "OPENCODE_SERVER_USERNAME | Override basic auth username (default opencode)".
packages/web/src/content/docs/cli.mdx:126 and :378 — --username/-u flag rows: "Basic auth username (defaults to OPENCODE_SERVER_USERNAME or opencode)" (no such flag exists in packages/cli/src/commands/commands.ts).
Code hardcoding opencode and never reading the variable:
packages/server/src/auth.ts:19-21 — Config.configLayer accepts only a password and forces username: "opencode"; authorized() (line ~31) rejects any other username.
packages/server/src/process.ts:233 — ServerAuth.Config.of({ password: ..., username: "opencode" }).
packages/cli/src/env.ts:3-13 — the module that declares itself "Every environment variable the CLI reads, in one place" defines password (OPENCODE_PASSWORD / OPENCODE_SERVER_PASSWORD) and no username.
packages/cli/src/services/server-connection.ts:28 — client auth for an explicit --server hardcodes username: "opencode", so this CLI also cannot authenticate to a server that expects a different username.
packages/cli/src/services/standalone.ts:53 — standalone server auth hardcodes username: "opencode".
- Repo-wide grep:
OPENCODE_SERVER_USERNAME appears only in docs/translations and in packages/cli/test/standalone.test.ts:11, which sets it to "custom" and then asserts only HTTP 200 — the variable has no effect on the run, so the test gives false confidence that it is honored.
Corroboration that the fixed username is the deliberate v2 behavior: developing-today/openchamber packages/vscode/src/opencode.ts:95 comments "OpenCode 2 accepts only the opencode username; OPENCODE_SERVER_USERNAME is ignored." (The variable was a v1 feature; the docs are v1 leftovers.)
Why it matters
A user who follows the docs and sets OPENCODE_SERVER_USERNAME gets no error and no effect — the exact silent-failure shape that erodes trust in a security setting. Either the setting should work, or the docs and the misleading test should stop claiming it does.
Acceptance criteria
Pick one direction and apply it consistently:
- Implement it: read
OPENCODE_SERVER_USERNAME in packages/cli/src/env.ts, thread it through the server auth config (packages/server/src/auth.ts / process.ts), the standalone service, and the --server client auth; add a test that a non-default username actually authenticates and the default one fails (and vice versa). Or:
- Align docs and test with the deliberate v2 behavior: remove the override claims from
server.mdx, web.mdx, and cli.mdx (env table and the --username rows), state plainly that the username is always opencode, and drop the unused OPENCODE_SERVER_USERNAME from packages/cli/test/standalone.test.ts.
Either way, a grep for OPENCODE_SERVER_USERNAME afterwards should find it only where it is genuinely honored (direction 1) or nowhere outside a "v1 removed" note (direction 2).