Windows Codex 安装指南

在 Windows 系统上安装官方 Codex CLI,并配置为使用积木AI代码助手。

系统要求

系统
Windows 10(版本 1809 / build 17763)及以上
依赖
Node.js 20+ + npm
Node.js 安装(如果没有安装)
前往 nodejs.org/zh-cn/download 下载。
Git 安装(可选)
前往 git-scm.com/downloads/win 下载,保持默认一路下一步(不要改路径)。如访问不稳定,可用清华镜像 mirrors.tuna.tsinghua.edu.cn/github-release/git-for-windows/git/,选择 Git for Windows 下载。

可选:使用 WSL(Windows运行Linux)

如你需要 Linux 环境,可安装 WSL(Debian/Ubuntu)。安装完成后可直接参考 macOS/Linux Codex 安装指南。WSL 具体教程请参考其他网站。

安装步骤(Windows 终端)

1

环境检查(推荐)

powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr -useb https://code.jimuxyz.com/env_deploy/codex-install.ps1 | iex"

可在 PowerShell / CMD / Windows Terminal / VSCode 终端执行。

脚本会检查 Node.js / npm 版本,并提示修复方式。

2

卸载已安装的 Codex(可选,未安装请跳过)

powershell -NoProfile -ExecutionPolicy Bypass -Command "npm uninstall -g @openai/codex"
3

安装 Codex 官方原版包

powershell -NoProfile -ExecutionPolicy Bypass -Command "npm install -g @openai/codex"
4

验证安装

codex -V

若 PowerShell 提示“无法加载 codex.ps1,因为在此系统上禁止运行脚本”,请先执行:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser,然后重新打开终端再试。

5

可选:重建 .codex 配置目录(旧配置异常时再执行)

powershell -NoProfile -ExecutionPolicy Bypass -Command "Remove-Item -Recurse -Force ([IO.Path]::Combine([Environment]::GetFolderPath('UserProfile'), '.codex')) -ErrorAction SilentlyContinue; New-Item -ItemType Directory -Path ([IO.Path]::Combine([Environment]::GetFolderPath('UserProfile'), '.codex')) | Out-Null"

首次安装通常不必先删目录;只有之前装过 Codex、怀疑旧配置冲突时再执行这一条。

6

登录后创建并复制 Codex API Key

登录后到「API Key」页面创建一个新的 Codex Key(复制你的Codex_API_KEY)。

7

脚本快速配置(推荐)

powershell -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::SetEnvironmentVariable('JIMUXYZ_API_KEY','你的Codex_API_KEY','Process'); iwr -useb https://code.jimuxyz.com/env_deploy/codex-deploy.ps1 | iex"

脚本会自动写入 .codex\\auth.json.codex\\config.toml,并备份旧文件。

重要:如果你之前在本机用过其他 Key / 其他服务商,改完配置后请按场景选择命令。codex = 按当前新配置新建会话;codex resume = 继续旧会话;codex fork --last = 继承最近一次会话内容,但按当前新配置开一个新会话。若你想把旧历史接到新的积木AI配置继续使用,优先用 codex fork --last,不要直接用 codex resume

若 PowerShell 提示“无法加载 *.ps1,因为在此系统上禁止运行脚本”,请先执行:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser,然后重新打开终端再试。

或者

如果你不想用脚本,就按下方两个小步骤分别写入 auth.jsonconfig.toml

8

手动配置(auth.json + config.toml)提示:将 你的Codex_API_KEY 改为你在「API Key」页面创建的真实 Codex Key。

  • 步骤 1:写入 auth.json
powershell -NoProfile -ExecutionPolicy Bypass -Command "[IO.File]::WriteAllText([IO.Path]::Combine([Environment]::GetFolderPath('UserProfile'), '.codex\auth.json'), (@{ OPENAI_API_KEY = '你的Codex_API_KEY' } | ConvertTo-Json -Compress), (New-Object System.Text.UTF8Encoding 0))"
  • 步骤 2:写入 config.toml
powershell -NoProfile -ExecutionPolicy Bypass -Command "[IO.File]::WriteAllText([IO.Path]::Combine([Environment]::GetFolderPath('UserProfile'), '.codex\config.toml'), [string]::Join([Environment]::NewLine, @(
'model_provider = ''jimuxyz''',
'model = ''gpt-5.3-codex''',
'model_reasoning_effort = ''high''',
'disable_response_storage = true',
'preferred_auth_method = ''apikey''',
'',
'[model_providers.jimuxyz]',
'name = ''jimuxyz''',
'base_url = ''https://code.jimuxyz.com/p/v1''',
'wire_api = ''responses''',
'requires_openai_auth = true'
)), (New-Object System.Text.UTF8Encoding 0))"
9

启动 Codex / 续接历史

# 导航到你的项目(可选)
cd your-project

# 1) 全新按当前配置启动
codex

# 2) 只恢复旧会话
codex resume --last

# 3) 继承旧历史,但按当前新配置继续
codex fork --last

推荐口径:首次切到积木AI后,先用 codex 验证新配置;如果你想把旧历史一起带过来继续用,优先执行 codex fork --last;只有明确要原样恢复旧线程时,再用 codex resume