Bug: Incorrect WSL detection in Git Bash (MINGW64) environment
Bug: Incorrect WSL detection in Git Bash (MINGW64) environment
Problem
Claude Code incorrectly attempts to execute commands through WSL when running in Git Bash (MINGW64), causing this error:
Plugin hook error: <3>WSL (9 - Relay) ERROR: CreateProcessCommon:798: execvpe(/bin/bash) failed: No such file or directory
Root Cause
Environment detection logic cannot distinguish between:
- Git Bash (MINGW64) - POSIX-compatible environment on Windows
- WSL - Windows Subsystem for Linux
When running in Git Bash, Claude Code incorrectly assumes it should route bash commands through WSL, attempting to execute /bin/bash via WSL, which fails.
Environment
- OS: Windows 11 (Build 26200)
- Shell: Git Bash (MINGW64_NT-10.0-26200)
- PowerShell: 7.5.4
- WSL: Not installed
Environment variables in Git Bash:
MSYSTEM=MINGW64
WSL_DISTRO_NAME=(not set)
WSL_INTEROP=(not set)
Reproduction
- Install Git for Windows (includes Git Bash)
- Ensure WSL is not installed
- Launch Claude Code in Git Bash
- Execute any command using the Bash tool
- Observe the WSL error
Expected Behavior
Claude Code should:
- Detect Git Bash via
MSYSTEMenvironment variable - Use Git Bash's native
bashorshdirectly - Not attempt WSL execution
Actual Behavior
Claude Code:
- Misidentifies Git Bash as WSL
- Attempts to execute
/bin/bashthrough WSL - Fails with
execvpeerror
Proposed Fix
Improve environment detection using specific environment variables:
function detectEnvironment() {
if (process.platform === 'win32') {
// Check WSL first (highest priority)
if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) {
return 'wsl';
}
// Check Git Bash/MSYS
if (process.env.MSYSTEM) {
return 'gitbash';
}
// Check Cygwin
if (process.env.CYGWIN) {
return 'cygwin';
}
return 'windows';
}
return process.platform;
}
Shell selection:
| Environment | Detection | Shell Path | Execution |
|------------|-----------|------------|-----------|
| WSL | WSL_DISTRO_NAME or WSL_INTEROP | /bin/bash | via wsl command |
| Git Bash | MSYSTEM (MINGW64/MINGW32) | bash or sh | direct |
| Cygwin | CYGWIN | bash or sh | direct |
| Windows | none of above | pwsh or powershell | direct |
Workaround
Configure .claude/settings.json:
{
"shell": {
"path": "pwsh",
"args": ["-NoProfile", "-Command"]
}
}
Or run Claude Code in native PowerShell instead of Git Bash.
Impact
Affects all Windows users who:
- Use Git Bash as their primary terminal
- Don't have WSL installed or configured
- Need to use Claude Code in Git Bash environment
Willing to Contribute
- [ ] I can submit a Pull Request to fix this
- [ ] I can provide additional testing
- [ ] I can test the fix across different environments
Additional Context
Test script and detailed documentation available at: [your-repo-url]
Related: #2986 (environment detection issues)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗