Skip to content

fix(cli): add OAuth copy-url fallback when browser open fails#173

Open
RocketBoyMusic wants to merge 1 commit intodavis7dotsh:mainfrom
RocketBoyMusic:fix/windows-oauth-copy-url-fallback
Open

fix(cli): add OAuth copy-url fallback when browser open fails#173
RocketBoyMusic wants to merge 1 commit intodavis7dotsh:mainfrom
RocketBoyMusic:fix/windows-oauth-copy-url-fallback

Conversation

@RocketBoyMusic
Copy link

@RocketBoyMusic RocketBoyMusic commented Feb 7, 2026

Summary

On Windows, OAuth browser auto-open can fail on some setups, which leaves users stuck in the TUI flow.

This PR adds a manual fallback path so users can copy the authorization URL and continue authentication without restarting.

Changes

  • Adds browser-open failure handling to OpenAI OAuth login:
    • Captures non-zero exits from platform open commands (open, cmd /c start, xdg-open).
    • Exposes optional callbacks for auth URL and browser-open failure.
    • Continues OAuth flow by default when browser auto-open fails.
  • Updates Connect Wizard auth step:
    • Stores fallback OAuth URL when browser open fails.
    • Shows clear status guidance in auth step.
    • Adds c key shortcut in auth step to copy URL to clipboard.
    • Shows success/error feedback for clipboard copy.

Why

This keeps OAuth usable on Windows environments where browser launch is unreliable, while preserving current behavior on systems where browser open works.

Validation

  • bun run --cwd apps/cli check

Greptile Overview

Greptile Summary

This PR improves the CLI OAuth flow by detecting failures to auto-open the authorization URL (notably on Windows) and exposing hooks so the TUI can present a manual fallback.

On the library side (apps/cli/src/lib/opencode-oauth.ts), the OAuth login now reports the auth URL and browser-open failures via optional callbacks while continuing the underlying OAuth polling/verification.

On the TUI side (apps/cli/src/tui/components/connect-wizard.tsx), the connect wizard stores the fallback URL, shows user guidance, and adds a c shortcut to copy the URL to the clipboard.

One issue to address before merge: the new c key handler can still fire when there is no fallback URL (browser open succeeded), which can crash or behave incorrectly when attempting to copy a null URL.

Confidence Score: 3/5

  • This PR is close to safe to merge, but has a user-facing crash path in the TUI auth step that should be fixed first.
  • Core OAuth fallback behavior in the library looks consistent with existing flow (continue on open failure), but the connect wizard’s new clipboard shortcut does not guard against a missing fallback URL, which can break the auth step even when auto-open works.
  • apps/cli/src/tui/components/connect-wizard.tsx

Important Files Changed

Filename Overview
apps/cli/src/lib/opencode-oauth.ts Adds optional callbacks to surface the OAuth authorization URL and handle browser-open failures, while continuing the OAuth flow when auto-open fails.
apps/cli/src/tui/components/connect-wizard.tsx Adds TUI fallback UX for OAuth URL copying, but the new auth-step key handler can crash when no fallback URL is available.

Context used:

  • Context from dashboard - AGENTS.md (source)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 7, 2026

Additional Comments (1)

apps/cli/src/tui/components/connect-wizard.tsx
Null URL key crash
If the OAuth browser auto-open succeeds, oauthFallbackUrl stays null, but the new c key handler still runs copy(oauthFallbackUrl) and then does setAuthStepStatus(...) in the callback. Passing null to the clipboard helper will throw (or at least copy the string "null"), which can break the auth step even though the primary flow is working. Guard the handler (and the UI hint) behind oauthFallbackUrl != null, or early-return with a friendly message when it’s absent.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/tui/components/connect-wizard.tsx
Line: 426:428

Comment:
**Null URL key crash**
If the OAuth browser auto-open succeeds, `oauthFallbackUrl` stays `null`, but the new `c` key handler still runs `copy(oauthFallbackUrl)` and then does `setAuthStepStatus(...)` in the callback. Passing `null` to the clipboard helper will throw (or at least copy the string `"null"`), which can break the auth step even though the primary flow is working. Guard the handler (and the UI hint) behind `oauthFallbackUrl != null`, or early-return with a friendly message when it’s absent.

How can I resolve this? If you propose a fix, please make it concise.

@RocketBoyMusic
Copy link
Author

Okay, I double checked this path and we do guard it before copy:

const url = oauthFallbackUrl();
if (!url) return;

So copyToClipboard only runs when a fallback URL exists in the auth step. So I don't see any problem personally, luckily :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments