GuidesGetting started

Codex login: sign in, log out and switch accounts

How codex login works in Codex 0.172: the browser sign-in and its port 1455 callback, --device-auth, API keys, login status, logout, auth.json and switching.

November 25, 2026The Everpod team
The short answer

Run codex login. It starts a small server on localhost:1455, opens your browser at OpenAI’s sign-in page, and saves the ChatGPT sign-in when the browser calls back. On a machine with no browser, run codex login --device-auth and enter the code it prints from any other device. To use an API key instead, pipe it in: printenv OPENAI_API_KEY | codex login --with-api-key. codex login status shows how you are signed in, and codex logout removes the saved credentials, which live in ~/.codex/auth.json by default. To switch accounts, run codex login again: it signs the old account out first.

What codex login does

With no flags, codex login runs the browser sign-in, which OpenAI’s authentication page calls “the default authentication path when no valid session is available”. In Codex 0.172.0 (released November 24, 2026) it prints:

Starting local login server on http://localhost:1455.

If your browser did not open, navigate to this URL to authenticate:

<the sign-in URL>

On a remote or headless machine? Use `codex login --device-auth` instead.
Copied

Codex opens that URL in your default browser. You sign in to ChatGPT there, the page redirects to http://127.0.0.1:1455/auth/callback, and the small server Codex started takes the tokens from it, saves them and prints Successfully logged in. Starting codex with nothing saved shows the same choice as a screen: Sign in with ChatGPT, Sign in with Device Code, or Sign in another way.

The callback is why browser sign-in fails in some places. The browser has to reach port 1455 on the machine running Codex, so it breaks when Codex runs over SSH, in a container or on a server, and when, in OpenAI’s words, “your local networking configuration blocks the localhost callback”. If port 1455 is busy, the login server first asks an earlier Codex login server on it to stop, then falls back to port 1457, and only then fails with Port … is already in use.

Signing in without a browser

codex login --device-auth
Copied

Codex prints https://auth.openai.com/codex/device and a one-time code that “expires in 15 minutes”. Open the link on your phone or laptop, sign in to the ChatGPT account Codex should use, and enter the code; the terminal finishes on its own. OpenAI still labels this beta and recommends it for headless machines. It needs device code sign-in switched on in your ChatGPT security settings, or by a workspace admin; if Codex tells you to enable it, the device-code guide has the switch. The other route OpenAI documents forwards the callback port from your laptop, so the browser sign-in works through SSH:

ssh -L 1455:localhost:1455 user@remote
codex login        # in that session; open the printed URL on your laptop
Copied

The rest of a server setup is in Codex CLI on a Linux server.

Signing in with an API key

printenv OPENAI_API_KEY | codex login --with-api-key
Copied

The key is read from standard input, so you never type it as an argument on the command line. Codex answers:

Reading API key from stdin...
API key saved. Authentication is checked when you send a request.
Copied

The last sentence is literal: a wrong key is saved without complaint and fails on the first request. The old --api-key flag, which took the key as an argument, now only exits with:

The --api-key flag is no longer supported. Pipe the key instead,
e.g. `printenv OPENAI_API_KEY | codex login --with-api-key`.
Copied

A key bills your OpenAI Platform account per token, not your ChatGPT plan, and some features, Codex cloud among them, need a ChatGPT sign-in. Using Codex with an API key covers the cost, CODEX_API_KEY for a single run, and CI. An access token, where you have been given one, signs in the same way, with printenv CODEX_ACCESS_TOKEN | codex login --with-access-token.

Checking which account is signed in

$ codex login status
Logged in using ChatGPT
Copied

It prints the mode, and exits with 0 when logged in, so scripts can test it. The lines you will usually see:

OutputMeaningExit
Logged in using ChatGPT
A ChatGPT sign-in, browser or device code0
API key configured - sk-proj-***…
A saved key, shown masked; not tested against OpenAI0
Logged in using access token
A saved access token0
Not logged in
Nothing saved in this Codex home1

It does not name the ChatGPT account or workspace. It reads only what is saved, so a CODEX_API_KEY in the environment still shows Not logged in.

codex logout

codex logout
Copied

It removes the saved credentials, ChatGPT or API key, and prints Successfully logged out, or Not logged in if there was nothing to remove; it takes no flags. Inside an interactive session, /logout logs you out. The CLI and the IDE extension share one saved sign-in, so logging out of either signs both out.

For a ChatGPT sign-in, logout also revokes the refresh token at OpenAI, best-effort: if that request fails, the local copy is still deleted. For an API key it revokes nothing, so a key you no longer trust has to be revoked on the Platform’s API keys page.

Where the sign-in is stored

By default in auth.json under CODEX_HOME, which is ~/.codex unless you set it. It is plain text; OpenAI’s advice is to “treat ~/.codex/auth.json like a password: it contains access tokens.” The cli_auth_credentials_store setting in ~/.codex/config.toml moves it:

ValueWhere credentials go
file (default)
CODEX_HOME/auth.json
keyring
The operating system’s credential store; fails if there is none
auto
The credential store when available, otherwise auth.json
ephemeral
Memory only, for the current process
cli_auth_credentials_store = "keyring"
Copied

Set it before you sign in. A headless Linux server often has no credential store, so keyring fails there and auto ends up using the file.

Switching accounts or workspaces

Codex keeps one sign-in per Codex home. To change ChatGPT accounts, run codex login (or --device-auth) again and sign in as the other account in the browser. Both commands log the old account out, revoking its token, before they start, so a sign-in you abandon halfway leaves Codex signed out. Saving an API key replaces whatever was saved without that logout step.

Close every Codex session started under the old account first, including any in tmux and background codex app-server processes. A process still running on the old sign-in fails at its next refresh with “Your access token could not be refreshed because you have since logged out or signed in to another account”, one of the messages in the refresh-token guide.

To keep two sign-ins on one machine, give the second its own Codex home. Codex refuses a CODEX_HOME that does not exist, so create it first:

mkdir -p ~/.codex-work
CODEX_HOME=~/.codex-work codex login
CODEX_HOME=~/.codex-work codex      # sessions here use the second account
Copied

The second home reads its own config.toml, not the one in ~/.codex. An admin can pin sign-ins to one workspace with forced_chatgpt_workspace_id, or to one method with forced_login_method = "chatgpt" or "api"; if the saved credentials do not match, “Codex logs the user out and exits.”

Copying a sign-in to a server

OpenAI documents signing in on a machine with a browser and copying the file across:

ssh user@remote 'mkdir -p ~/.codex'
scp ~/.codex/auth.json user@remote:~/.codex/auth.json
Copied

If your credentials are in the operating system’s credential store rather than auth.json, OpenAI says this method “may not apply”. It also has a catch: the copy is one sign-in in two places. Codex replaces the refresh token each time it uses it, and OpenAI’s page on Codex in CI says “Do not share the same file across concurrent jobs or multiple machines.” Once both copies are in use, the one that refreshes second stops with “your refresh token was already used”. Treat the copy as the server’s alone, or skip it and sign the server in with --device-auth.

Which plans can sign in

Per OpenAI’s pricing page, Codex is included in ChatGPT Free, Go, Plus, Pro, Business, Edu and Enterprise, so any ChatGPT account can sign in; the plans differ in how much you can use. Which ChatGPT plans include Codex has the allowances.

When login fails

MessageCause and fix
Browser shows a connection error after sign-in
It could not reach Codex’s callback (port 1455, or 1457 after a fallback): Codex is on another machine or the port is blocked. Use --device-auth or the SSH forward above.
Port … is already in use
Something else holds ports 1455 and 1457. Stop it, or use --device-auth.
A request to enable device code sign-in
The ChatGPT setting is off: the device-code guide.
device auth timed out after 15 minutes
The code was not entered in time. Run the command again for a new code.
ChatGPT login is disabled. Use API key login instead.
forced_login_method = "api" is set, by you or an admin.
API key login is disabled. Use ChatGPT login instead.
forced_login_method = "chatgpt" is set.
Login is restricted to workspace id(s) ….
The account you chose is not in the workspace forced_chatgpt_workspace_id names. Sign in with an account in that workspace.
--with-api-key expects the API key on stdin.
Nothing was piped in. Pipe the key, as above.
401 “Missing bearer or basic authentication in header”
Codex found no credentials for this user: the 401 guide.
“…your refresh token was already used”
Another copy of the same sign-in refreshed first: the refresh-token guide.

If codex login status says you are signed in but a job says you are not, the job runs as another user or with another HOME or CODEX_HOME, and looks for a different auth.json.

Run Codex on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.