Bug: Incorrect WSL detection in Git Bash (MINGW64) environment

Resolved 💬 3 comments Opened Jan 24, 2026 by flyfoxai Closed Jan 27, 2026

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

  1. Install Git for Windows (includes Git Bash)
  2. Ensure WSL is not installed
  3. Launch Claude Code in Git Bash
  4. Execute any command using the Bash tool
  5. Observe the WSL error

Expected Behavior

Claude Code should:

  • Detect Git Bash via MSYSTEM environment variable
  • Use Git Bash's native bash or sh directly
  • Not attempt WSL execution

Actual Behavior

Claude Code:

  • Misidentifies Git Bash as WSL
  • Attempts to execute /bin/bash through WSL
  • Fails with execvpe error

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)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗