Skip to content

安装 Codex

安装 CLI

Windows / Linux

Windows 在 cmder 或者 git bash 中执行以下命令:

bash
npm i -g @openai/codex@latest

VSCode 安装插件

直接搜索 @id:openai.chatgpt 安装即可。

如果是用 Remote SSH 连接到远程 Linux 服务器,有时候安装时会出现问题,可以在远程服务器上写入并运行下面的脚本:

install_vsc_codex.sh
sh
#!/usr/bin/env bash
set -euo pipefail

EXT="${1:-openai.chatgpt}"
VSCODE_ROOT="${VSCODE_AGENT_FOLDER:-$HOME/.vscode-server}"

echo "[info] user: $(id -un)"
echo "[info] home: $HOME"
echo "[info] vscode root: $VSCODE_ROOT"
echo "[info] extension: $EXT"

if [[ ! -d "$VSCODE_ROOT" ]]; then
  echo "[error] VS Code Server root not found: $VSCODE_ROOT" >&2
  echo "[error] Open this host once with VS Code Remote SSH first." >&2
  exit 1
fi

echo "[1/4] Find Microsoft VS Code Server code-server binary..."

CODE_SERVER="$(
  find "$VSCODE_ROOT" \
    -type f \
    \( -path '*/server/bin/code-server' -o -path '*/bin/code-server' \) \
    2>/dev/null \
    | sort \
    | tail -n 1
)"

if [[ -z "${CODE_SERVER}" ]]; then
  echo "[error] Cannot find code-server under: $VSCODE_ROOT" >&2
  echo "[debug] Existing files:" >&2
  find "$VSCODE_ROOT" -maxdepth 6 -type f -name 'code*' 2>/dev/null | sort | tail -n 50 >&2
  exit 1
fi

echo "[info] code-server: $CODE_SERVER"

EXT_DIR="$VSCODE_ROOT/extensions"
mkdir -p "$EXT_DIR"

echo "[2/4] Install extension into remote VS Code Server..."
"$CODE_SERVER" \
  --install-extension "$EXT" \
  --extensions-dir "$EXT_DIR" \
  --force

echo "[3/4] Verify extension list..."
"$CODE_SERVER" \
  --list-extensions \
  --show-versions \
  --extensions-dir "$EXT_DIR" \
  | grep -i '^openai\.chatgpt' || {
    echo "[warn] openai.chatgpt not found in code-server extension list"
  }

echo "[4/4] Extension directory:"
find "$EXT_DIR" -maxdepth 1 -type d -iname 'openai.chatgpt*' -print -exec du -sh {} \; 2>/dev/null || true

echo "[done]"

登录

Token exchange failed: token endpoint returned status 403 Forbidden · Issue #2414 · openai/codex

https://github.com/openai/codex/issues/2414

Windows

直接在 cmder 命令行运行:

bash
codex

登录好后,登录信息会保存在:C:\Users\<Username>\.codex\auth.json

Linux 的在:~/.codex/auth.json

VSCode 插件登录

在 CLI 登录后,默认就是登录状态了。

Linux 登录

可以考虑在 VSCode 插件中登录。或者复制 auth.json 到 Linux 的 ~/.codex/auth.json 中。

如果在 VSCode 中在远程服务器的插件中登录了,那么默认就是登录状态了。

MCP 服务

Playwright

需要 npx 安装 Playwright :

sh
npx -y playwright@latest install chromium

需要在 config.toml 中添加:

sh
[mcp_servers.playwright]
command = "npx"
args = ["-y", "@playwright/mcp@latest"]
startup_timeout_sec = 60
tool_timeout_sec = 300

Playwright 启动问题

下面的方法实测似乎无效。重新运行上面的安装 playwright 的命令,然后重启 Codex 的 VSCode 插件 或者 CLI ,问题就解决。

如果遇到启动问题,可以在后台启动 Playwright MCP 服务:

sh
npx -y @playwright/mcp@latest --port 28931

然后配置修改为:

sh
[mcp_servers.playwright]
url = "http://localhost:28931/mcp"
startup_timeout_sec = 30
tool_timeout_sec = 300

Codex Apps

启动时会报错。实际上也用不着,因此可以禁用。

config.toml 中添加:

sh
[features]
apps = false

配置和环境样例

  • Windows: C:\Users\<Username>\.codex
  • Linux: ~/.codex
config.toml
toml
model = "gpt-5.5"
model_reasoning_effort = "medium"

[mcp_servers.playwright]
command = "npx"
args = ["-y", "@playwright/mcp@latest"]
startup_timeout_sec = 60
tool_timeout_sec = 300

[features]
apps = false

[tui.model_availability_nux]
"gpt-5.5" = 4
.env
env
https_proxy="http://127.0.0.1:11119" 
http_proxy="http://127.0.0.1:11119"
all_proxy="http://127.0.0.1:11119"
no_proxy="localhost,127.0.0.1"