Bash tool broken on Windows: Git Bash MSYS2 Bad file descriptor with piped stdout
Description
The Bash tool fails on every command with exit code 1 and no output on Windows. Even echo hello fails silently.
Environment
- Claude Code: 2.1.45
- OS: Windows 11 Home 24H2 (Build 26100.7623)
- Git for Windows: 2.51.0
- Git Bash (MSYS2):
C:\Program Files\Git\usr\bin\bash.exe - Node: 22.17.0
Root Cause
Git Bash (MSYS2 runtime) produces Bad file descriptor when stdout is a pipe rather than a console. Claude Code's Bash tool captures output via pipes, so MSYS2 can't write to them.
The actual error (visible when stderr is captured via PowerShell wrapper):
/usr/bin/bash: line 1: echo: write error: Bad file descriptor
Reproduction Steps
- Install Git for Windows 2.51.0 on Windows 11
- Open Claude Code 2.1.45
- Run any Bash tool command, e.g.
echo hello - Result: Exit code 1, zero output
Key Observations
| Method | Result |
|--------|--------|
| Bash tool directly | BROKEN - exit code 1, no output |
| powershell.exe -NoProfile -Command "echo hello" via Bash tool | Works |
| WSL bash (C:\Windows\System32\bash.exe) via Bash tool | Works |
| Git Bash from user's PowerShell terminal | Works (ConPTY gives it a real console, not a pipe) |
| Session hooks (e.g. tdd-guard) | Works (different I/O path - exit code check, not piped stdout) |
This confirms the issue is specifically with how Claude Code creates stdout/stderr pipes for the Bash tool, and MSYS2's inability to write to those pipes.
Workaround
Wrapping all commands in PowerShell works:
powershell.exe -NoProfile -Command "git status"
Expected Behavior
echo hello should print hello and exit with code 0.
Additional Context
- The
dangerouslyDisableSandbox: trueoption does not fix this (also tested). - Git Bash with
--loginflag also fails with the same error. - This may be a regression in Claude Code 2.1.45's pipe handling, a regression in Git for Windows 2.51.0's MSYS2 runtime, or an interaction between the two.
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗