Detect the authenticated GitHub username via the gh CLI.
Runs gh api user --jq '.login' asynchronously and validates the result
against GitHub's username rules. Never throws — returns null on any failure
(gh not installed, not authenticated, invalid output, etc.).
Returns Promise<string|null>
The GitHub username string, or null if detection fails
Example
constusername = awaitdetectGitHubUsername(); if (username) { console.log(`Logged in as ${username}`); }
Detect the authenticated GitHub username via the
ghCLI.Runs
gh api user --jq '.login'asynchronously and validates the result against GitHub's username rules. Never throws — returnsnullon any failure (gh not installed, not authenticated, invalid output, etc.).