Got the fix.
How to Fix Codex Sign-In on VS Code with WSL2 (localhost:1455 errors)
I was stuck with ERR_CONNECTION_REFUSED, Invalid Session, and State mismatch errors when trying to sign in to Codex in VS Code with WSL2. After a lot of trial and error, here’s the full solution that worked for me.
Steps
1. Install Firefox inside WSL2
By default, Ubuntu on WSL2 doesn’t ship with a browser. Codex login requires one inside WSL, because the login server listens on localhost:1455 inside WSL only.
Install Firefox via Snap:
sudo apt update
sudo apt install -y snapd
sudo snap install firefox
Don’t try to use Windows Firefox/Chrome here — they can’t reach WSL’s loopback server without extra networking hacks.
2. Start the Codex login flow
In your WSL2 terminal:
codex auth login
This starts a local server at http://localhost:1455 (inside WSL) and prints a long https://auth.openai.com/... URL.
Keep this terminal open — if you close it, the login server shuts down.
3. Open the login URL in Firefox (inside WSL2)
Open another WSL2 terminal and run:
firefox "https://auth.openai.com/..."
-
Paste the full URL from the
codex auth loginoutput. -
Quote the URL (
"...") so bash doesn’t split on spaces. -
If you see spaces in the URL (e.g.
scope=openid profile email ...), replace them with%20.
This will launch Firefox through WSLg (GUI apps on Windows 11), and the redirect to localhost:1455 will correctly reach Codex’s listener.
4. Complete the sign-in
-
Log into your OpenAI account.
-
Approve access.
-
You should see either:
-
A browser success page: “Signed in to Codex”, or
-
The CLI prints:
Successfully logged in
-
If you see “Invalid Session” or “State mismatch”:
-
Don’t reuse old URLs.
-
Restart with a fresh
codex auth login. -
Clear cookies for
auth.openai.comin Firefox if needed.
5. Reload VS Code
Back in VS Code (Remote-WSL):
-
Run
Ctrl+Shift+P → Reload Window. -
The Codex extension should now show you as signed in.
If it still says “Sign in with ChatGPT”:
codex auth whoami # should print your account
codex auth logout
codex auth login # then redo the Firefox step
Notes
-
If you install Codex extension on Windows VS Code instead of WSL, you must log in on the Windows side (
codex auth loginin PowerShell/CMD) and may need URL ACLs:netsh http add urlacl url=http://localhost:1455/ user=%USERNAME% netsh http add urlacl url=http://localhost:1455/auth/callback/ user=%USERNAME% -
For most people, the cleanest way is do everything inside WSL2 using Linux Firefox installed via Snap.
TL;DR
-
sudo apt install snapd && sudo snap install firefox -
Run
codex auth loginin WSL2 (keep terminal open). -
In another WSL2 terminal:
firefox "https://auth.openai.com/..." -
Complete login → see “Signed in to Codex”.
-
Reload VS Code window.