codex icon indicating copy to clipboard operation
codex copied to clipboard

codex auth login fails with "Port 127.0.0.1:1455 is already in use" on WSL

Open guluarte opened this issue 1 year ago • 15 comments

What version of Codex is running?

codex-cli 0.39.0

Which model were you using?

No response

What platform is your computer?

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64, Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

codex auth login

What is the expected behavior?

The codex auth login command should successfully initiate the authentication process, typically by opening a browser window or providing a URL for the user to visit and authenticate with their OpenAI account. It should not report port conflicts or timeouts.

What do you see instead?

Failed to cancel previous login server: connection timed out Error logging in: Port 127.0.0.1:1455 is already in use

Additional information

[wsl2] memory=32GB processors=6 swap=12GB swapfile=C:\temp\wsl-swap.vhdx networkingMode=mirrored [experimental] hostAddressLoopback=true

netstat -ano | findstr :1455 and lsof -i :1455 return nothing running on these ports.

guluarte avatar Sep 19 '25 16:09 guluarte

I encountered the same issue. Until the official fix is released, you can temporarily work around it using the following method:

  1. Follow the steps in the official document "Connecting on a headless machine" (https://github.com/openai/codex/blob/main/docs/authentication.md#connecting-on-a-headless-machine).
  2. Run codex auth login on the Windows host to complete the login (this will open a browser on Windows or provide an authorization URL).
  3. After successfully logging in, copy the auth.json file from Windows (usually located at %USERPROFILE%.codex) to the corresponding location in WSL (~/.codex/auth.json).
  4. Then run the codex command that requires authentication from within WSL.

This avoids the port conflict caused by starting a local callback server until the official fix is released.

litechenacc avatar Sep 21 '25 07:09 litechenacc

I ran into this on Mac with a Linux devcontainer running. Stopping the devcontainer fixed the issue and opened the login.

PS OpenAI, can we be a bit more graceful with the updates breaking authorization? My existing conversations just got 401'd after returning from the weekend.

tcare avatar Sep 22 '25 05:09 tcare

I experienced the same error on Mac. I was using my local environment, instead of a virtual environment.

The cause was that I already had the Codex extension running on VS Code. Closing VS Code solved the issue.

Yusuke196 avatar Sep 23 '25 02:09 Yusuke196

so how????????

DWDROME avatar Oct 07 '25 16:10 DWDROME

I was also getting this error on windows "An Attempt Was Made to Access a Socket in a Way Forbidden by Its Access Permissions’ (OS Error 10013)"

this fixed both errors on my end

net stop winnat
net start winnat

guluarte avatar Oct 09 '25 20:10 guluarte

I run multiple devcontainer environment. Codex try to use 1455 port, but if not available, vscode automatically forward it to 1456, 1457... And It cause problem.

Manual auth token prompt should be added.

Image

ryush00 avatar Oct 12 '25 08:10 ryush00

Would be nice if we could specify, or be prompted for, an available port to avoid having to shut down vscode when using the cli.

kpb avatar Nov 05 '25 16:11 kpb

netsh interface ipv4 show excludedportrange protocol=tcp

Same here (os error 10013), I fixed it by ➝

net stop winnat
net start winnat

TosakaWolf avatar Nov 07 '25 20:11 TosakaWolf

I tried to log into Codex CLI on two VS Code devcontainers at the same time as well as outside of the devcontainers and got this error.

alexsapps avatar Nov 09 '25 08:11 alexsapps

Closing stale bugs.

If you run into this condition, it's likely related to your local network configuration (firewalls, VPNs, etc.).

As a workaround, you can use our headless device login mechanism.

etraut-openai avatar Jan 10 '26 02:01 etraut-openai

Root cause identified for mirrored networking mode users

If you're on WSL2 with networkingMode=mirrored in .wslconfig, the Windows IP Helper service (iphlpsvc) holds port 1455 at the OS level, making it unavailable to WSL even though nothing WSL-side is using it.

Diagnose from WSL:

powershell.exe -Command "Get-NetTCPConnection -LocalPort 1455 -ErrorAction SilentlyContinue | ForEach-Object { \$proc = Get-Process -Id \$_.OwningProcess -ErrorAction SilentlyContinue; Write-Host \"PID: \$(\$_.OwningProcess) Process: \$(\$proc.Name)\" }"
# Output: PID: 5356  Process: svchost

powershell.exe -Command "Get-WmiObject Win32_Service | Where-Object { \$_.ProcessId -eq 5356 } | Select-Object DisplayName"
# Output: IP Helper

Permanent fix — switch to NAT mode in C:\Users\<you>\.wslconfig:

[wsl2]
networkingMode=NAT

Then wsl --shutdown from PowerShell and reopen WSL. NAT mode still relays localhost from Windows to WSL, so dev server workflows are unaffected.

I solved by using the headless device login mechanism after changing to NAT.

talkingtoaj avatar Feb 24 '26 07:02 talkingtoaj

I've got an error when tried to login in Powershell. It's definitely a new bug because I didn't have this error before.

loglux avatar Apr 10 '26 12:04 loglux

I've met the same situation on mac when I have a codex running on Cursor which seemed to be conflict with the offcial codex client. Exit the original cursor codex then everything runs smoothly

Laaaaaang avatar Apr 15 '26 04:04 Laaaaaang

I ran into what looks like the same WSL issue and managed to get it working.

In my case the real problem was not an actual port conflict on 127.0.0.1:1455. The login flow from WSL could not launch the browser correctly, so the error was misleading and sent me in the wrong direction.

What fixed it for me was making sure the auth URL opens in the Windows browser, not inside the Linux side of WSL.

First, in VS Code / Kilo I had to make sure the external browser setting pointed to a real browser available on Windows. VS Code supports configuring the browser used for opening links via workbench.externalBrowser, instead of only relying on the system default.

Then on Ubuntu/WSL I installed wslu:

sudo apt update
sudo apt install wslu

After that I verified that WSL could open links in the Windows browser:

wslview https://example.com

Once that worked, the OpenAI login flow started working from WSL too. In my case I did not need extra port forwarding or localhost hacks after that.

So the workaround was basically:

  1. Make sure VS Code / Kilo is configured to use a valid Windows browser for external links.
  2. Install wslu in WSL so Linux-side link opening can forward into the Windows browser.
  3. Retry the login flow.

It might be worth teaching Codex to detect WSL and prefer wslview automatically when available. Right now the error points people toward port debugging, even when the real issue is just that WSL cannot launch the browser properly.

woleks avatar Apr 16 '26 08:04 woleks

when I close the cursor,the bug is fixed …

hhhheep avatar Apr 21 '26 09:04 hhhheep