Skip to content

Authentication

You installed Codex, launched it, and hit the sign-in screen. Two options stare back at you: “Sign in with ChatGPT” and “Sign in with API Key.” Picking the wrong one does not break anything, but it determines how you are billed, which features you can access, and whether cloud threads work at all.

  • A clear understanding of the two authentication methods and when to use each
  • Codex authenticated across all surfaces (App, CLI, IDE extension) with a single sign-in
  • Credential storage configured for your security preferences
  • Headless/remote authentication working for SSH and Docker environments
  • Multi-factor authentication set up for Codex Cloud access

Codex supports two authentication methods. They are mutually exclusive per session — you pick one when you sign in.

How it works: Codex opens a browser window, you sign in with your ChatGPT account, and the browser returns an access token.

Billing: Usage is included in your ChatGPT plan (Plus at $20/mo, Pro at $200/mo, Business, Edu, Enterprise). No per-token charges.

Features: Full access to all surfaces including Codex Cloud, cloud threads, GitHub integration with @codex mentions, and automatic code review.

Best for: Individual developers and teams already on ChatGPT plans.

Terminal window
# CLI: Start and choose ChatGPT login
codex
# Or explicitly
codex login

The beautiful thing about Codex authentication: sign in once, and all surfaces pick up your credentials automatically. The App, CLI, and IDE extension share ~/.codex/auth.json (or your OS credential store).

  1. Sign in through any surface — the App, CLI, or IDE extension.

  2. Open a different surface. It should detect your existing credentials and skip the sign-in flow.

  3. If a second surface still prompts you to sign in, check that both surfaces are using the same CODEX_HOME directory (defaults to ~/.codex).

By default, Codex caches credentials in a plaintext file at ~/.codex/auth.json. For better security, you can switch to your operating system’s keyring.

Configure the storage method in ~/.codex/config.toml:

# Options: "file" | "keyring" | "auto"
cli_auth_credentials_store = "keyring"
MethodWhere credentials liveWhen to use
file~/.codex/auth.jsonDefault. Works everywhere. Treat the file like a password.
keyringmacOS Keychain, Linux Secret Service, Windows Credential ManagerBetter security. Requires a GUI session or unlocked keyring.
autoKeyring if available, falls back to fileBest of both worlds for most developers.

Running Codex on a remote server, inside a Docker container, or over SSH? The browser-based login flow will not work. You have three options.

Device code authentication lets you sign in without a local browser.

Terminal window
# Start device code login
codex login --device-auth

Codex prints a URL and a one-time code. Open the URL on any device with a browser, sign in, enter the code, and Codex completes authentication.

Prerequisites: Enable device code login in your ChatGPT security settings (personal account) or workspace permissions (admin).

Multi-Factor Authentication for Codex Cloud

Section titled “Multi-Factor Authentication for Codex Cloud”

Codex Cloud interacts directly with your codebase through GitHub, so OpenAI requires stronger security. If you log in with email and password, you must enable MFA before accessing Codex Cloud.

If you use a social login provider (Google, Microsoft, Apple), MFA is not strictly required on your ChatGPT account, but you should still enable it with your provider:

For managed environments, admins can restrict authentication methods:

# ~/.codex/config.toml or managed config
# Force all users to sign in with ChatGPT (no API keys)
forced_login_method = "chatgpt"
# Restrict to a specific workspace
forced_chatgpt_workspace_id = "00000000-0000-0000-0000-000000000000"

If the active credentials do not match the configured restrictions, Codex logs the user out and exits.

Browser does not open during sign-in: Check that your default browser is configured. On macOS, verify in System Settings > Default Web Browser. On Linux, check xdg-settings get default-web-browser.

Sign-in succeeds but Codex says “not authenticated”: The auth cache may be stale. Delete ~/.codex/auth.json and sign in again. If using keyring storage, check that the keyring is unlocked.

API key works in CLI but not in the App: Make sure you entered the key in the App’s own sign-in flow. The App does not read the OPENAI_API_KEY environment variable automatically.

“MFA required” error when accessing Cloud: Enable multi-factor authentication on your ChatGPT account or social login provider. Email/password accounts must have MFA enabled directly.

Credentials not shared between surfaces: Ensure CODEX_HOME is the same for all surfaces. If you set a custom CODEX_HOME in one terminal but not in the App, they will use different auth caches.