Claude Code Windows 安装过程
·
一、安装 Node.js
先安装 Node.js,建议使用 LTS 版本。
安装完成后打开 CMD,检查:
node -v
npm -v
能够正常显示版本号,说明 Node.js 和 npm 安装成功。
二、安装 Claude Code
打开 CMD,执行:
npm install -g @anthropic-ai/claude-code --allow-scripts=@anthropic-ai/claude-code
出现类似以下内容,表示软件包已经安装:
changed 2 packages
三、查看 npm 全局目录
执行:
npm config get prefix
一般输出:
C:\Users\用户名\AppData\Roaming\npm
例如:
C:\Users\syz\AppData\Roaming\npm
四、配置环境变量
将 npm 全局目录添加到 Windows 用户环境变量 Path:
C:\Users\syz\AppData\Roaming\npm
配置方法:
-
按
Win + R,输入:
sysdm.cpl
-
进入“高级”。
-
点击“环境变量”。
-
找到用户变量中的
Path。 -
点击“编辑”→“新建”。
-
添加 npm 全局目录。
-
确定并关闭所有窗口。
-
关闭原来的 CMD,重新打开。
也可以使用 PowerShell 自动添加:
powershell -NoProfile -Command "$n=Join-Path $env:APPDATA 'npm';$p=[Environment]::GetEnvironmentVariable('Path','User');if(($p -split ';') -notcontains $n){[Environment]::SetEnvironmentVariable('Path',($p.TrimEnd(';')+';'+$n),'User')}"
五、验证安装
重新打开 CMD,执行:
claude --version
如果显示类似:
2.1.212
说明安装成功。
启动 Claude Code:
claude
六、指定工作目录启动
例如需要在 C:\testClaude 中使用:
cd /d C:\testClaude
claude
Claude Code 会以当前目录作为工作目录。
七、常见问题
如果提示:
'claude' 不是内部或外部命令
检查启动文件是否存在:
dir "%APPDATA%\npm\claude*"
如果存在 claude.cmd,说明是环境变量问题,可以临时执行:
set "PATH=%PATH%;%APPDATA%\npm"
claude --version
如果不存在 claude.cmd,检查 npm 配置:
npm config get bin-links
如果输出 false,执行:
npm config set bin-links true --location=user
npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code --allow-scripts=@anthropic-ai/claude-code --bin-links=true
如果出现:
npm approve-scripts does not work for global installs
不要使用:
npm approve-scripts -g
全局安装应直接通过以下参数放行脚本:
--allow-scripts=@anthropic-ai/claude-code
完整安装命令为:
npm install -g @anthropic-ai/claude-code --allow-scripts=@anthropic-ai/claude-code

然后用ccswitch来配置源
更多推荐




所有评论(0)