Repository navigation
Keychain lookup ignores account field, breaks multi-account setups #12885
Description
Activity
Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.
Unless you see the help wanted
Contributions welcome label, we are not currently looking for external contributions for this feature.If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.
- added a commit that references this issue
on Apr 9, 2026 I've traced this to TokenFromKeyring in internal/keyring/keyring.go — it looks up by service only (gh:github.com), so when multiple accounts share the same host, macOS Keychain returns an arbitrary entry. TokenFromKeyringForUser already does the correct per-user lookup, but ActiveToken only calls it after resolving the globally active user, so the account field is effectively ignored.
I've implemented a fix in cli/cli#13130 that approaches this from the usage side: a new
gh auth set-user --owner <org> <username>command stores an owner→user mapping in hosts.yml, and httpClientFunc in the factory resolves the repo owner from the git remote and selects the correct authenticated user before making any API call. No signature changes to tokenGetter or AddAuthTokenHeader, falls back gracefully to the globally active user when no mapping exists.All existing tests pass and new table-driven tests cover the owner mapping behaviour.
Would the maintainers be open to adding help_wanted to this issue? The bot will auto-close my PR in 7 days without it, and I think this is a real pain point for anyone using gh across multiple accounts on the same machine.Reacted by Veesh- added 5 commits that reference this issue
on Apr 19, 2026 - added a commit that references this issue
on May 11, 2026 - added a commit that references this issue
on May 18, 2026 - added a commit that references this issue
on May 25, 2026 - added 3 commits that reference this issue
on Aug 13, 2026 - added a commit that references this issue
on Aug 24, 2026 - added a commit that references this issue
on Aug 31, 2026 - added a commit that references this issue
on Sep 19, 2026 - added a commit that references this issue
on Sep 28, 2026 - added a commit that references this issue
on Oct 5, 2026
Description
When two GitHub accounts are configured for the same host (
github.com) usingGH_CONFIG_DIRto separate configs,gh auth tokenretrieves the wrong token because the keychain lookup doesn't include the account name.Steps to reproduce
security:gh auth tokenreturns the wrong token for one of the configs:Root cause
The keychain lookup appears to query by service name only (
gh:github.com) without passing the account field. macOS Keychain returns an arbitrary entry when multiple entries share the same service name.gh auth statusreads the username fromhosts.yml(correct), but the actual token retrieval doesn't use it as a filter.Workaround
Read the keychain entry directly with the correct account and set
GH_TOKEN:Expected behavior
gh auth token(and all commands that retrieve the token) should pass the account name fromhosts.ymlto the keychain lookup, so that multiple accounts for the same host can coexist.Environment