|
| 1 | +--- |
| 2 | +name: github-cli-setup |
| 3 | +description: Establish a correct, least-surprise `gh` CLI session before doing any GitHub work — confirm the right account is active, that it can actually see the target repo, and that its token carries the scopes the task needs (repo, project, workflow). Use at the start of any GitHub task, or when a `gh` command fails with "Could not resolve to a Repository", "Not Found", or "missing required scopes". Domain-agnostic — the same checks apply to any repo or project. |
| 4 | +--- |
| 5 | + |
| 6 | +# github-cli-setup |
| 7 | + |
| 8 | +Most GitHub automation failures aren't the task — they're the *session*: the wrong account is |
| 9 | +active, that account can't see a private repo, or its token is missing a scope the command needs. |
| 10 | +This skill front-loads those checks so the real work doesn't fail halfway through. Run it before |
| 11 | +issue/milestone/project/PR work, and reach for it the moment a `gh` call returns a resolution, |
| 12 | +not-found, or scope error. |
| 13 | + |
| 14 | +## Background: the three things that go wrong |
| 15 | + |
| 16 | +1. **Wrong active account.** `gh` supports several logged-in accounts but only one is *active*. |
| 17 | + The active one may not be the account that owns (or can see) the repo you're targeting. |
| 18 | +2. **No access to the repo.** A private repo is invisible to any account that isn't the owner or |
| 19 | + a collaborator — the symptom is `Could not resolve to a Repository` / HTTP 404, which reads |
| 20 | + like the repo doesn't exist when really the *active account* just can't see it. |
| 21 | +3. **Missing token scopes.** A task needs specific OAuth scopes. Common ones: |
| 22 | + - `repo` — repos, issues, milestones, PRs (needed for almost everything). |
| 23 | + - `project` / `read:project` — GitHub Projects (v2) boards. **Milestones and issues do NOT |
| 24 | + need this — only the Projects board does.** |
| 25 | + - `workflow` — editing `.github/workflows/` files. |
| 26 | + Adding a scope requires an **interactive** re-auth the user must run themselves. |
| 27 | + |
| 28 | +## Steps |
| 29 | + |
| 30 | +1. **Check the session.** Run `gh auth status` and read every logged-in account, which is active, |
| 31 | + and each account's token scopes. |
| 32 | +2. **Identify the account that owns/can-see the target repo.** If the task names a repo under a |
| 33 | + specific owner, that owner's account (or a collaborator) is the one you need. If the active |
| 34 | + account differs, switch: `gh auth switch --user <login>`. |
| 35 | +3. **Verify visibility.** Confirm the active account can actually resolve the repo: |
| 36 | + `gh repo view <owner>/<repo> --json name,visibility,hasIssuesEnabled`. A 404 here almost |
| 37 | + always means "active account can't see it," not "doesn't exist" — switch accounts or ask the |
| 38 | + user to grant access, rather than concluding the repo is missing. |
| 39 | +4. **Check the scopes the task needs** against the active account's scopes from step 1: |
| 40 | + - issues / milestones / PRs → `repo` |
| 41 | + - Projects (v2) board → `project` (and `read:project` to list/read) |
| 42 | + - editing workflows → `workflow` |
| 43 | +5. **If a scope is missing, ask the user to add it** — this is interactive and cannot be done |
| 44 | + non-interactively. Give them the exact command to run in their session: |
| 45 | + `gh auth refresh -s <scope> --hostname github.com` (e.g. `-s project`). It shows a one-time |
| 46 | + code and opens a browser to approve on the correct account. Wait for them to confirm, then |
| 47 | + re-check `gh auth status` before proceeding. |
| 48 | +6. **Proceed only once** the active account both resolves the repo and holds the needed scopes. |
| 49 | + Note in your summary which account you're operating as, so the user isn't surprised later. |
| 50 | + |
| 51 | +## Do not |
| 52 | + |
| 53 | +- Do not conclude a repo "doesn't exist" on a 404 without first checking whether a *different* |
| 54 | + logged-in account can see it — private-repo visibility is account-scoped. |
| 55 | +- Do not try to add a scope non-interactively or by editing token files — `gh auth refresh` must |
| 56 | + be run by the user. |
| 57 | +- Do not assume the active account is the right one just because a previous command happened to |
| 58 | + work; a read that succeeds under `repo` scope says nothing about `project` scope. |
| 59 | +- Do not store or echo full tokens; treat the masked values from `gh auth status` as enough. |
0 commit comments