Logging out of Codex removes the cached local sign-in from the current CLI or IDE extension environment so the machine can be left unauthenticated or switched to another account cleanly.
The codex logout command clears the cached login that Codex reuses between launches. Current OpenAI authentication docs say the CLI and IDE extension share that cached state, and the credentials are stored either in the operating system credential store or in auth.json under CODEX_HOME, which defaults to /~/.codex.
Local logout changes only the credentials cached on that machine. It does not revoke the upstream ChatGPT or API credential, so suspected exposure still requires separate revocation or rotation, and current OpenAI Help guidance says older API-key-based CLI setups can switch back to subscription access by logging out and starting Codex again.
Steps to log out of Codex:
- Check the current authentication state in the same terminal environment that is about to log out.
$ codex login status Logged in using ChatGPT
This preflight confirms the local profile still has cached credentials before the logout command runs. API key profiles report API key authentication instead.
- Remove the cached local login from Codex.
$ codex logout Successfully logged out
Current local verification with file-based cached credentials returned Successfully logged out and removed the local auth.json file from the isolated CODEX_HOME used for testing. The same command returned Not logged in and exited cleanly when no cached session was present.
- Check the authentication state again and confirm the local profile is now unauthenticated.
$ codex login status Not logged in
This is the decisive success state after logout. In the same local verification, codex login status returned Not logged in and exited with status 1 once the cached login was gone.
- Start the next login flow only when the same machine or shell still needs Codex access.
$ codex login
Use How to log in to Codex with device authentication for headless terminals or How to log in to Codex with an API key for programmatic environments. OpenAI Help guidance for subscription access also notes the supported switch path of logging out and then starting Codex again on older API-key-based setups.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
