opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(auth): improve Windows browser opening with fallback methods

Open Haadka opened this issue 5 months ago • 1 comments

Problem

Fixes #1103

On Windows, antivirus software can block or delete PowerShell execution during authentication flows, causing browser opening to fail completely. This particularly affects Claude Pro/Max authentication where automatic browser opening is required for OAuth flows.

Solution

This PR adds smart Windows-specific fallback methods for opening URLs safely:

Changes Made

  1. New WindowsUtils module (src/util/windows.ts):

    • Platform detection for Windows-specific handling
    • Multiple fallback methods for opening URLs:
      • start "" command (cleanest approach)
      • rundll32 url.dll,FileProtocolHandler (Windows native)
      • explorer command (backup method)
    • User-friendly error messages with actionable guidance
  2. Enhanced authentication (src/cli/cmd/auth.ts):

    • Replaced direct open() calls with smart safeOpenUrl() function
    • Automatic fallback through multiple Windows-native methods
    • Clear error messages when all methods fail

Benefits

  • Resolves authentication failures on Windows due to antivirus blocking
  • Graceful degradation - tries multiple methods before giving manual instructions
  • Better user experience - helpful error messages instead of cryptic failures
  • No breaking changes - maintains existing behavior on non-Windows platforms

Testing

I've reproduced the original issue locally on Windows and confirmed these changes resolve the authentication blocking issue.

Files Changed

  • packages/opencode/src/util/windows.ts - New Windows utilities module
  • packages/opencode/src/cli/cmd/auth.ts - Enhanced authentication with fallbacks

Haadka avatar Aug 07 '25 13:08 Haadka

A fallback would be helpful for WSL setups too, not just Windows. Allowing a link to be presented is necessary for WSL since the linux side could never open a browser window on the Windows side.

mattlgroff avatar Aug 08 '25 16:08 mattlgroff