gh auth token
Get the token for scripts and other tools
gh auth token prints the authentication token gh is currently using. Feed it to other tools, curl, or Docker logins that expect a GitHub token — reusing gh's login instead of managing a separate personal access token.
gh auth tokenSyntax
gh auth token [flags]Examples
Print the active token
gh auth tokenExport it into an environment variable
export GH_TOKEN=$(gh auth token)Token for a specific host
gh auth token --hostname github.example.comLog in to a container registry with it
gh auth token | docker login ghcr.io -u USERNAME --password-stdinOptions & flags
| Flag | What it does |
|---|---|
| -h, --hostname | Print the token for a specific host. |
| -u, --user | Print the token for a specific account on the host. |
How to use gh auth token, step by step
- Make sure you're signed in with
gh auth status. - Run
gh auth tokento print the token. - Pipe it into a tool or capture it with
$(gh auth token). - Never paste the token into shared logs or commit it to a repo.
Common errors and fixes
no oauth token found for github.com
You're not logged in on that host, or logged in a different way. Run gh auth login, then try again.
Related commands
Frequently asked questions
How do I get my GitHub token from the CLI?
Run gh auth token. It prints the token gh is currently authenticated with, which you can capture in a script as $(gh auth token).
Can I use gh auth token in CI or with other tools?
Yes. Common uses include export GH_TOKEN=$(gh auth token) and piping it into docker login ghcr.io --password-stdin. Treat the value as a secret.
How do I get the token for a GitHub Enterprise host?
Add --hostname: gh auth token --hostname github.example.com prints the token for that server.