Skip to content

Add env var to force anonymous/no-auth mode #13307

Closed

Description

@junior-ricon

Feature request

Add an environment variable that tells GitHub CLI to ignore all configured credentials and act as an anonymous public user for the current process.

Example shape:

GH_AUTH_DISABLED=1 gh api repos/cli/cli/tags

or similar naming, e.g. GH_ANONYMOUS=1.

Motivation

Today, if a process wants gh to make an anonymous public request, it has to manually scrub every auth source it knows about:

env -u GH_TOKEN -u GITHUB_TOKEN \
    -u GH_ENTERPRISE_TOKEN -u GITHUB_ENTERPRISE_TOKEN \
    GH_CONFIG_DIR="$(mktemp -d)" \
    gh api repos/cli/cli/tags

That is brittle:

  • callers have to remember every token environment variable
  • stored credentials require a separate GH_CONFIG_DIR workaround
  • new auth-related variables would require every caller to update their scrub list
  • scripts that intentionally want anonymous/public behavior can accidentally inherit CI tokens or enterprise tokens from the parent environment

A single opt-in env var would make this behavior explicit and easier to audit.

Use case

Tooling that shells out to GitHub-related commands sometimes needs to fetch public release metadata while running inside CI or a larger authenticated environment. In those cases, inherited tokens can be actively harmful: they may be for the wrong GitHub host, have insufficient scopes, be rate-limited, or trigger a 403 where anonymous public access would otherwise work.

The desired behavior is: for this process only, do not read token env vars, do not read stored hosts credentials, and do not prompt; just make the request anonymously.

Possible behavior

When set, the variable would make gh:

  • ignore GH_TOKEN, GITHUB_TOKEN, GH_ENTERPRISE_TOKEN, and GITHUB_ENTERPRISE_TOKEN
  • ignore stored host credentials from GH_CONFIG_DIR / default config
  • avoid interactive auth prompts
  • continue to respect non-auth env vars such as GH_HOST, GH_REPO, GH_DEBUG, etc.

I would be interested in contributing a PR if this is a direction the project would accept.

Activity

  1. babakks commented on May 12, 2026

    @babakks
    Member

    Thanks for the detailed writeup, @junior-ricon! 🙏

    This is an interesting idea, but I want to understand the real world use cases a bit more before we commit to a direction.

    Most gh commands require authentication, even when the underlying action could technically work without it. An env var like GH_AUTH_DISABLED would effectively disable the majority of gh commands, which could lead to confusing failures, especially if the var leaks into child processes or persists in a shell session longer than intended.

    Could you share more about the specific commands you're using in these scenarios? For example, is this mostly gh api calls against public endpoints, or are there other commands involved? Knowing the concrete workflows would help us figure out whether a narrower solution (like a per-command flag) might be a better fit than a global env var.

  2. added
    more-info-needed
    on May 12, 2026
  3. github-actions commented on May 26, 2026

    @github-actions
    Contributor

    Thank you for your issue!
    We haven't gotten a response to our questions above. With only the information that is currently in the issue, we don't have enough information to take action. We're going to close this but don't hesitate to reach out if you have or find the answers we need. If you answer our questions above, this issue will automatically reopen.

  4. rusak47 commented on Aug 13, 2026

    @rusak47

    Hello! A simple use case would be to allow the coding agent to check issues and similar information in read‑only mode — it can retrieve data, but it should not be allowed to write or commit any changes.

    I'm new to the GitHub CLI tool, so maybe this functionality already exists. If so, could you please point me in the right direction on how to set that up?

  5. david-a-wheeler commented on Aug 31, 2026

    @david-a-wheeler

    Hi, same issue for me: AIs are the key driver.

    Claude Code keeps wanting to use gh, but I don't give Claude Code any working GitHub tokens and I'm working on publicly-visible repos.

    For the moment I'm creating an anon_github [COMMANDS] to switch to anonymous github access, given the env sequence above, to the best I can. If [COMMANDS] is given they're run, else it'll spawn a shell. Not ideal though, since gh sometimes wants login access when it's not needed.

  6. david-a-wheeler commented on Sep 1, 2026

    @david-a-wheeler

    All: if you ended up here, I have identified an obvious workaround: on GitHub, create a fine-grained token scoped to "public repos only" and give it no permissions. Hand that token to gh.

    Then gh works just fine for reading public read-only information, while preventing changes.

  7. jglick commented on Sep 3, 2026

    @jglick

    #2680 is older.

    The suggested script in #13307 (comment) does not seem to work as of 2.99.0. The empty PAT suggested in #13307 (comment) does work, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    more-info-neededneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions