feat(auth): improve Windows browser opening with fallback methods
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
-
New
WindowsUtilsmodule (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) -
explorercommand (backup method)
-
- User-friendly error messages with actionable guidance
-
Enhanced authentication (
src/cli/cmd/auth.ts):- Replaced direct
open()calls with smartsafeOpenUrl()function - Automatic fallback through multiple Windows-native methods
- Clear error messages when all methods fail
- Replaced direct
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
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.