feat(attach): Add --username flag for custom basic auth username #8542

Closed
opened 2026-02-16 18:10:14 -05:00 by yindo · 4 comments
Owner

Originally created by @li-zane on GitHub (Feb 4, 2026).

Originally assigned to: @thdxr on GitHub.

Description

Currently, opencode attach only supports the -p, --password flag for basic auth, and the username is hardcoded to opencode. This prevents users from connecting to servers configured with a custom OPENCODE_SERVER_USERNAME.

Current Behavior

When running a web server with a custom username:

OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode web

There's no way to attach with the custom username:

# This fails with "Unauthorized" because username defaults to "opencode"
opencode attach http://localhost:4096 -p secret

# Environment variable doesn't work either
OPENCODE_SERVER_USERNAME=myuser opencode attach http://localhost:4096 -p secret

Expected Behavior

Add a -u, --username flag (defaulting to opencode for backward compatibility):

opencode attach http://localhost:4096 -u myuser -p secret

Or support OPENCODE_SERVER_USERNAME environment variable in the attach command.

Additional Context

Using the default username opencode reduces security since attackers only need to guess the password. Custom usernames add an extra layer of protection.

Originally created by @li-zane on GitHub (Feb 4, 2026). Originally assigned to: @thdxr on GitHub. ## Description Currently, `opencode attach` only supports the `-p, --password` flag for basic auth, and the username is hardcoded to `opencode`. This prevents users from connecting to servers configured with a custom `OPENCODE_SERVER_USERNAME`. ## Current Behavior When running a web server with a custom username: ```bash OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode web ``` There's no way to attach with the custom username: ```bash # This fails with "Unauthorized" because username defaults to "opencode" opencode attach http://localhost:4096 -p secret # Environment variable doesn't work either OPENCODE_SERVER_USERNAME=myuser opencode attach http://localhost:4096 -p secret ``` ## Expected Behavior Add a `-u, --username` flag (defaulting to `opencode` for backward compatibility): ```bash opencode attach http://localhost:4096 -u myuser -p secret ``` Or support `OPENCODE_SERVER_USERNAME` environment variable in the attach command. ## Additional Context Using the default username `opencode` reduces security since attackers only need to guess the password. Custom usernames add an extra layer of protection.
yindo closed this issue 2026-02-16 18:10:14 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 4, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8458: [FEATURE]: Attach to authenticated OC Server (parent feature request)
  • #9011: Cannot 'attach' to an opencode server with a password (directly related bug)
  • #8676: fix: Plugin client returns 401 Unauthorized when OPENCODE_SERVER_PASSWORD is set (mentions OPENCODE_SERVER_USERNAME support)
  • #9706: [BUG] Plugin client missing Authorization header when OPENCODE_SERVER_PASSWORD is set
  • #9066: Failing to authenticate into web UI when username or password is set
  • #12118: [FEATURE]: Support for dynamic auth prompts and CLI login improvements

Feel free to ignore if this specific implementation detail addresses a unique case not covered by these issues.

@github-actions[bot] commented on GitHub (Feb 4, 2026): This issue might be a duplicate of existing issues. Please check: - #8458: [FEATURE]: Attach to authenticated OC Server (parent feature request) - #9011: Cannot 'attach' to an opencode server with a password (directly related bug) - #8676: fix: Plugin client returns 401 Unauthorized when OPENCODE_SERVER_PASSWORD is set (mentions OPENCODE_SERVER_USERNAME support) - #9706: [BUG] Plugin client missing Authorization header when OPENCODE_SERVER_PASSWORD is set - #9066: Failing to authenticate into web UI when username or password is set - #12118: [FEATURE]: Support for dynamic auth prompts and CLI login improvements Feel free to ignore if this specific implementation detail addresses a unique case not covered by these issues.
Author
Owner

@R44VC0RP commented on GitHub (Feb 4, 2026):

Thanks for the detailed report @li-zane! You're right that there's a mismatch - the server supports custom usernames via OPENCODE_SERVER_USERNAME, but the attach command hardcodes it to "opencode".

Good news: PR #9095 addresses this by adding OPENCODE_SERVER_USERNAME environment variable support to the attach command. Once merged, you'll be able to:

OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode attach http://localhost:4096

The PR has been open since Jan 17 and is ready for review. I'll flag it for prioritization.

Regarding the -u, --username CLI flag you suggested - that's not included in #9095 (which focuses on env var support). If you'd still like a CLI flag after #9095 is merged, feel free to open a follow-up issue or PR for that enhancement.

Closing this as a duplicate of the work being done in #9095.

@R44VC0RP commented on GitHub (Feb 4, 2026): Thanks for the detailed report @li-zane! You're right that there's a mismatch - the server supports custom usernames via `OPENCODE_SERVER_USERNAME`, but the attach command hardcodes it to `"opencode"`. Good news: **PR #9095** addresses this by adding `OPENCODE_SERVER_USERNAME` environment variable support to the attach command. Once merged, you'll be able to: ```bash OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode attach http://localhost:4096 ``` The PR has been open since Jan 17 and is ready for review. I'll flag it for prioritization. Regarding the `-u, --username` CLI flag you suggested - that's not included in #9095 (which focuses on env var support). If you'd still like a CLI flag after #9095 is merged, feel free to open a follow-up issue or PR for that enhancement. Closing this as a duplicate of the work being done in #9095.
Author
Owner

@R44VC0RP commented on GitHub (Feb 4, 2026):

Duplicate of #9095

@R44VC0RP commented on GitHub (Feb 4, 2026): Duplicate of #9095
Author
Owner

@LeonMueller-OneAndOnly commented on GitHub (Feb 5, 2026):

Thanks for the detailed report @li-zane! You're right that there's a mismatch - the server supports custom usernames via OPENCODE_SERVER_USERNAME, but the attach command hardcodes it to "opencode".

Good news: PR #9095 addresses this by adding OPENCODE_SERVER_USERNAME environment variable support to the attach command. Once merged, you'll be able to:

OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode attach http://localhost:4096

The PR has been open since Jan 17 and is ready for review. I'll flag it for prioritization.

Regarding the -u, --username CLI flag you suggested - that's not included in #9095 (which focuses on env var support). If you'd still like a CLI flag after #9095 is merged, feel free to open a follow-up issue or PR for that enhancement.

Closing this as a duplicate of the work being done in #9095.

I added the support for the username flag to the attach command. The implementation is straight forward and makes a cleaner PR altogether

@LeonMueller-OneAndOnly commented on GitHub (Feb 5, 2026): > Thanks for the detailed report [@li-zane](https://github.com/li-zane)! You're right that there's a mismatch - the server supports custom usernames via `OPENCODE_SERVER_USERNAME`, but the attach command hardcodes it to `"opencode"`. > > Good news: **PR [#9095](https://github.com/anomalyco/opencode/pull/9095)** addresses this by adding `OPENCODE_SERVER_USERNAME` environment variable support to the attach command. Once merged, you'll be able to: > > OPENCODE_SERVER_USERNAME=myuser OPENCODE_SERVER_PASSWORD=secret opencode attach http://localhost:4096 > > The PR has been open since Jan 17 and is ready for review. I'll flag it for prioritization. > > Regarding the `-u, --username` CLI flag you suggested - that's not included in [#9095](https://github.com/anomalyco/opencode/pull/9095) (which focuses on env var support). If you'd still like a CLI flag after [#9095](https://github.com/anomalyco/opencode/pull/9095) is merged, feel free to open a follow-up issue or PR for that enhancement. > > Closing this as a duplicate of the work being done in [#9095](https://github.com/anomalyco/opencode/pull/9095). I added the support for the username flag to the attach command. The implementation is straight forward and makes a cleaner PR altogether
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8542