>_ ghcli.com
ghcli / Auth & Config / gh auth token

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.

Quick answer
gh auth token

Syntax

gh auth token [flags]

Examples

Print the active token

gh auth token

Export it into an environment variable

export GH_TOKEN=$(gh auth token)

Token for a specific host

gh auth token --hostname github.example.com

Log in to a container registry with it

gh auth token | docker login ghcr.io -u USERNAME --password-stdin

Options & flags

FlagWhat it does
-h, --hostnamePrint the token for a specific host.
-u, --userPrint the token for a specific account on the host.

How to use gh auth token, step by step

  1. Make sure you're signed in with gh auth status.
  2. Run gh auth token to print the token.
  3. Pipe it into a tool or capture it with $(gh auth token).
  4. 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.