Text of docs.github.com › en › copilot › how-tos › copilot-cli › set-up-copilot-cli › authenticat… as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Authenticating GitHub Copilot CLI - GitHub Docs

Skip to main content Skip to content Collapse sidebar Expand sidebar Authenticating GitHub Copilot CLI Authenticate Copilot CLI so that you can use Copilot directly from the command line. Who can use this feature? GitHub Copilot CLI is available with all Copilot plans. If you receive Copilot from an organization, the Copilot CLI policy must be enabled in the organization's settings. In this article About authentication GitHub authentication is not required if you use your own LLM provider API keys (BYOK) or sign in with a Microsoft Entra account.

Authentication is required for any other GitHub Copilot CLI usage. When authentication is required, Copilot CLI supports several methods. The method you use depends on whether you are working interactively or in an automated environment. OAuth : The default and recommended method for interactive use. There are two OAuth flows. The browser (web) flow opens your browser to authorize the sign-in and completes it on a local loopback callback.

The device code flow displays a one-time code that you enter in your browser. The browser flow is the default on a local desktop, and known remote or headless environments (including SSH, GitHub Codespaces, dev containers, and CI) default to the device code flow. See Authenticating with OAuth . Environment variables : Recommended for CI/CD pipelines, containers, and non-interactive environments. You set a supported token as an environment variable ( COPILOT_GITHUB_TOKEN , GH_TOKEN , or GITHUB_TOKEN ), and the CLI uses it automatically without prompting.

See Authenticating with environment variables . GitHub CLI fallback : If you have GitHub CLI ( gh ) (note: the gh CLI, not copilot ) installed and authenticated, Copilot CLI can use its token automatically. This is the lowest priority method and activates only when no other credentials are found. See Authenticating with GitHub CLI . Once authenticated, Copilot CLI remembers your login and automatically uses the token for all Copilot API requests.

You can log in with multiple accounts, and the CLI will remember the last-used account. Token lifetime and expiration depend on how the token was created on your account or organization settings. Using Copilot CLI without GitHub authentication GitHub authentication is not required if you use either of the following for AI model requests: Your own LLM provider API keys (BYOK) : Copilot CLI connects directly to your configured provider without a GitHub account or token.

A Microsoft Entra account : If your Microsoft Entra tenant uses OpenID Connect (OIDC) to connect to GitHub Enterprise Managed Users, you can use your Microsoft Entra account to sign in on Windows or macOS. If a Microsoft 365 Copilot license exists for that Microsoft Entra user, model requests can go to Microsoft 365 Copilot. See Authenticating with Microsoft Entra . However, without GitHub authentication, the following features are not available : /delegate : Requires Copilot cloud agent, which runs on GitHub's servers GitHub MCP server: Requires authentication to access GitHub APIs GitHub Code Search: Requires authentication to query GitHub's search index You can combine BYOK or Microsoft Entra authentication with GitHub authentication to get the best of both: your preferred model for AI responses, plus access to GitHub-hosted features like /delegate and code search.

Offline mode If you set the COPILOT_OFFLINE environment variable to true , Copilot CLI runs without contacting GitHub's servers. In offline mode: No GitHub authentication is attempted. The CLI only makes network requests to your configured BYOK provider. Telemetry is fully disabled. Offline mode is only fully air-gapped if your BYOK provider is local or otherwise within the same isolated environment (for example, a model running on-premises with no external network access).

If COPILOT_PROVIDER_BASE_URL points to a remote or internet-accessible endpoint, prompts and code context will still be sent over the network to that provider. Without offline mode, even when using BYOK without GitHub authentication, telemetry is still sent normally. Supported token types Token type Prefix Supported Notes OAuth token (browser or device flow) gho_ Yes Default method via copilot login Fine-grained PAT github_pat_ Yes Must be owned by your personal account (not an organization) with the Copilot Requests account permission GitHub App user-to-server ghu_ Yes Via environment variable Classic PAT ghp_ No Not supported by Copilot CLI How Copilot CLI stores credentials By default, the CLI stores your OAuth token in your operating system's keychain under the service name copilot-cli : Platform Keychain macOS Keychain Access Windows Credential Manager Linux libsecret (GNOME Keyring, KWallet) If the system keychain is unavailable—for example, on a headless Linux server without libsecret installed—the CLI prompts you to store the token in a plaintext configuration file at ~/.copilot/config.json .

When you run a command, Copilot CLI checks for credentials in the following order: COPILOT_GITHUB_TOKEN environment variable GH_TOKEN environment variable GITHUB_TOKEN environment variable OAuth token from the system keychain GitHub CLI ( gh auth token ) fallback Note An environment variable silently overrides a stored OAuth token. If you set GH_TOKEN for another tool, the CLI uses that token instead of the OAuth token from copilot login .

To avoid unexpected behavior, unset environment variables you do not intend the CLI to use. There is one exception: in GitHub Codespaces, the GITHUB_TOKEN that is injected automatically does not take precedence over an account you signed in with using /login . A GITHUB_TOKEN , COPILOT_GITHUB_TOKEN , or GH_TOKEN that you export explicitly still does. When you configure BYOK provider environment variables (for example, COPILOT_PROVIDER_BASE_URL , COPILOT_PROVIDER_API_KEY ), Copilot CLI uses these for AI model requests regardless of your GitHub authentication status.

GitHub tokens are only needed for GitHub-hosted features. Authenticating with OAuth OAuth is the default authentication method for interactive use. You can authenticate by running /login from Copilot CLI or copilot login from your terminal. Both offer a browser (web) flow and a device code flow. Authenticate with /login From Copilot CLI, run /login . /login Select the account you want to authenticate with. For GitHub Enterprise Cloud with data residency, enter the hostname of your instance.

If you select Your organization (Microsoft Entra) , Copilot CLI automatically signs you in with your existing Microsoft Entra account. What account do you want to log into? 1. GitHub.com 2. GitHub Enterprise Cloud with data residency (*.ghe.com) 3. Your organization (Microsoft Entra) Choose how you want to sign in. The recommended option is listed first, and depends on your environment: the browser flow on a local terminal, or the device code flow in a remote or headless environment.

The following example shows the prompt in a local terminal: How do you want to sign in? 1. Sign in with your browser (recommended) 2. Sign in with a device code Complete the flow you selected. Browser : Copilot CLI opens your browser so that you can authorize the sign-in. If your browser does not open automatically, the terminal displays a URL that you can visit instead. Device code : The CLI displays a one-time user code, and can copy it to your clipboard and open your browser for you.

Waiting for authorization... Enter one-time code: 1234-5678 at https://github.com/login/device Press any key to copy to clipboard and open browser... Navigate to the verification URL at https://github.com/login/device if your browser did not open automatically, then paste the one-time code in the field on the page. If your organization uses SAML SSO, click Authorize next to each organization you want to grant access to.

Review the requested permissions and click Authorize GitHub Copilot CLI . Return to your terminal. The CLI displays a succ

The rest of this page is on the live site.