Skip to content

feat(auth): Better multi-account gh account usage #13768#13781

Draft
platinummonkey wants to merge 2 commits into
cli:trunkfrom
platinummonkey:feature/context-scoped-accounts
Draft

feat(auth): Better multi-account gh account usage #13768#13781
platinummonkey wants to merge 2 commits into
cli:trunkfrom
platinummonkey:feature/context-scoped-accounts

Conversation

@platinummonkey

Copy link
Copy Markdown

FIXES #13768

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 #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.

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]>
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better multi-account gh account usage

1 participant