In CI, `gh pr comment` fails with `HTTP 401: Bad credentials`, or locally `gh` says `You are not logged into any GitHub hosts. To log in, run: gh auth login`.
BeginnerTroubleshootingGitHub, Actions and Pull Request Issues
Answer
Likely causes → gh found no token: in Actions it needs GH_TOKEN (or GITHUB_TOKEN) in the step's environment. A 401 means the token is set but expired, revoked or malformed.
Diagnose →
gh auth status
env | grep -E '^(GH|GITHUB)_TOKEN=' | cut -c1-12
Fix →
- run: gh pr comment "$PR" --body "Deployed to staging"
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
permissions:
pull-requests: write
Locally: gh auth login (or gh auth refresh -s repo,workflow to add scopes).
Prevent → Always pass GH_TOKEN explicitly in workflow steps that call gh.
More on GitHub, Actions and Pull Request Issues
A workflow step that pushes a version bump fails with `remote: Permission to org/repo.git denied to github-actions[bot].` and `The requested URL returned error: 403`.IntermediateA workflow pushes a commit or tag, but the workflow that should run on that push or tag never starts.IntermediateA container job fails on any Git command with `fatal: detected dubious ownership in repository at '/__w/app/app'`.IntermediateYour PR suddenly shows 340 changed files and dozens of commits you did not write.IntermediateThe PR is stuck on `Expected — Waiting for status to be reported` for a required check called `build`.IntermediateThe PR was approved, but merging shows "Review required" again after you pushed a small fix.Beginner