AI / GitHub Copilot CLI Fundamentals Interview Questions
How do you authenticate GitHub Copilot CLI and what token types are supported?
Copilot CLI supports two authentication methods: an interactive browser-based flow (default) and a token-based flow for headless/automated environments.
| Method | How it works | Best for |
|---|---|---|
| Browser-based (default) | Run copilot or /login - browser opens for OAuth flow; token stored in system credential store | Interactive use on developer machines |
| Environment variable token | Set COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN env var | Headless automation, CI/CD, scripts |
# Method 1: Interactive browser flow (first time use) copilot # → prompted to /login if not authenticated # Follow on-screen browser authentication # Method 2: Fine-grained PAT in environment variable export COPILOT_GITHUB_TOKEN=github_pat_xxx copilot -p "List my open issues" # Method 3: Use GH_TOKEN or GITHUB_TOKEN (checked in order) export GH_TOKEN=your_token_here copilot -p "Explain this code"
Token type precedence (checked in order): COPILOT_GITHUB_TOKEN → GH_TOKEN → GITHUB_TOKEN.
Supported token types:
- Fine-grained personal access tokens (v2 PATs) with the Copilot Requests permission
- OAuth tokens from the Copilot CLI app
- OAuth tokens from the GitHub CLI (gh) app
- Classic personal access tokens (ghp_) are NOT supported
When no credential store is found, the token is saved as plain text in ~/.copilot/ (or the path set by COPILOT_HOME).
More Related questions...