Windows PowerShell 安装说明

安装 npm、Codex CLI 和 Claude Code

本页面适用于 Windows 用户。按顺序完成 Node.js/npm 安装、PowerShell 执行策略设置、Codex/Claude Code 安装,以及 API Key 和代理地址配置。

1. 安装 Node.js/npm 使用 winget 安装 Node.js LTS,npm 会随 Node.js 一起安装。
2. 允许 npm 脚本运行 设置 PowerShell 执行策略,解决 npm.ps1 禁止运行问题。
3. 安装 CLI 工具 通过 npm 全局安装 OpenAI Codex 和 Claude Code。
4. 配置 API Key 向提供者获取 IP、端口和 Key,写入对应配置。

0准备事项

请使用 Windows 自带的 PowerShell。建议右键 PowerShell,选择以管理员身份运行

重要:页面里的 IPPORTportsk-xxx 都是占位符。实际 IP、端口和 API Key 请向提供者获取后替换。

不要把真实 API Key 发给无关人员,也不要把带真实 Key 的配置截图公开。

1安装 Node.js LTS 和 npm

打开 PowerShell,输入下面命令安装 Node.js LTS:

PowerShell
winget install -e --id OpenJS.NodeJS.LTS

安装完成后,关掉 PowerShell,重新打开,输入:

PowerShell
node -v
如果看到类似 v24.x.xv22.x.x 这样的版本号,说明 Node.js 安装成功。

2设置 PowerShell 执行策略

打开 PowerShell,运行下面命令:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

系统询问确认时,输入:

PowerShell
Y

然后关掉 PowerShell,重新打开,输入:

PowerShell
npm -v
如果看到 npm 版本号,例如 10.x.x11.x.x,说明 npm 可以正常使用。

3安装 Codex CLI 和 Claude Code

打开 PowerShell,先安装 Codex:

PowerShell
npm i -g @openai/codex

再安装 Claude Code:

PowerShell
npm i -g @anthropic-ai/claude-code

安装完成后,在 PowerShell 里分别输入下面命令,确认是否安装完成:

运行 Codex
codex
运行 Claude
claude
说明:首次运行时如果还没有配置 API Key 和服务地址,可能会进入登录/配置流程,或因为网络风控原因无法直接使用。继续完成下面的配置后再运行。

4A配置 Codex

先确保 .codex 文件夹存在。打开 PowerShell,运行:

PowerShell
New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex"

4A-1. 编辑 config.toml

在 PowerShell 里输入:

PowerShell
notepad "$env:USERPROFILE\.codex\config.toml"

在记事本里粘贴下面内容。把 http://IP:PORT 改成实际服务地址:

config.toml
model_provider = "OpenAI"
model = "gpt-5.5"
review_model = "gpt-5.5"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true
model_context_window = 1000000
model_auto_compact_token_limit = 900000

[model_providers.OpenAI]
name = "OpenAI"
base_url = "http://IP:PORT"
wire_api = "responses"
requires_openai_auth = true

4A-2. 编辑 auth.json

再次在 PowerShell 里输入:

PowerShell
notepad "$env:USERPROFILE\.codex\auth.json"

在记事本里粘贴下面内容。把 sk-xxx 改成实际 API Key:

auth.json
{
  "OPENAI_API_KEY": "sk-xxx"
}
Codex 的 IPPORTOPENAI_API_KEY 请向提供者获取。

4B配置 Claude Code

打开 PowerShell,先运行下面三行环境变量配置。把 IPportsk-xxx 替换为实际值:

PowerShell
$env:ANTHROPIC_BASE_URL="http://IP:port"
$env:ANTHROPIC_AUTH_TOKEN="sk-xxx"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

然后继续在同一个 PowerShell 窗口里运行:

PowerShell
claude
上面三行 $env: 配置只对当前 PowerShell 窗口有效。关闭窗口后,下次运行 Claude 前需要重新设置。
可选:把 Claude 配置写成当前用户的永久环境变量

只在自己的电脑上使用。写入后需要关闭 PowerShell 并重新打开才会生效。

PowerShell,可选
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "http://IP:port", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-xxx", "User")
[Environment]::SetEnvironmentVariable("CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC", "1", "User")

最终检查

全部安装和配置完成后,重新打开 PowerShell,依次检查:

PowerShell
node -v
npm -v
codex --version
claude --version
where.exe codex
where.exe claude
看到 node -v 版本号:Node.js 安装成功。
看到 npm -v 版本号:npm 安装成功。
codex 能启动:Codex CLI 安装成功。
claude 能启动:Claude Code 安装成功。

?常见问题

npm 提示“在此系统上禁止运行脚本”怎么办?

说明 PowerShell 执行策略没有设置好。重新运行第二步:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

确认输入 Y,然后关闭 PowerShell 并重新打开。

node 有版本号,但 npm 找不到怎么办?

先关闭 PowerShell,重新打开再试。如果仍然失败,检查 npm 位置:

PowerShell
where.exe node
where.exe npm
where.exe npm.cmd

也可以临时用 npm.cmd 代替 npm

PowerShell
npm.cmd -v
npm.cmd i -g @openai/codex
npm.cmd i -g @anthropic-ai/claude-code

Codex 配置文件在哪里?

Windows 下通常是:

路径
C:\Users\你的用户名\.codex\config.toml
C:\Users\你的用户名\.codex\auth.json

PowerShell 里的写法是:

PowerShell
$env:USERPROFILE\.codex\config.toml
$env:USERPROFILE\.codex\auth.json

官方参考

Node.js LTS 安装器包含 npm;Codex CLI 支持用 npm 全局安装并运行 codex;Claude Code 也支持 npm 全局安装。