feat(auth): Better multi-account gh account usage #13768#13781
Draft
platinummonkey wants to merge 2 commits into
Draft
feat(auth): Better multi-account gh account usage #13768#13781platinummonkey wants to merge 2 commits into
gh account usage #13768#13781platinummonkey wants to merge 2 commits into
Conversation
Automatically select which authenticated account gh acts as based on local, API-free context (working directory and base-repo owner) instead of the single global active account. This addresses cli#13768: multiple accounts on the same host (e.g. an EMU + a personal github.com identity) cannot be disambiguated by host, and `gh auth switch` mutates global state, which is unsafe for concurrent agents. New `account_rules` config key (gitdir + owner maps) and an explicit `--account` / `GH_ACCOUNT` override. Resolution wraps the HTTP client's token getter and never mutates persistent state. Token precedence: env token (GH_TOKEN etc.) > --account/GH_ACCOUNT > rules > globally active account. When no rules or override are configured, behavior is byte-identical to before. `gh auth status` now shows which account resolves for the current context, and GH_DEBUG traces resolution, so automatic switching is observable rather than silent. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
FIXES #13768
Automatically select which authenticated account
ghacts as based on local, API-free context (working directory and base-repo owner) instead of the single global active account. This addresses #13768: multiple accounts on the same host (e.g. an EMU + a personal github.com identity) cannot be disambiguated by host, andgh auth switchmutates global state, which is unsafe for concurrent agents.New
account_rulesconfig key (gitdir + owner maps) and an explicit--account/GH_ACCOUNToverride. Resolution wraps the HTTP client's token getter and never mutates persistent state.Token precedence: env token (
GH_TOKENetc.) >--account/GH_ACCOUNT> rules >globally active account. When no rules or override are configured, behavior is byte-identical to before.
gh auth statusnow shows which account resolves for the current context, and GH_DEBUG traces resolution, so automatic switching is observable rather than silent.