Fastest path: in the same terminal where you start codex, set HTTPS_PROXY to point at your local proxy (HTTP, not socks5), verify connectivity with curl against api.openai.com, then run codex again. Nine out of ten reconnect issues are solved at this step.
Step 1: 30-second diagnosis — network or bug?
Reconnecting means the connection between Codex and OpenAI (a WebSocket / SSE stream) failed to establish or stay alive. Run this quick check before trying anything else:
# Can you reach OpenAI directly? A 401 means the connection works — just no key attached.
$ curl -I https://api.openai.com/v1/models
# Now test through your proxy
$ curl -I -x http://127.0.0.1:7890 https://api.openai.com/v1/models
- Both time out / connection refused → Network problem. Focus on the "Proxy" section below.
- Direct times out, proxy returns 401/200 → The proxy works but Codex isn't using it. See "Proxy not working".
- Both return 401 but codex still reconnects → Likely an auth conflict or version bug. Jump to those sections.
Cause 1: no proxy or wrong proxy (most common outside the US)
Networks that block OpenAI directly will cause Codex to reconnect endlessly the moment it starts. The fix is to route Codex through a proxy — it reads standard proxy environment variables:
export HTTPS_PROXY="http://127.0.0.1:7890"
export HTTP_PROXY="http://127.0.0.1:7890"
export ALL_PROXY="http://127.0.0.1:7890"
After editing, run source ~/.zshrc (or reopen the terminal) and then launch codex. Match the port to your proxy client: Clash commonly uses 7890, some clients use 7897.
To avoid touching the global environment, prefix the command inline: HTTPS_PROXY=http://127.0.0.1:7890 codex. Or put the three lines in a .env file inside ~/.codex/. For a full proxy walkthrough see Proxy & restricted networks.
Proxy configured but still not working?
- Confirm you set the variable and launched
codexin the same terminal session — a new terminal won't inherit a temporaryexport. - Check for a lowercase variable (
https_proxy) overriding your setting:env | grep -i proxy. - On corporate networks, make sure a
NO_PROXYallowlist isn't excluding the relevant domains.
Cause 2: socks5 proxy (Codex doesn't support it)
A very common trap: Codex does not support socks5 proxies. If your ALL_PROXY is set to socks5://..., connections will fail silently and Codex will loop on Reconnecting. Switch to the HTTP port exposed by your proxy client, or use a tool to convert socks5 to HTTP:
# ✗ Don't use this
export ALL_PROXY="socks5://127.0.0.1:7891"
# ✓ Use the HTTP port instead (most clients expose both)
export HTTPS_PROXY="http://127.0.0.1:7890"
Cause 3: OAuth and API key both present (auth conflict)
When you have both signed in with a ChatGPT account (OAuth) and have OPENAI_API_KEY set in the environment, the two auth mechanisms coexist in an unstable way and can cause erratic reconnects. Clear one of them and re-authenticate:
- Sign out and clear cached credentials:
$ codex logout $ rm -f ~/.codex/auth.json $ unset OPENAI_API_KEY - Pick one auth method and sign back in — ChatGPT account:
codex login; or API key only:codex login --with-api-key. - Run
codexagain and send a simple message to confirm everything works.
Cause 4: VS Code extension / WSL2 networking
Reconnecting inside an editor or WSL often has a different root cause from the terminal — the two environments use separate network configurations:
VS Code extension keeps Reconnecting
The extension doesn't read your terminal's export — you must configure the proxy in VS Code's own settings: press Ctrl+, to open settings, search for proxy, set Http: Proxy to http://127.0.0.1:7890, then fully restart VS Code.
Windows + WSL2 can't connect
The codex process running inside WSL2 does not automatically use the Windows system proxy. Two approaches:
- Enable mirrored networking in WSL2: this makes WSL share the Windows loopback, so the proxy port becomes reachable. In
%USERPROFILE%\.wslconfigadd[wsl2]/networkingMode=mirrored, then runwsl --shutdownand reopen WSL. - Remember that socks5 is unsupported inside WSL2 as well — use the HTTP proxy port there too.
Cause 5: version bug or frozen session
If network and auth are ruled out and Codex still reconnects or freezes on Working, it's likely a known issue in a specific build. Handle in priority order:
- Close all sessions and restart as a single instance (the most effective community fix): press
Ctrl+Cto terminate all codex processes, wait about 60 seconds for a full exit, open exactly one new session, and sendHELLOto confirm recovery. - Upgrade to the latest version:
$ npm install -g @openai/codex@latest $ codex --version # Homebrew users: brew upgrade codex - Check MCP servers: a misbehaving MCP server can drag down the connection. Temporarily comment out any suspicious
[mcp_servers.*]entries in~/.codex/config.toml, or toggleexperimental_use_rmcp_client. - Submit diagnostics: run
/feedbackinside a session — it attaches the request ID, error log, and connection snapshot, helping the team pin down the issue.
Last resort: clean reinstall
If nothing above works, do a clean reinstall (this clears your login — you'll need to sign in again):
$ npm uninstall -g @openai/codex
$ npm install -g @openai/codex@latest
# Optional: wipe config and credentials (use with caution)
$ rm -rf ~/.codex
Once you see ● connected — gpt-5.3-codex, everything is back to normal. Add the proxy exports to ~/.zshrc to persist them across reboots.
Frequently asked questions
Is my account banned or missing permissions?
Rarely. Permission or quota problems typically return a clear 401 or 429 error rather than a silent reconnect loop. First test connectivity with curl, then check the error lookup table for specific error codes.
I switched to HTTP proxy and it's still not working?
Confirm the export and the codex launch happened in the same terminal. Run curl -x http://127.0.0.1:PORT -I https://api.openai.com/v1/models to verify this port actually exits to the internet. Also check whether a NO_PROXY variable or a lowercase duplicate (https_proxy) is overriding your setting.
How do I make the proxy permanent so I don't have to export it every time?
Add the three export lines to ~/.zshrc (or ~/.bashrc) and they'll be active in every new terminal. On Windows, add HTTPS_PROXY as a system environment variable.