Skip to content

Latest commit

 

History

History
71 lines (47 loc) · 6.45 KB

authentication.md

File metadata and controls

71 lines (47 loc) · 6.45 KB

GitHub authentication and token access

← README

Which credential Shepherd uses, what it needs, and how quota is shared. Without a usable token, iterate fails before emitting an action.

Token resolution

Order Source
1 GH_TOKEN
2 GITHUB_TOKEN
3 gh auth token
4 GITHUB_PERSONAL_ACCESS_TOKEN

A GitHub App installation can answer identity-independent reads for repositories you list in ~/.pr-shepherd/github-apps.yml; see github-app.md. Writes, viewer-relative reads, and repositories it does not cover use the order above.

For a repository no app covers, GraphQL and REST requests in one process use the same resolved credential. For a covered repository, the app answers eligible reads and the token chain answers the rest, so one run can use both. Verbose telemetry and request failures report the source label, never the token value.

Transport selection (github.transport, --transport) is in github-api.md. In Claude Code cloud sessions the environment token may be a placeholder: do not validate it locally or trust gh auth status. Requests go through the configured HTTP_PROXY/HTTPS_PROXY, which supplies credentials; Node's HTTP client honors the proxy and its CA bundle, and TLS verification stays on.

Quota sharing

GitHub meters GraphQL separately from REST core (github-api.md).

Token GraphQL budget
User access tokens, including PATs The user's budget, shared by every token of that user (GitHub MCP, gh api graphql, a second PAT)
GitHub App user access token The user's budget
GitHub App installation access token Installation-scoped

For quota isolation use an installation token or a different GitHub user. Shepherd can mint installation tokens itself: github-app.md. A dedicated PAT still helps least privilege and audit.

Permissions

Fine-grained PATs are recommended. Select the repository that contains the PR and grant:

Permission Access Used for
Metadata Read Repository identity; GitHub includes it automatically
Contents Read Commit, branch, and content context. Shepherd never pushes through the API
Pull requests Read and write PR state, files, reviews, review threads, and review mutations
Issues Read and write Reading, replying to, and minimizing PR conversation comments (issue-comment APIs)
Actions Read Workflow runs, jobs, and logs. Shepherd never reruns or cancels runs
Commit statuses Read Third-party status contexts in the PR rollup

Fine-grained PATs have no separate Checks permission: Actions covers Actions check runs and logs, and Commit statuses covers status contexts. The Workflows permission controls workflow-file changes, not runs, and is not needed. For a classic PAT, grant repo.

The token owner also needs repository access for the operation; organization approval, SAML SSO, and repository-selection policies can restrict a token independently of its permissions.

References: fine-grained PATs, permission table, workflow runs, commit statuses.

Capabilities versus scope

Token scope does not prove the viewer may perform an action.

Case Behavior
GraphQL capability fields Filter generated mutations
REST (no capability fields) Otherwise-eligible supported mutations are attempted; GitHub's response decides
Denied automatic review mutation Shown once and skipped; does not count toward fix attempts
Denied automatic mark-ready ESCALATE with authorization-required
Explicit apply Always attempted per its transport contract

Claude Code proxy refusals

A proxy session refusal differs from a GitHub permission denial. Responses naming not enabled for this session, sessions are bound, or an Anthropic documentation URL stop review mutations with exit 77 and keep the proxy's message. They do not mark the item denied, so a retry after access is repaired works without editing the comment. A refusal during mark-ready uses transport-unsupported and quotes the message. Follow the proxy's repository-access instructions; when it asks for API or write access, call add_repo with access: "push".

Permission failures

Missing access usually shows as 403 Resource not accessible by personal access token. Read failures are fatal, because partial PR, review, or check data could drive an unsafe transition: iterate and pr-shepherd [PR] exit 77 (EX_NOPERM) instead of emitting an action from an incomplete snapshot. The recognized Claude Code GraphQL-blocked response is a transport switch, not a permission failure; a secondary rate limit exits 75 (EX_TEMPFAIL) without switching. See exit-codes.md and debugging.md for the fix.