Add fallback to manual URL paste when browser cannot open#66
Merged
Conversation
On headless Linux environments (e.g. remote servers, containers, CI), the OAuth login flow fails because there's no browser to open and localhost may not be reachable from the user's machine. The new --headless flag prints the authorization URL for the user to copy to any browser, then accepts the pasted callback URL to extract the authorization code. The callback server still runs as a fallback in case localhost is reachable. https://claude.ai/code/session_01XP5tu7h6nuEAaavYWQab6q
… login Instead of a separate --headless flag, the login flow now automatically detects when the browser cannot be opened and falls back to prompting the user to paste the callback URL from their browser. This handles headless environments (remote servers, containers) without requiring any extra flags. https://claude.ai/code/session_01XP5tu7h6nuEAaavYWQab6q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enhanced the OAuth flow to gracefully handle environments where a browser cannot be automatically opened (e.g., headless servers, containers). When browser launch fails, users can now manually paste the callback URL instead of the flow failing entirely.
Key Changes
openBrowser()totryOpenBrowser()and changed it to return a boolean indicating success/failure instead of throwing an errorextractCodeFromUrl()function to parse authorization codes and state from callback URLs, with proper error handling for malformed URLs and OAuth errorspromptForCallbackUrl()function to interactively prompt users to paste the callback URL using readline (compatible with all terminal environments)performOAuthFlow()to detect browser launch failures and fall back to URL paste modeImplementation Details
Promise.race()to allow either the callback server or manual URL paste to complete the flowhttps://claude.ai/code/session_01XP5tu7h6nuEAaavYWQab6q