Credentials belong to a Codex CLI environment, so two terminals on the same machine can have different login states. The login status identifies the cached authentication method available to the current environment before a session starts.

ChatGPT and API-key sign-ins are cached locally. The CLI and IDE extension share those login details when they use the same credential storage. Depending on the configuration, credentials reside in the operating system credential store or in an auth.json file under CODEX_HOME, which defaults to ~/.codex.

A cached login does not establish access to a particular model or workspace. The status query reports authentication state without starting an agent task or signing the user in or out, making it suitable for a read-only check before an interactive session or automation run.

Steps to check Codex login status:

  1. Query the login status in the terminal environment that will run Codex.
    $ codex login status
    Not logged in

    Not logged in means this environment has no cached login. A cached ChatGPT sign-in reports Logged in using ChatGPT; an API-key sign-in reports its authentication mode with a masked key. If authentication is needed, the sign-in procedures are separate.
    Related: How to log in to Codex with device authentication
    Related: How to log in to Codex CLI with an API key

    An environment that sets CODEX_HOME can use different configuration and cached credentials from the default home.

  2. Read the status command's exit code immediately in Bash or zsh.
    $ echo $?
    1

    1 accompanies Not logged in, while a logged-in status returns 0. An intervening command replaces $?, so the value must be read immediately after the status query. A different error message needs attention even if its exit code is also nonzero.

Share this guide