Codex CLI 需要 Node.js 22 或更高版本:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs验证安装:
node --version
npm --version打开终端,运行以下命令:
npm install -g @openai/codexmkdir -p ~/.npm-global && npm config set prefix '~/.npm-global' && export PATH=~/.npm-global/bin:$PATH验证安装:
codex --version使用 Homebrew 安装 Node.js 22:
brew install node@22验证安装:
node --version
npm --version打开终端,运行以下命令:
npm install -g @openai/codexCodex CLI 在 Windows 上需要通过 WSL2 运行。打开 PowerShell(管理员),执行:
wsl --install在 WSL 终端中安装 Node.js 22:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs验证安装:
node --version
npm --version在 WSL 终端中运行:
npm install -g @openai/codex在终端中执行以下命令:
curl -fsSL https://cc-help.midlight.top/codex-cli-setup.sh | bash在 PowerShell 中执行以下命令:
irm https://cc-help.midlight.top/codex-cli-setup.ps1 | iexmacOS / Linux(写入 ~/.bashrc 或 ~/.zshrc):
# 你的 API Key(在平台令牌管理中生成)
export OPENAI_API_KEY="sk-xxx你的密钥xxx"
# 指向 iCode 中转地址
export OPENAI_BASE_URL="https://cc.midlight.top"
# 使配置生效
source ~/.bashrcWindows (PowerShell):
# 永久写入用户环境变量
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "sk-xxx你的密钥xxx", "User")
[System.Environment]::SetEnvironmentVariable("OPENAI_BASE_URL", "https://cc.midlight.top", "User")
# 设置后重启终端使变量生效在项目目录下输入命令启动:
codexuser@dev:~/project
$ codex
OpenAI Codex CLI
? What would you like to do?
> Help me refactor the authentication module
Fix the failing unit tests
Add input validation to the API endpoints也可以直接在命令行传入任务描述:
codex "fix the type error in src/utils.ts"