-
Notifications
You must be signed in to change notification settings - Fork 16.5k
fix(windows): reject WSL bash.exe in findGitBashPath detection #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,42 @@ function isExecutable(shellPath: string): boolean { | |
| * Determines the best available shell to use. | ||
| */ | ||
| export async function findSuitableShell(): Promise<string> { | ||
| // Windows-only one-shot warning: if WSL bash launcher is on PATH and no | ||
| // Git for Windows bash is detected, surface a warning so the user knows | ||
| // why hooks/BashTool will misbehave. The actual filtering lives in | ||
| // findExecutableWithDeps (windowsPaths.ts); this is purely user-facing. | ||
| if ( | ||
| getPlatform() === 'windows' && | ||
| !process.env.CLAUDE_CODE_GIT_BASH_PATH && | ||
| !process.env.CLAUDE_CODE_GIT_BASH_PATH_WARNED | ||
| ) { | ||
| try { | ||
| const whereResult = execFileSync('where.exe', ['bash'], { | ||
| stdio: ['ignore', 'pipe', 'ignore'], | ||
| encoding: 'utf8', | ||
| }) | ||
| const lines = whereResult | ||
| .split(/\r?\n/) | ||
| .map(l => l.trim().toLowerCase()) | ||
| .filter(Boolean) | ||
| const hasWslBash = lines.some(l => | ||
| /(?:system32|windowsapps)\\bash\.exe$/.test(l), | ||
| ) | ||
| const hasGitBash = lines.some(l => /\\git\\.*bash\.exe$/.test(l)) | ||
| if (hasWslBash && !hasGitBash) { | ||
| process.env.CLAUDE_CODE_GIT_BASH_PATH_WARNED = '1' | ||
| console.warn( | ||
| '[CCB] Detected WSL bash on PATH without Git for Windows. ' + | ||
| 'Hooks and BashTool will not work correctly. ' + | ||
| 'Install Git for Windows (https://git-scm.com/download/windows) ' + | ||
| 'or set CLAUDE_CODE_GIT_BASH_PATH to your bash.exe.', | ||
|
Comment on lines
+80
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use the Git Bash resolver for the availability check.
Add regression coverage for a valid override and for Git for Windows that is discoverable without appearing in 🧰 Tools🪛 ast-grep (0.45.0)[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
| ) | ||
| } | ||
| } catch { | ||
| // where.exe not available or failed — fall through silently | ||
| } | ||
| } | ||
|
|
||
| // Check for explicit shell override first | ||
| const shellOverride = process.env.CLAUDE_CODE_SHELL | ||
| if (shellOverride) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 50385
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 50387
Use asynchronous Bun process execution for the PATH lookup.
findSuitableShell()is async, soexecFileSync('where.exe', ['bash'])blocks shell discovery untilwhere.exereturns and can hang without a timeout. Replace this lookup with Bun subprocess execution, keep failures ignored, and add a bounded timeout for the lookup.🧰 Tools
🪛 ast-grep (0.45.0)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync, spawn } from 'child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
🤖 Prompt for AI Agents
Source: Coding guidelines