2:59
When using Codex Desktop, you probably often encounter the following situation:

Almost every time, it only gives a response after 5 reconnection attempts. These 5 reconnections make everyone wait too long and are a complete waste of time.
The reason is that after the new version upgrade of Codex Desktop (the specific version is unknown), the default connection method was changed to the WebSocket protocol. When this fails to connect, it shows up directly in the logs as a WebSocket handshake timeout.
Why does this happen? Because Codex Desktop is a desktop application, it doesn't automatically inherit system proxies like a browser does. When it starts, it needs to explicitly read environment variables like HTTP_PROXY and HTTPS_PROXY to use a proxy. If these variables aren't set, it assumes it can connect directly, resulting in no response for a long time and entering a reconnection loop.
Taking macOS as an Example
- Enter the following command in the terminal to view proxy information:
1scutil --proxy

The image above shows that the proxy ports for both http and https are 6152. You can manually create or edit the existing ~/.codex/.env file and write the proxy variables.
1HTTP_PROXY=http://127.0.0.1:61522HTTPS_PROXY=http://127.0.0.1:6152
After editing ~/.codex/.env and saving it, quit Codex Desktop and reopen it to solve this problem.
If you don't want to do it manually, you can use the following Prompt and send it to Codex:
1Help me fix the issue where Codex Desktop keeps Reconnecting.23Please locate the proxy port and proxy protocol currently being used on my machine, then create or update ~/.codex/.env and write the following proxy configuration. Do not hardcode the port; please replace it with the actual port. If the file already exists, keep other configurations.45HTTP_PROXY="http://127.0.0.1:<HTTP or mixed port>"6HTTPS_PROXY="http://127.0.0.1:<HTTP or mixed port>"78After writing, check if the configuration is correct and tell me how I need to restart Codex Desktop.
Of course, you can also try my one-click automation script (macOS only):
1#!/bin/bash2# Detect macOS system proxy and update ~/.codex/.env34ENV_DIR="$HOME/.codex"5ENV_FILE="$ENV_DIR/.env"67# Read system proxy configuration8proxy_info=$(scutil --proxy)910http_enabled=$(echo "$proxy_info" | awk '/HTTPEnable/{print $3}')11http_host=$(echo "$proxy_info" | awk '/HTTPProxy/{print $3}')12http_port=$(echo "$proxy_info" | awk '/HTTPPort/{print $3}')1314https_enabled=$(echo "$proxy_info" | awk '/HTTPSEnable/{print $3}')15https_host=$(echo "$proxy_info" | awk '/HTTPSProxy/{print $3}')16https_port=$(echo "$proxy_info" | awk '/HTTPSPort/{print $3}')1718# Build proxy URLs19http_proxy=""20https_proxy=""2122if [[ "$http_enabled" == "1" && -n "$http_host" && -n "$http_port" ]]; then23 http_proxy="http://${http_host}:${http_port}"24fi2526if [[ "$https_enabled" == "1" && -n "$https_host" && -n "$https_port" ]]; then27 https_proxy="http://${https_host}:${https_port}"28fi2930# If neither HTTP nor HTTPS proxy is found31if [[ -z "$http_proxy" && -z "$https_proxy" ]]; then32 echo "❌ No system proxy detected; no proxy settings applied."33 exit 034fi3536# If HTTPS is not set separately, reuse HTTP proxy37if [[ -n "$http_proxy" && -z "$https_proxy" ]]; then38 https_proxy="$http_proxy"39fi4041echo "✅ System proxy detected:"42[[ -n "$http_proxy" ]] && echo " HTTP_PROXY=$http_proxy"43[[ -n "$https_proxy" ]] && echo " HTTPS_PROXY=$https_proxy"4445# Ensure directory exists46mkdir -p "$ENV_DIR"4748# If .env file doesn't exist, create it49if [[ ! -f "$ENV_FILE" ]]; then50 {51 [[ -n "$http_proxy" ]] && echo "HTTP_PROXY=$http_proxy"52 [[ -n "$https_proxy" ]] && echo "HTTPS_PROXY=$https_proxy"53 } > "$ENV_FILE"54 echo "📄 Created $ENV_FILE and wrote proxy configuration."55 exit 056fi5758# File exists, update or append59update_or_append() {60 local key="$1" value="$2"61 if grep -q "^${key}=" "$ENV_FILE"; then62 sed -i '' "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"63 echo "🔄 Updated ${key}"64 else65 echo "${key}=${value}" >> "$ENV_FILE"66 echo "➕ Appended ${key}"67 fi68}6970[[ -n "$http_proxy" ]] && update_or_append "HTTP_PROXY" "$http_proxy"71[[ -n "$https_proxy" ]] && update_or_append "HTTPS_PROXY" "$https_proxy"7273echo "✅ $ENV_FILE update complete."
Want to get started with AI quickly but don't know where to begin?
AI Spark has organized a free AI knowledge base covering AI basics, knowledge base construction, workflow applications, mainstream AI tools, Obsidian, Codex, Skill, and Prompt practice.
Free Knowledge Base:





![[Вибачення та вдячність] Переосмислення цінності офісу в епоху ШІ](/cdn-cgi/image/width=1920,quality=90,format=auto,metadata=none/https%3A%2F%2Fcms-assets.youmind.com%2Fmedia%2F1784654487214_c56a6p_HNr6-znbwAAQJbv.jpg)
