Skip to content

Connect the GitHub CLI

Give your agent a logged-in line to GitHub, so "make a repo and push this" or "invite Alice" just works — no clicking through the website.

Time: ~3 min, once. The only un-delegable bit is approving the login in your browser (one code, one click). You'll need: a GitHub account and Claude Code. Last verified: 2026-06-07 · works on macOS, Windows, and Linux.

New to all this? Do Create a GitHub account and Set up Claude Code first — then come back here.

The default: ask your agent

With Claude Code running, say:

"Install the GitHub CLI and log me in with gh auth login. Stop and hand me the browser step when you reach it."

Your agent installs gh and starts the login. It can't finish the login alone — GitHub makes you approve it. So it'll pause and pass you a code; you do the two clicks below.

The one step that's yours: approve the login

When gh auth login runs, it shows a one-time code like 1A2B-3C4D and offers to open your browser.

  1. Copy the code, then let it open github.com/login/device (or press Enter to open it).
  2. Paste the code and click Continue.
  3. Click Authorize. Sign in if asked. The terminal flips to "Logged in as …" on its own. [confirmed]

That's it — the token is saved in your system's secure credential store, and your agent can now act on GitHub as you. [confirmed]

You're done when

Your agent runs gh auth status and it reports you're logged in to github.com (no error, no red). From here, anything GitHub — new repos, invites, pull requests — is one sentence to your agent. [confirmed]

If it doesn't work

  • command not found: gh → the install didn't land. Reopen your terminal, or ask your agent to install it the official way for your OS (Homebrew on macOS, winget on Windows, apt on Linux).
  • The code page says "expired" or "invalid" → the code lives only a few minutes. Re-run gh auth login to get a fresh one, and paste it promptly.
  • Browser won't open (remote server / no GUI) → that's fine. The terminal still prints the code and the github.com/login/device URL — open it on any device (your phone works) and type the code in. [confirmed]
  • "Already logged in to github.com" → you're set; nothing to do. To switch accounts, run gh auth login again or gh auth logout first.
  • It asks SSH or HTTPS → pick HTTPS unless you know you want SSH; it's the simpler path and lets gh handle your git logins too. [confirmed]
  • Work laptop, login blocked → a firewall may block the device flow. Ask your agent to log in with a personal access token instead (gh auth login --with-token), or ask IT.
  • Anything else → the official gh auth login manual lists every flag and prompt.

Watch / read

  • Best written walkthrough: GitHub CLI quickstart — GitHub's own page; covers install + gh auth login end to end in a couple of screens. The single most reliable source.
  • Video: Easy GitHub CLI Installation & Authentication — What Make Art, 2:20. Short and on-task by its title; okay start (we couldn't pull the transcript to confirm it line-by-line, so lean on the quickstart above if it drifts).

Sources