Codex VS Code extension cannot authenticate when running on Remote SSH

Resolved 💬 15 comments Opened Dec 17, 2025 by RuihanCao Closed Mar 11, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the VS Code extension are you using?

Latest version from VS Code Marketplace as of today (auto-updated)

What subscription do you have?

ChatGPT Plus

Which IDE are you using?

Cursor

What platform is your computer?

Local: Windows 11 x64 Remote: Linux (SSH / container on AutoDL GPU node)

What issue are you seeing?

When I tried to sign in to the Codex extension while it is running on a Remote SSH, authentication fails.

After completing authentication using the verification code flow, the browser redirects to a page that shows:

“Token exchange failed: token endpoint returned status 403 Forbidden”

This occurs only when the Codex extension is enabled on the remote host.
Local sign-in works correctly.

What steps can reproduce the bug?

  1. Connect to a Remote SSH / container environment.
  2. Enable or install the Codex VS Code extension on the remote host.
  3. Trigger the Codex sign-in flow.
  4. Complete authentication using the verification code in the browser.

Result:
The sign-in flow fails and the browser shows:
“Token exchange failed: token endpoint returned status 403 Forbidden”.

What is the expected behavior?

The Codex extension should successfully complete authentication when running on a Remote SSH.

Additional information

_No response_

View original on GitHub ↗

15 Comments

github-actions[bot] contributor · 7 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #6413
  • #7623
  • #6628
  • #6849
  • #6632

Powered by Codex Action

RuihanCao · 7 months ago

For additional context: I looked through the suggested duplicate issues, which appear to focus on WSL-specific behavior.

In my case, the Codex extension is running on a Remote SSH rather than WSL. I also tried one of the suggested solutions there, setting chatgpt.runCodexInWindowsSubsystemForLinux = false but this did not change the behavior.

etraut-openai contributor · 7 months ago

We have recently added support for headless device code authentication. This is still in preview mode, but it's ready for use. See here for instructions. This authentication mechanism is specifically designed to handle cases where you're on a remote server or other environment that cannot receive a redirect from a browser running locally.

RuihanCao · 7 months ago

Thanks for the update. I tried the new headless device code authentication flow.

However, after I run:
codex login --device-auth

The request fails with:
“Error logging in with device code: device code request failed with status 403 Forbidden”

edzwu · 7 months ago

If the remote ssh is wsl, my solution is logging in host machine (windows I mean), then copy the auth file to ~/.codex/, like cp /mnt/c/Users/your own user name/.codex/auth.json ~/.codex/ This command works for me

sorbicacid · 6 months ago
If the remote ssh is wsl, my solution is logging in host machine (windows I mean), then copy the auth file to ~/.codex/, like cp /mnt/c/Users/your own user name/.codex/auth.json ~/.codex/ This command works for me

works for me

RuihanCao · 6 months ago

It's not wsl, that method does not work for me.

meloncockatiel · 6 months ago

I have same problem as you. I'm using VSCode to SSH into my server (Ubuntu 24.04.1) and using the CodeX plugin, but the callback authentication fails at the end of the login process. "http://localhost:1455/auth/callback?code=..." displays "Token exchange failed: token endpoint returned status 403 Forbidden".
I also tried some suggested solutions such as copying the auth.json file from my local Windows to the server. This allowed me to log in, but it gets stuck at the thinking step.
Have you solved this yet?

ChrisLauVI · 5 months ago

same

yxq477 · 5 months ago

I’m using VS Code. Changing Proxy to Global fixed the issue for me. 盲猜是启动的 local server (1455 端口的服务)和外网通讯的时候出问题了。

RuihanCao · 5 months ago
I have same problem as you. I'm using VSCode to SSH into my server (Ubuntu 24.04.1) and using the CodeX plugin, but the callback authentication fails at the end of the login process. "http://localhost:1455/auth/callback?code=..." displays "Token exchange failed: token endpoint returned status 403 Forbidden". I also tried some suggested solutions such as copying the auth.json file from my local Windows to the server. This allowed me to log in, but it gets stuck at the thinking step. Have you solved this yet?

Same, I was able to login after copying the auth.json file from my local Windows to the server, but now it gets stuck at the thinking step. Were you able to solve that?

justinTM · 5 months ago

still an issue. they say "close this feature request because the functionality is now in place" ~2798 but localhost port is hardcoded to use the same one as VS Code Remote SSH:

❯ codex login       
Error logging in: Port 127.0.0.1:1455 is already in use
❯ lsof -nP -iTCP:1455 -sTCP:LISTEN
COMMAND    PID   USER   FD   TYPE     DEVICE       SIZE/OFF NODE NAME
Code\x20H 5393   me       42u  IPv4   0xxxxxxxxx        0t0    TCP   127.0.0.1:1455 (LISTEN)

^^ that's on local machine, to copy auth.json to remote manually. if you try to sign in via the Codex extension on the remote, it hangs indefinitely in the browser waiting for localhost redirect (which will never happen since it needs the remote).

UTF-z · 5 months ago

I ran into exactly the same issue. From what I can tell, the token exchange request is sent from the remote machine, and the 403 error happens because those remote requests are not properly going through a proxy. This doesn’t appear to be a Codex bug itself.

My solution was to correctly configure a proxy on the remote side and make sure that both the remote VS Code server and the extension’s HTTP requests go through that proxy.

Configure VS Code so remote extensions use the proxy

  1. In VS Code settings, set Http: Proxy to your local proxy address.
  2. Add localhost, 127.0.0.1, and ::1 to Http: No Proxy.
  3. Set Http: Proxy Support to On.
  4. Switch to Remote settings and enable Http: Use Local Proxy Configuration.

Set up reverse port forwarding on the remote to reach the local proxy

  1. When connecting to the remote host via SSH in VS Code, use a command like:

``bash
ssh -R <remote_proxy_port (same as local proxy port)>:<local_proxy_ip>:<local_proxy_port> user@ip -p port
``

  1. The SSH config entry auto-generated by VS Code may be incorrect. For example:

``text
Host ip
HostName ip
RemoteForward 7897:127.0.0.1:7897
User user
Port port
`
You need to change
RemoteForward 7897:127.0.0.1:7897
to
RemoteForward 7897 127.0.0.1:7897`.

  1. Reconnect to the remote host. After that, Codex should be able to log in normally.
Weigaa · 5 months ago

@UTF-z I met the same problem, and I use your method to partially solve the 403 error, but there is an important issue is that if you already baned 127.0.0.1,localhost, in your vpn settings such as clash, you must do not set "Add localhost, 127.0.0.1, and ::1 to Http: No Proxy." Otherwise, your vscode IDE will be broken.

I also use docker in the remote server, the codex also ran smoothly in docker env.

hxflyer · 4 months ago

Spend me a while to get it work, almost give up. here is the solution:
1 In your remote ssh vscode window, click login in button of the codex extention, it will open local browser and jump to a login page.
2 Copy the link from local browser, open vscode integrated browser in your remote vscode window ( https://code.visualstudio.com/docs/debugtest/integrated-browser )
3 Paste the login link to the integrated browser in your remote vscode
4 Input username , password, login, click next.. next...
5 Done!