Description
opencode attach constructs the Basic auth header by hardcoding the username as "opencode", regardless of the OPENCODE_SERVER_USERNAME environment variable.
In packages/opencode/src/cli/cmd/tui/attach.ts, the auth header is built as:
const auth = Basic ${Buffer.from(opencode:${password}`).toString("base64")}
By contrast, packages/opencode/src/cli/cmd/run.ts correctly reads the env var:
const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode"
This means opencode attach always authenticates as opencode even when the server requires a different username (e.g. when OPENCODE_SERVER_USERNAME is set). Authentication fails silently or produces an unhelpful error.
Plugins
No response
OpenCode version
1.2.27
Steps to reproduce
Run opencode serve (or connect to a remote server) with a non-default username configured via OPENCODE_SERVER_PASSWORD/OPENCODE_SERVER_USERNAME.
Set OPENCODE_SERVER_USERNAME=myuser and OPENCODE_SERVER_PASSWORD=mypassword in the client environment.
Run opencode attach.
Authentication fails — the wrong username (opencode) is sent instead of myuser.
Screenshot and/or share link
No response
Operating System
NixOS (x86_64-linux)
Terminal
wezterm
Description
opencode attach constructs the Basic auth header by hardcoding the username as "opencode", regardless of the OPENCODE_SERVER_USERNAME environment variable.
In packages/opencode/src/cli/cmd/tui/attach.ts, the auth header is built as:
const auth = Basic ${Buffer.from(opencode:${password}`).toString("base64")}
By contrast, packages/opencode/src/cli/cmd/run.ts correctly reads the env var:
const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode"
This means opencode attach always authenticates as opencode even when the server requires a different username (e.g. when OPENCODE_SERVER_USERNAME is set). Authentication fails silently or produces an unhelpful error.
Plugins
No response
OpenCode version
1.2.27
Steps to reproduce
Run opencode serve (or connect to a remote server) with a non-default username configured via OPENCODE_SERVER_PASSWORD/OPENCODE_SERVER_USERNAME.
Set OPENCODE_SERVER_USERNAME=myuser and OPENCODE_SERVER_PASSWORD=mypassword in the client environment.
Run opencode attach.
Authentication fails — the wrong username (opencode) is sent instead of myuser.
Screenshot and/or share link
No response
Operating System
NixOS (x86_64-linux)
Terminal
wezterm