Skip to content

Get started

This page takes you from installation to a first authenticated clone and a first exec command on a workstation with an OS keyring.

  • The GitHub CLI 2.45 or newer and Git 2.30 or newer.
  • An authenticated GitHub CLI session that can download the extension (gh auth login, or a suitable GH_TOKEN). This installer identity is separate from the GitHub App you configure later.
  • A GitHub App already installed on the organization that owns your repository, with access to that repository and Contents: read, plus the App’s Client ID (for example Iv1.…) and a downloaded .pem private key.
  • A workstation with an OS keyring. On a headless machine or in a pipeline, use the CI guide. To use a personal access token instead of an App, see Personal access tokens.

Creating or installing a GitHub App and generating its key can require organization owner or App manager rights; see Manage credentials for the roles and permissions. If you cannot do these yourself, ask an administrator to install the App, and obtain the Client ID and key through your organization’s approved access or secret-sharing procedure. Never send a private key over chat or email.

This walkthrough uses one GitHub App and no PATs, because when an App and a PAT both match a repository the helper compares them by priority, which changes which credential is chosen.

Terminal window
gh extension install AmadeusITGroup/gh-app-auth

gh installs the precompiled binary for your platform from the latest release. Upgrade an unpinned install with gh extension upgrade app-auth, and see what is installed with gh extension list. Do not use gh app-auth --version to identify the release; it is not reliable. To stay on a specific release, add --pin <release-tag>, for example --pin v0.2.0, and choose and test the release you want.

Go is not needed to use the extension. Release packages and assets are described in the release runbook, building from source is in development, and shell completion is generated by completion.

Every value below is a placeholder. Replace it with your own.

Placeholder Meaning
Iv1.example Client ID of your GitHub App
$HOME/keys/example-app.pem Path to the private key file you downloaded
github.com/example-org/ Host and organization that the App covers
Example App A friendly name shown in list output
example-org/private-repo A private repository the App can read

The key file must not be readable by other users. On Linux and macOS:

Terminal window
chmod 600 "$HOME/keys/example-app.pem"

chmod does not apply on Windows, where file permissions are set through ACLs. The permission check that gh-app-auth performs on key files is skipped on Windows, so protecting the file is your responsibility there.

Terminal window
gh app-auth setup \
--client-id Iv1.example \
--key-file "$HOME/keys/example-app.pem" \
--patterns 'github.com/example-org/' \
--name 'Example App'

--client-id is preferred. --app-id with the numeric App ID also works. By default the key is stored in the OS keyring. Passing the key through the GH_APP_PRIVATE_KEY environment variable instead of --key-file changes how you supply it, not where it is stored: it is still persisted by gh-app-auth.

On a headless machine without an OS keyring, add --use-filesystem together with --key-file. That is the reliable route there. Do not count on setup falling back to the filesystem by itself: that automatic fallback can leave a configuration that is rejected later, and the key file it writes is plain, unencrypted text. See known limitations. This does not help PATs: reading a PAT from the filesystem is not implemented, so a PAT needs an OS keyring.

The installation ID is detected automatically. The full flag list is in the setup reference.

Terminal window
gh app-auth gitconfig --sync

This writes credential helper entries to your global Git configuration for the credentials you registered. --local limits the change to the current repository. See the Git credential helper guide.

Terminal window
gh app-auth list --verify-keys

Expected outcome: Example App appears in the list with its pattern, and its private key is reported as accessible. If the key cannot be read, fix that here before going further.

Terminal window
gh app-auth test --repo github.com/example-org/private-repo

This checks that a pattern matches the repository, that a JWT can be signed with the key, that an installation token can be retrieved, and that the GitHub API accepts it. Expected outcome: the command reports success for each check; any failure names the step that failed. The command contacts GitHub with the credentials you configured. Nothing on this site runs it for you, and the examples here never use real credentials.

Terminal window
git clone https://github.com/example-org/private-repo.git

Git asks its configured credential helpers for credentials, the helper selects Example App for this remote, and the clone should complete. If Git still prompts, another credential helper earlier in your Git configuration may be answering first; check git config --show-origin --get-all credential.helper.

  • A configuration file at ~/.config/gh/extensions/gh-app-auth/config.yml. Set GH_APP_AUTH_CONFIG to use another path.
  • The private key in the OS keyring. If you used --use-filesystem --key-file instead, the configuration records the path of your key file and gh-app-auth reads that file; it does not encrypt it.
  • Credential helper entries in your Git configuration.
  • No installation token on disk. Tokens are generated on demand and cached in memory only.

gh app-auth exec runs a command with a token from a credential you already configured: a short-lived installation token for a GitHub App, or the stored token for a PAT. Prefer it to printing a token, because the token goes into the child process environment.

From inside a clone of a repository covered by a configured App:

Terminal window
gh app-auth exec -- gh api repos/{owner}/{repo} --jq .full_name

Outside a repository, name the target:

Terminal window
gh app-auth exec --repo github.com/example-org/private-repo -- gh api repos/example-org/private-repo --jq .full_name

Expected outcome: the command runs as the GitHub App installation and prints its normal output. If no credential matches the repository, exec fails before running the command.

The child process and everything it starts inherit the token, so treat the child as trusted. An installation token is a snapshot taken when exec starts; it is not renewed while the child runs and stops working when it expires, so a long-running child fails. For repository-independent calls and explicit App selection, see Identifiers in commands. The full variable rules are in configuration and environment, the flags in the exec reference, and exposure limits, including the token command’s standard-output boundary, in the security model.