Codex CLI uses OPENAI_API_KEY instead of logged-in session
Resolved 💬 2 comments Opened Aug 24, 2025 by abdulmunimjundurahman Closed Oct 28, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
codex-cli 0.23.0
Which model were you using?
gpt5
What platform is your computer?
Linux 6.8.0-52-generic x86_64 x86_64
What steps can reproduce the bug?
- Log in with codex login successfully.
- Run a Codex CLI command (e.g., codex run ...).
- Notice that the CLI attempts to use OPENAI_API_KEY from the environment instead of the logged-in session.
What is the expected behavior?
Codex CLI should use the logged-in session token when a user is authenticated via codex login, even if an OPENAI_API_KEY is set.
What do you see instead?
Codex ignores the login session and tries to use OPENAI_API_KEY, which may cause authentication errors or unexpected behavior.
Additional information
_No response_
2 Comments
Sorry for the possibly stupid question, but did you log in via the chatgpt with a redirect through the browser? What did your login process look like?
If so, check your
/home/USER/.codex/auth.a json(~/.codex/auth.json) file.Try to delete it and/or execute a
codex logout. After that,codex loginagain.Enter the string in
/home/USER/config.toml:`
`preferred_auth_method = "chatgpt"
Then log in again.
The auth and login code for codex has changed significantly since 0.23.0, so this issue is probably no longer relevant. If you're still having a problem related to login with the latest published version of Codex, please file a new issue.