Codex localhost Refused to Connect? 3 Proven Fixes for the Login Callback
codex localhost refused to connect means the browser login never reached Codex. Use codex login --device-auth or ssh -L 1455:localhost:1455. Claude Code fix too.

When you sign in to Codex with ChatGPT and the browser lands on a localhost page that says localhost refused to connect., the browser could not reach the callback server Codex opened on your machine (by default localhost:1455), so the sign-in never got back to the terminal. The official fix is device code login: codex login --device-auth. If Codex runs on a remote server and you want the browser flow, forward the port from your local machine with ssh -L 1455:localhost:1455. The same steps fix codex localhost refused to connect on WSL, Docker and SSH hosts. We checked every step against the official Codex authentication docs on November 4, 2026. The last section covers the matching Claude Code login error.

What codex localhost refused to connect means
localhost refused to connect. is Chrome’s error page, usually with the code ERR_CONNECTION_REFUSED. Chinese-language Chrome shows 「localhost 拒绝了我们的连接请求。」. It appears at the last step of the login flow:
- you run
codex login, and Codex starts a local callback server and opens a browser; - you sign in to ChatGPT in the browser;
- the browser redirects to
http://localhost:1455/...to hand the credentials to Codex.
If step 3 can’t connect, you get this page. The docs name two situations: Codex runs in a remote or headless environment, or your local network configuration blocks the localhost callback. The first is the common one. Codex runs on a server, in WSL or in a Docker container while the browser runs on your own computer, so the browser’s localhost is your computer and the callback server lives somewhere else.
Fix 1: codex login –device-auth (recommended)
Device code login doesn’t use the localhost callback. OpenAI marks it as beta.
- Turn on device code login first: in your ChatGPT security settings for a personal account, or in workspace permissions (admin) for a workspace.
- In the terminal where Codex runs, run the command below, or pick “Sign in with Device Code” in the interactive login screen.
- Open the printed link in any browser, sign in, and enter the one-time code.
codex login --device-auth
Then confirm the active method:
codex login status
Fix 2: forward port 1455 over SSH
To keep the browser flow on a remote machine, tunnel the callback port. On your local computer run:
ssh -L 1455:localhost:1455 user@remote
In that SSH session, run codex login and open the printed address in your local browser. When the browser redirects to localhost:1455, the request travels through the tunnel to Codex on the remote machine.
Fix 3: sign in elsewhere and copy auth.json
If neither works, the documented fallback is to run codex login on a machine where the browser flow works and copy ~/.codex/auth.json to the target:
ssh user@remote 'mkdir -p ~/.codex'
scp ~/.codex/auth.json user@remote:~/.codex/auth.json
Treat auth.json like a password because it contains access tokens. If your OS keeps Codex credentials in a credential store, there is no file to copy and this method doesn’t apply.
Still failing on a single local machine
If Codex and the browser are on the same computer, the docs only say a local network configuration can block the callback. The checks below are our inference, not from the docs:
- make sure
codex loginis still running in the terminal when the browser redirects; once it exits, the callback server is gone; - check whether a system proxy or security tool intercepts localhost traffic, and add a localhost bypass;
- check whether another program holds port 1455, for example with
lsof -i :1455on macOS or Linux.
If none of that helps, use codex login --device-auth. Direct codex login runs write a codex-login.log file that support may ask for.
For the full first-time setup see how to install Codex and sign in. A 403 during login is covered in Codex token exchange failed, and other messages are in the OpenAI and Codex error codes list.
The matching Claude Code login error
Claude Code hits the same wall in WSL2, SSH sessions and containers: the browser signs you in, then shows a connection error for a localhost address. According to the Claude Code troubleshooting docs, you don’t need to fix the network:
- at the login prompt, press
cto copy the login URL (withclaude auth login, copy the URL it prints); - open it in a local browser and sign in; the page shows a code instead of returning to localhost;
- paste the code at the prompt that begins
Paste code here.
If Claude Code can’t open its local port at all, it stops with:
Couldn't start the local listener that receives the browser sign-in. Try again.
The docs say to run the command again first. If it fails the same way, run claude setup-token on a machine where sign-in works and set the printed token as CLAUDE_CODE_OAUTH_TOKEN on this machine. More fixes are in the Claude Code error list.
FAQ
Device code login says it isn’t available
Check that device code login is turned on in your ChatGPT security settings or workspace permissions. Otherwise use the SSH tunnel or copy auth.json.
Does API key login have this problem?
No. printenv OPENAI_API_KEY | codex login --with-api-key skips the browser, but usage is billed at API rates instead of your ChatGPT plan.