One Simple Trick to Fix Codex Desktop Reconnecting 5 Times

@jinglian
СПРОЩЕНА КИТАЙСЬКА2 місяці тому · 06 черв. 2026 р.
500K
883
151
54
2.2K

Коротко

This article explains how to fix Codex Desktop's WebSocket handshake timeout by correctly setting HTTP and HTTPS proxy environment variables in the application's configuration file.

前端哥Liam - inline image

2:59

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

前端哥Liam - inline image

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

  1. Enter the following command in the terminal to view proxy information:
text
1scutil --proxy
前端哥Liam - inline image

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.

text
1HTTP_PROXY=http://127.0.0.1:6152
2HTTPS_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:

text
1Help me fix the issue where Codex Desktop keeps Reconnecting.
2
3Please 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.
4
5HTTP_PROXY="http://127.0.0.1:<HTTP or mixed port>"
6HTTPS_PROXY="http://127.0.0.1:<HTTP or mixed port>"
7
8After 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):

bash
1#!/bin/bash
2# Detect macOS system proxy and update ~/.codex/.env
3
4ENV_DIR="$HOME/.codex"
5ENV_FILE="$ENV_DIR/.env"
6
7# Read system proxy configuration
8proxy_info=$(scutil --proxy)
9
10http_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}')
13
14https_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}')
17
18# Build proxy URLs
19http_proxy=""
20https_proxy=""
21
22if [[ "$http_enabled" == "1" && -n "$http_host" && -n "$http_port" ]]; then
23 http_proxy="http://${http_host}:${http_port}"
24fi
25
26if [[ "$https_enabled" == "1" && -n "$https_host" && -n "$https_port" ]]; then
27 https_proxy="http://${https_host}:${https_port}"
28fi
29
30# If neither HTTP nor HTTPS proxy is found
31if [[ -z "$http_proxy" && -z "$https_proxy" ]]; then
32 echo "❌ No system proxy detected; no proxy settings applied."
33 exit 0
34fi
35
36# If HTTPS is not set separately, reuse HTTP proxy
37if [[ -n "$http_proxy" && -z "$https_proxy" ]]; then
38 https_proxy="$http_proxy"
39fi
40
41echo "✅ System proxy detected:"
42[[ -n "$http_proxy" ]] && echo " HTTP_PROXY=$http_proxy"
43[[ -n "$https_proxy" ]] && echo " HTTPS_PROXY=$https_proxy"
44
45# Ensure directory exists
46mkdir -p "$ENV_DIR"
47
48# If .env file doesn't exist, create it
49if [[ ! -f "$ENV_FILE" ]]; then
50 {
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 0
56fi
57
58# File exists, update or append
59update_or_append() {
60 local key="$1" value="$2"
61 if grep -q "^${key}=" "$ENV_FILE"; then
62 sed -i '' "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
63 echo "🔄 Updated ${key}"
64 else
65 echo "${key}=${value}" >> "$ENV_FILE"
66 echo "➕ Appended ${key}"
67 fi
68}
69
70[[ -n "$http_proxy" ]] && update_or_append "HTTP_PROXY" "$http_proxy"
71[[ -n "$https_proxy" ]] && update_or_append "HTTPS_PROXY" "$https_proxy"
72
73echo "✅ $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:

https://lcnniolukk80.feishu.cn/wiki/space/7644091204958866380?ccm_open_type=lark_wiki_spaceLink&open_tab_from=wiki_home

Збереження в один клік

Використовуйте YouMind для AI-глибокого читання віральних статей

Зберігайте джерела, ставте цілеспрямовані запитання, підсумовуйте аргументи та перетворюйте віральні статті на корисні нотатки в одному AI-робочому просторі.

Дослідити YouMind
Для авторів

Перетворіть свій Markdown на охайну статтю для 𝕏

Коли ви публікуєте власні лонгріди, зображення, таблиці та блоки коду роблять форматування в 𝕏 складним. YouMind перетворює повну чернетку в Markdown на чисту статтю для 𝕏, готову до публікації.

Спробувати Markdown для 𝕏

Більше патернів для аналізу

Останні віральні статті

Переглянути більше віральних статей