Skip to content

opencode attach ignores OPENCODE_SERVER_USERNAME, hardcodes "opencode" #18611

@ChrisOboe

Description

@ChrisOboe

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions