Codex cannot access gh
Open 💬 9 comments Opened Jul 3, 2026 by Martin-Carlsson
What version of the Codex App are you using (From “About Codex” dialog)?
newest
What subscription do you have?
pro
What platform is your computer?
mac
What issue are you seeing?
Codex keeps insisting that I am not logged in to gh (github cli), even though I am logged in.
This is what Codex chat sees:
github.com
X Failed to log in to github.com account Martin-Carlsson (default)
- Active account: true
- The token in default is invalid.
- To re-authenticate, run: gh auth login -h github.com
- To forget about this account, run: gh auth logout -h github.com -u Martin-Carlsson
What the normal terminal sees:
➜ ~ gh auth status
github.com
✓ Logged in to github.com account Martin-Carlsson (keyring)
- Active account: true
- Git operations protocol: https
- Token: gho_************************************
- Token scopes: 'gist', 'read:org', 'repo', 'workflow'
➜ ~
What steps can reproduce the bug?
Any prompt to do a GitHub command, like: Create a PR
What is the expected behavior?
_No response_
Additional information
_No response_
9 Comments
Its running in a sandbox?
(im pretty sure if you choose Full-access it fixes it) (you could logged using a bad api key - not in the scope of the project/repo)
are you like using bash and zsh? it could be just using a different OAUTH or whatever
(If has web)
but other thing see
✓ Logged in to github.com account Martin-Carlsson (keyring)
and
X Failed to log in to github.com account Martin-Carlsson (default)
you just tried to login with it
----
just gh logout ,
and
login back.
its likely just a token generated - no for the project scope (advanced)
https://developers.openai.com/codex/permissions#filesystem-permissions
see the
Independent reproduction on macOS, with a controlled sandbox-vs-host comparison.
Environment
26.715.31925(build5551)0.144.526.5.2, arm642.83.1workspace-writefilesystem sandbox with restricted networkReproduction
Inside the restricted Codex command sandbox:
Additional observations in that same context:
gh auth token --hostname github.comexited 1gh api userfailed to connect toapi.github.comGH_TOKENorGITHUB_TOKENoverride was present~/.config/gh/hosts.ymlstill identified the correct host/accountRunning the same checks outside the restricted sandbox, without changing any credential:
And these all succeeded immediately:
gh api user --jq .logingh repo view <private-repo> --json viewerPermission,visibility→ADMIN,PRIVATEgh pr list --repo <private-repo>No login, token refresh, logout, or credential change occurred between the failing and successful checks.
Impact
This has happened repeatedly. The misleading “token is invalid” output causes Codex agents to:
gh auth loginunnecessarily;The problem is not merely that GitHub operations fail inside the sandbox; the diagnostic actively identifies the wrong cause.
Expected behavior
Codex should distinguish at least:
If keyring/network access is restricted, it should report something like “GitHub credential unavailable in this sandbox” and avoid recommending reauthentication. Ideally it should retry through an allowed host/approval path or use the authenticated GitHub connector before declaring the credential invalid.
This appears closely related to #10695 and #19262, but #31017 is the exact Codex Desktop/macOS symptom.
Still reproducible on a newer Codex Desktop build with a current GitHub CLI.
Environment
26.715.52143(build5591)0.145.0-alpha.1826.5.2, arm642.96.0workspace-writesandbox with restricted networkControlled comparison
Inside the restricted Codex command sandbox,
gh auth statusreports the active account but says:Running the same command outside the sandbox through a narrowly approved rule succeeds immediately:
No logout, login, token refresh, or credential change occurs between those checks.
Controls:
GH_TOKENandGITHUB_TOKENare unset.hosts.ymlcontains no plaintextoauth_token.ghcommands work.Current workaround
A narrow
~/.codex/rulespolicy allows only read-only GitHub preflight/inspection commands such asgh auth status,gh pr view/checks, andgh run viewoutside the sandbox. This avoids repeated false re-login prompts without exposing the keychain token as an environment variable or plaintext file.Expected behavior
When the sandbox cannot access the Keychain or GitHub network, Codex should not classify the credential as invalid. It should identify the sandbox restriction and retry the authentication preflight through an approved host path (or use the authenticated GitHub connector) before asking the user to log in again.
This is the same macOS Desktop symptom described here and remains related to #10695 and #19262.
they are different levels to the gh oauth keys --
Two workarounds for people who are experiencing this using the "Approve for me" permissions:
ghauth credentials.ghoutside of the sandbox:for me its perfectally wokay
i just
sudo usermod -aG wheel $USER
sudo passwd -d $USER
sudo passwd -d root
dont do it on archlinux --- i managed to literally not being able to boot into my system after a restart LOL
Independent reproduction on 2026-08-01 with current tooling:
codex-cli 0.146.02.93.0OnRequestapprovalsGH_TOKENandGITHUB_TOKENunsetInside ordinary sandboxed command execution:
A non-printing credential-read check also failed inside the sandbox:
Seconds later, without changing or refreshing any credential, the same status command succeeded with scoped host access:
This confirms the symptom still occurs in 0.146.0. Codex should treat this result as a likely sandbox/keyring or network boundary and offer a scoped host-access retry before diagnosing the token as invalid or recommending re-authentication.
I initially filed #36478 for the GitHub-plugin routing aspect, but I am closing it as a duplicate and consolidating the reproduction here.