When using VS Code Remote SSH to connect to a remote server and log in to Codex, many users encounter the following issues:
Token exchange failed: token endpoint returned status 403 Forbidden- Login is successful, but the plugin remains stuck on "Thinking…"
In most cases, these issues are not caused by the plugin itself but by restricted network access on the remote server.
This article provides a set of feasible solutions applicable when:
- The server cannot directly access external network services.
- The local network environment is normal.
- SSH can be used for port forwarding.
I. Root Cause of the Problem
This issue is typically caused by one of the following:
- The remote server cannot access the authentication interface.
- The server's network proxy is not configured or is incomplete.
- VS Code Server did not inherit the local network environment.
Simply put: the authentication request is sent, but the server cannot get the correct response.
II. Overall Solution Strategy
The core solution strategy is as follows:
- Complete the login authentication locally.
- Synchronize the authentication information to the server.
- Use SSH for port forwarding.
- Configure proxy environment variables on the server.
- Restart VS Code Server.
III. Complete Codex Login Locally
⚠️ Note: This step must be performed under normal local network conditions.
Steps:
- Open VS Code locally (do not connect to the remote server).
- Install the Codex plugin.
- Complete the login process.

After successful login, an authentication directory will be generated:
C:\Users\\.codex

IV. Copy Authentication Information to the Server
Copy the .codex folder to the server:
scp -r C:\Users\\.codex user@server:~/ After copying, ensure the server directory is:
~/.codexThen reconnect via SSH.
At this point, the remote environment should typically recognize the login status.
V. Configure SSH Port Forwarding (Crucial Step)
If the server cannot directly access the external network, you need to use local network forwarding.
Open the SSH configuration file:
~/.ssh/configAdd to the corresponding host configuration:
RemoteForward 7897 127.0.0.1:7897Explanation:
7897is the local proxy port (must be consistent with your local setup)Common ports:
- Clash: 7890 / 7897
- SOCKS: 1080
Reconnect SSH after configuration is complete.
VI. Configure Server Proxy Environment Variables
Edit the server's
~/.bashrc:export HTTP_PROXY=http://127.0.0.1:7897
export HTTPS_PROXY=http://127.0.0.1:7897
export ALL_PROXY=http://127.0.0.1:7897Make the configuration effective:
source ~/.bashrcVII. Restart VS Code Remote Server
Execute in VS Code:
Ctrl + Shift + PEnter and select:
Remote-SSH: Kill VS Code Server on HostThen reconnect to the server
(Insert image: VS Code Command Palette screenshot)
VIII. Verify Proxy Effectiveness
Execute on the server:
curl -v --proxy http://127.0.0.1:7897 https://chat.openai.comIf normal HTTP information is returned, the forwarding is successful.
IX. Principle Analysis (Simple Understanding)
The entire process is essentially:
```htmlServer Request
↓
SSH RemoteForward
↓
Local 127.0.0.1:7897
↓
Local Proxy Tool
↓
Access External Service InterfaceIn other words:
The server is borrowing your local network capabilities
X. Summary
If you encounter:
- 403 Token Error
- Codex keeps Thinking
You can troubleshoot using this process:
✔ Log in locally first
✔ Sync.codex
✔ Configure SSH forwarding
✔ Set proxy environment variables
✔ Restart VS Code ServerThis should basically solve the problem.
```END本文标题:VS Code Remote SSH Login Codex 403 / Stuck on Thinking Solution (Tested and Works)
本文链接:https://www.imsuk.cn/archives/246/?lang=en
除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议。
声明:转载请注明文章来源。
Last modification:April 12, 2026© Allow specification reprint