From 6275ce55dc6bf03d64fd0e24f1d8862c643f690c Mon Sep 17 00:00:00 2001 From: bookworm Date: Fri, 10 Apr 2026 10:33:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(installer):=20bash=20PATH=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BF=AE=E5=A4=8D=20=E2=80=94=20Claude=20Code=20?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=E5=B7=A5=E5=85=B7=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git for Windows 默认只把 cmd\ 加入 PATH (含 git.exe), 但 bash.exe 在 bin\ 目录, 导致 Claude Code 的 Bash 工具不可用. Phase 1 新增: 安装 Git 后自动检测 bash.exe 位置, 将 Git\bin 永久加入用户 PATH. 搜索 4 个常见安装路径. Co-Authored-By: Claude Opus 4.6 (1M context) --- auto-setup.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/auto-setup.ps1 b/auto-setup.ps1 index d15928d..d581602 100644 --- a/auto-setup.ps1 +++ b/auto-setup.ps1 @@ -604,6 +604,31 @@ foreach ($dep in $deps) { } } +# ── bash PATH 自动修复 (Claude Code 的核心工具依赖 bash) ── +# Git 默认只把 cmd\ 加 PATH (有 git.exe), 但 bash.exe 在 bin\ 目录 +if ((Test-Cmd "git") -and -not (Test-Cmd "bash")) { + $gitBinPaths = @( + "$env:ProgramFiles\Git\bin", + "${env:ProgramFiles(x86)}\Git\bin", + "D:\Git\bin", + "$env:LOCALAPPDATA\Programs\Git\bin" + ) + $gitBin = $gitBinPaths | Where-Object { Test-Path (Join-Path $_ "bash.exe") } | Select-Object -First 1 + if ($gitBin) { + # 加入用户 PATH (永久) + $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") + if ($userPath -notmatch [regex]::Escape($gitBin)) { + [System.Environment]::SetEnvironmentVariable("Path", "$userPath;$gitBin", "User") + $env:Path += ";$gitBin" + Log-OK "bash 已加入 PATH: $gitBin" + } + } else { + Log-Warn "Git 已安装但找不到 bash.exe (Claude Code Bash 工具可能不可用)" + } +} elseif (Test-Cmd "bash") { + Log-OK "bash 已就绪" +} + # Claude Code 依赖 npm, 需要在 Node.js 安装后再检查 if (-not (Test-Cmd "claude") -and (Test-Cmd "npm")) { Log-Info "安装 Claude Code..."