LinuxmacOSWindows

Where Does the GitHub CLI Store Logins?

Where the gh CLI keeps hosts.yml logins and config.yml on each OS, and the variable that moves them.

Last updated

The gh CLI stores authentication in hosts.yml and preferences in config.yml, together in one directory: ~/.config/gh on Linux and macOS, %APPDATA%\GitHub CLI on Windows. Each host gets a section with its token and protocol choice.

Tokens in that file are secrets with a path attached, so treat copies like passwords. GH_CONFIG_DIR relocates the whole directory for isolated environments, and gh auth commands edit the files safely where hand edits risk YAML indentation faults.

Where GitHub CLI stores this, by platform

Linux
~/.config/gh/hosts.yml

Respects $XDG_CONFIG_HOME. hosts.yml holds per host tokens, config.yml holds aliases and behavior. Override with GH_CONFIG_DIR. Inspect with gh auth status and gh config list.

macOS
~/.config/gh/hosts.yml

Same files and commands as Linux. Keychain entries may supplement the file on newer builds; gh auth status shows the effective state.

Windows
%APPDATA%\GitHub CLI\hosts.yml

Paste %APPDATA%\GitHub CLI into Explorer. Same hosts.yml/config.yml pair and GH_CONFIG_DIR override as other platforms.

Frequently asked questions

Which accounts am I logged into?

Run gh auth status. It lists logged in accounts per host and which token each uses, without exposing secrets. Re login with gh auth login when a token expires; the file updates in place.

Can I copy gh config to another machine?

Yes for hosts and aliases, carefully for tokens. gh auth refresh regenerates tokens in place, which beats copying stale ones. Environment variable auth (GH_TOKEN) overrides the file entirely and never touches it.

Notice an outdated path? Let us know.