[PR #9095] fix(TUI): complete auth fix for TUI with server password (HTTP mode) #12977

Open
opened 2026-02-16 18:17:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9095

State: open
Merged: No


Summary

Completes the TUI authentication fix for when OPENCODE_SERVER_PASSWORD is set and TUI starts an HTTP server, due to the --port or '--hostname' flag being set.

Problem

PR #8179 fixed TUI authentication when using direct RPC communication, but didn't handle the case where TUI starts an HTTP server (when --port flag is used). In this scenario, the TUI would fail to authenticate against its own server.

Solution

  • Extracted getAuthorizationHeader() to a shared module packages/opencode/src/flag/auth.ts

  • Modified packages/opencode/src/cli/cmd/tui/thread.ts to use a custom fetch function that includes the Authorization header when an HTTP server is started with password protection

  • Modified packages/opencode/src/cli/cmd/tui/attach.ts to use a custom fetch function too (if needed)

  • Modified packages/opencode/src/plugin/index.ts to use a custom fetch function too (if needed)

  • The fix ensures the TUI can authenticate to the HTTP server it spawns when password is set. For plugins, the base TUI command itself and the attach TUI command.

Testing [Base TUI command]

Verified with:

OPENCODE_SERVER_PASSWORD="test" bun dev . --hostname 127.0.0.1 --port 4096

Previously this would fail with Unauthorized errors. Now the TUI successfully authenticates and works as expected.

Testing [Attach command]

Terminal 1 [start server process]:
OPENCODE_SERVER_PASSWORD="test" bun dev serve --hostname 127.0.0.1 --port 4096

Terminal 2 [attach TUI to existing server]:
OPENCODE_SERVER_PASSWORD="test" bun dev attach http://127.0.0.1:4096/

Previously this would fail with Unauthorized errors. Now the TUI successfully authenticates and works as expected.

Related

  • Completes #8179 (previous partial fix)
  • Fixes #8173 (original issue)
  • Fixes #9066 (same root issue)
  • Fixes #8676 (duplicate issue)
  • Fixes #8458 (same root cause)
  • Fixes #10166 (duplicate issue)

This PR completes the authentication flow that was partially addressed in #8179. The previous PR only fixed the RPC communication path, while this PR fixes the HTTP server path.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9095 **State:** open **Merged:** No --- ## Summary Completes the TUI authentication fix for when `OPENCODE_SERVER_PASSWORD` is set and TUI starts an HTTP server, due to the `--port` or '--hostname' flag being set. ## Problem PR #8179 fixed TUI authentication when using direct RPC communication, but didn't handle the case where TUI starts an HTTP server (when `--port` flag is used). In this scenario, the TUI would fail to authenticate against its own server. ## Solution - Extracted `getAuthorizationHeader()` to a shared module `packages/opencode/src/flag/auth.ts` - Modified `packages/opencode/src/cli/cmd/tui/thread.ts` to use a custom fetch function that includes the Authorization header when an HTTP server is started with password protection - Modified `packages/opencode/src/cli/cmd/tui/attach.ts` to use a custom fetch function too (if needed) - Modified `packages/opencode/src/plugin/index.ts` to use a custom fetch function too (if needed) - The fix ensures the TUI can authenticate to the HTTP server it spawns when password is set. For plugins, the base TUI command itself and the attach TUI command. ## Testing [Base TUI command] Verified with: ```bash OPENCODE_SERVER_PASSWORD="test" bun dev . --hostname 127.0.0.1 --port 4096 ``` Previously this would fail with `Unauthorized` errors. Now the TUI successfully authenticates and works as expected. ## Testing [Attach command] Terminal 1 [start server process]: OPENCODE_SERVER_PASSWORD="test" bun dev serve --hostname 127.0.0.1 --port 4096 Terminal 2 [attach TUI to existing server]: OPENCODE_SERVER_PASSWORD="test" bun dev attach http://127.0.0.1:4096/ Previously this would fail with `Unauthorized` errors. Now the TUI successfully authenticates and works as expected. ## Related - Completes #8179 (previous partial fix) - Fixes #8173 (original issue) - Fixes #9066 (same root issue) - Fixes #8676 (duplicate issue) - Fixes #8458 (same root cause) - Fixes #10166 (duplicate issue) This PR completes the authentication flow that was partially addressed in #8179. The previous PR only fixed the RPC communication path, while this PR fixes the HTTP server path.
yindo added the pull-request label 2026-02-16 18:17:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12977