# ============================================================= # DeepSeek x Claude Code 一键环境安装脚本 (Windows) # 用法: 以管理员身份打开 PowerShell, 执行: # irm https://b2.ink/cc-deepseek/install.ps1 | iex # 作用: 装 Node.js(LTS) + 配国内 npmmirror 镜像 + 装 Claude Code # 不含: cc-switch(图形界面, 自行安装) / DeepSeek API Key(自行申请) # 全程国内网络直连, 不需要代理 # 源码即本文件 —— 浏览器打开上面的地址就能逐行审查 # 开源仓库(含完整修改历史): https://github.com/hongnono-wdh/cc-deepseek-install # b2.ink 上的这份是仓库同名文件的托管副本, 内容一致, 欢迎对照 # 版本: v1.2 (2026-07-05) · 仅供学习交流 # v1.1 修复: Windows 自带 PowerShell 5.1 下版本列表解析成整个数组 # 导致 414 URL 超长; 并增加版本号格式校验 + 内置稳定版兜底 # v1.2 修复: Windows 默认执行策略 Restricted 会拦住 npm.ps1 / claude.ps1 # 启动器, 脚本开头自动检测并放行本地脚本 (RemoteSigned) # ============================================================= $ErrorActionPreference = "Stop" # Win10 老系统的 PowerShell 默认没开 TLS 1.2, 不开的话 https 下载会失败 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Windows 默认禁止运行 .ps1 (Restricted), 会拦住 npm / claude 的启动器, # 必须最先放行。RemoteSigned = 本地脚本放行, 网上下载的仍需签名 (微软推荐设置) if ((Get-ExecutionPolicy) -notin @("RemoteSigned", "Unrestricted", "Bypass")) { try { Set-ExecutionPolicy -Scope LocalMachine RemoteSigned -Force } catch { } } # 刷新当前窗口的 PATH, 让刚装好的 node / npm / claude 立刻可用 function Update-SessionPath { $env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User") } Write-Host "==> [1/4] 检查 / 安装 Node.js (LTS)..." -ForegroundColor Cyan if (Get-Command node -ErrorAction SilentlyContinue) { Write-Host " 已检测到 Node.js $(node -v), 跳过安装" } else { # 从国内 npmmirror 镜像直接下最新 LTS 安装包 (不走 winget, 大陆网络走不通) $mirror = "https://registry.npmmirror.com/-/binary/node" # 注意: PowerShell 5.1 的 irm 会把 JSON 数组当单个对象返回, # 必须先 ForEach-Object 强制展开, 否则筛出来的是整个版本列表 $ver = $null try { $index = irm "$mirror/index.json" $ver = ($index | ForEach-Object { $_ } | Where-Object { $_.lts } | Select-Object -First 1).version } catch { } # 版本号必须形如 v24.18.0, 否则一律改用内置稳定 LTS 兜底 $ver = "$ver".Trim() if ($ver -notmatch '^v\d+\.\d+\.\d+$') { $ver = "v24.18.0" Write-Host " 在线查询 LTS 版本失败, 改用内置稳定版 $ver" } $msi = "node-$ver-x64.msi" $tmp = Join-Path $env:TEMP $msi Write-Host " 从国内镜像下载 $msi ..." iwr "$mirror/$ver/$msi" -OutFile $tmp Write-Host " 静默安装中 (约 1 分钟)..." Start-Process msiexec.exe -ArgumentList "/i `"$tmp`" /qn /norestart" -Wait Update-SessionPath if (-not (Get-Command node -ErrorAction SilentlyContinue)) { throw "Node.js 装好了但本窗口还认不到它 —— 关掉本窗口, 重新以管理员打开 PowerShell, 再跑一次同样的命令即可" } Write-Host " Node.js 装好: $(node -v)" } Write-Host "==> [2/4] 配置 npm 国内镜像 (npmmirror, 下载飞快)..." -ForegroundColor Cyan npm config set registry https://registry.npmmirror.com Write-Host "==> [3/4] 安装 Claude Code..." -ForegroundColor Cyan npm install -g @anthropic-ai/claude-code Write-Host "==> [4/4] 验证安装..." -ForegroundColor Cyan Update-SessionPath claude --version Write-Host "" Write-Host "✅ 环境装好了! 上面那行就是 Claude Code 的版本号。" -ForegroundColor Green Write-Host "下一步: 装 cc-switch, 填入你的 DeepSeek API Key (见教程第 3-4 步)。" -ForegroundColor Green