Lesstep
GitHub Actions · GitHub CLI · Checked November 3, 2026

GitHub Actions: gh "set the GH_TOKEN environment variable"

GitHub CLI found no token. It does not pick up the job's token by itself: it reads GH_TOKEN, then GITHUB_TOKEN, from the step's environment (gh help environment), and the credentials that actions/checkout stores for git are not among them. gh prints this text when it finds no token and GITHUB_ACTIONS is true (help.go), and exits with 4, its code for "requires authentication". The fix is one line, but in many recent cases the line was there and its value was empty.

What it looks like

gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable. Example:
  env:
    GH_TOKEN: ${{ github.token }}
Error: Process completed with exit code 4.

1. No token in that step

Set it on the step, or on the job so that every step has it. Blur-AutoClicker-arch moved it to the job after one gh step in a rarely used path went without (#3).

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    env:
      GH_TOKEN: ${{ github.token }}
    steps:
      - uses: actions/checkout@v7
      - run: gh release create "$GITHUB_REF_NAME" --generate-notes

github.token is the same token as secrets.GITHUB_TOKEN. Give the job the permissions the command needs: contents: write for releases, pull-requests: write for gh pr create, issues: write for gh issue create.

2. The line is there, and the value is empty

An expression for a secret that the run does not get is an empty string, and an empty GH_TOKEN is no token. In vbonk/repo-template, GH_TOKEN: ${{ secrets.PROJECT_TOKEN }} had no secret behind it, and 100 of the last 100 runs failed (#190). The usual reasons:

tuna-os/hive falls back to the job's token when the secret is unset (#28):

env:
  GH_TOKEN: ${{ secrets.GHCR_PRUNE_TOKEN || github.token }}

That fallback is right only when github.token can do the job. It cannot in these cases, and there a clear failure is better:

3. GitHub Enterprise Server

For a GitHub Enterprise Server host gh reads GH_ENTERPRISE_TOKEN, then GITHUB_ENTERPRISE_TOKEN, not GH_TOKEN. Set GH_HOST too when the host cannot be read from the repository's remote (gh help environment).

Telling it apart

See failed jobs from IntelliJ IDEA

Pipeline Inbox for GitHub Actions Workflows, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the runs of all your repositories in an IDE tool window, with their jobs and steps, and your current branch's runs are in the status bar. Reading is free; re-running failed jobs, cancelling, running workflows and reviewing deployments are Pro (US$1.50 a month, with a 30-day trial).

GitHub, GitHub Actions and GitHub CLI are trademarks of GitHub, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with, sponsored or endorsed by GitHub, Inc. or JetBrains.

More: "Resource not accessible by integration" · AWS "Could not load credentials from any providers" · "GH013: Repository rule violations found" · GitHub Actions plugins for IntelliJ IDEA compared · 日本語