Codex Login Issue Resolution

This page is machine-translated and may contain errors. Read the Chinese original

Basic Information:

  1. System environment: Linux desktop
  2. Application: Codex desktop
  3. Proxy tool: Clash Verge
  4. Port number: 7897
  5. Network prerequisite: The browser can access ChatGPT normally, and IPv6 has been disabled.

Problem symptom

The browser can access ChatGPT, which means the network itself is available.
However, the Codex desktop app is based on Electron, and the token exchange request in its login flow does not go through the proxy. As a result, the OpenAI server sees a local IP address, determines that it is from an unsupported country/region, and returns 403 Forbidden.

Solution

Resolve the issue by applying two configurations at the same time:

Configure ~/.codex/.env

Check whether the relevant file exists; if not, create it.

1
2
mkdir -p ~/.codex
vim ~/.codex/.env

Write the following content, making sure to use your actual port number.

1
2
3
4
HTTP_PROXY=http://127.0.0.1:7897 //Codex 的 HTTP/HTTPS 请求走代理
HTTPS_PROXY=http://127.0.0.1:7897
ALL_PROXY=socks5://127.0.0.1:7897 //部分请求可能只读取 ALL_PROXY,因此一并设置。
NO_PROXY=localhost,127.0.0.1,::1 //确保 localhost、127.0.0.1、::1 不走代理,避免 OAuth 本地回调失败

Configure Electron proxy parameters

Check whether the relevant file exists; if not, create it.

1
2
mkdir -p ~/.config/Codex
vim ~/.config/Codex/electron-flags.conf

Write the following content, making sure to use your actual port number.

1
2
--proxy-server=http://127.0.0.1:7897 # 强制 Electron 外壳层使用代理。
--proxy-bypass-list=localhost;127.0.0.1;<-loopback> # 绕过本地地址,保证登录回调可以正常完成

If the configuration directory used by Codex on this machine is not ~/.config/Codex, check whether it is a corresponding directory such as ~/.config/codex-desktop-linux.

Restart Codex

Restart Codex and log in again. The problem should no longer occur, and you should be able to log in normally.