Skip to content

fix: auto-detect git-bash path on Windows for Claude CLI (closes #23)#25

Closed
gy212 wants to merge 1 commit intoop7418:mainfrom
gy212:fix/windows-gitbash-detection
Closed

fix: auto-detect git-bash path on Windows for Claude CLI (closes #23)#25
gy212 wants to merge 1 commit intoop7418:mainfrom
gy212:fix/windows-gitbash-detection

Conversation

@gy212
Copy link
Copy Markdown
Contributor

@gy212 gy212 commented Feb 8, 2026

问题

Windows 上 Git 安装在非标准路径(如 D:\APP\Git)时,Claude CLI 无法找到 bash.exe,进程以退出码 1 退出:

Claude Code on Windows requires git-bash. If installed but not in PATH, set environment variable pointing to your bash.exe, similar to: CLAUDE_CODE_GIT_BASH_PATH=C:\Program Files\Git\bin\bash.exe

修复

src/lib/platform.ts 新增 findGitBash() 函数,按优先级自动检测 git-bash 路径:

  1. 环境变量 CLAUDE_CODE_GIT_BASH_PATH(用户手动设置)
  2. 常见安装路径C:\Program Files\Git\bin\bash.exeC:\Program Files (x86)\Git\bin\bash.exe
  3. where git 推导 — 定位 git.exe,从其路径推导 Git 安装目录,拼接 bin\bash.exe

src/lib/claude-client.ts 构建 SDK 子进程环境变量时,仅在 Windows 平台且 CLAUDE_CODE_GIT_BASH_PATH 未设置时调用该函数,将检测结果写入环境变量。

修改文件

文件 说明
src/lib/platform.ts 新增 findGitBash() 导出函数
src/lib/claude-client.ts 构建 sdkEnv 时调用自动检测

#24 拆分

按作者建议,从 PR #24 中拆分出此独立修复。Bug 1(#22)因 main 分支已移除 ApiConfigSection 组件需另行处理。

Windows 上 Git 安装在非标准路径时,Claude CLI 因找不到 bash.exe 而以退出码 1 退出。

新增 findGitBash() 函数,按优先级自动检测 git-bash 路径:
1. 环境变量 CLAUDE_CODE_GIT_BASH_PATH(用户手动设置)
2. 常见安装路径(C:\Program Files\Git\bin\bash.exe 等)
3. 通过 where git 命令推导 Git 安装目录

在构建 SDK 子进程环境变量时自动设置 CLAUDE_CODE_GIT_BASH_PATH。
@op7418
Copy link
Copy Markdown
Owner

op7418 commented Feb 9, 2026

Closing: this feature has already been implemented in main (findGitBash() in src/lib/platform.ts + auto-detection in src/lib/claude-client.ts). Thank you for the contribution!

@op7418 op7418 closed this Feb 9, 2026
@gy212 gy212 deleted the fix/windows-gitbash-detection branch March 5, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants