[BUG] Bash scripts with shebangs produce no output on Windows (MINGW64)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Bash scripts containing a shebang line (#!/bin/bash or #!/usr/bin/env bash) execute successfully (exit code 0) but produce zero output when run through Claude Code on Windows. The output is silently lost.
This breaks common development tools like npm and npx, which are bash scripts with shebangs on Windows (Git for Windows). Running npm --version returns nothing, while npm.cmd --version works correctly.
Scripts without shebangs work correctly - output is captured as expected.
Environment:
- OS: Windows 11 (MINGW64_NT-10.0-26100)
- Terminal: PowerShell/Git Bash
- Shell: Git Bash 5.2.37(1)-release (x86_64-pc-msys)
- Claude Code installed via npm
What Should Happen?
Scripts with shebangs should produce visible output, identical to scripts without shebangs. The shebang line should not affect output capture.
Both of these should output "hello":
echo 'echo "hello"' > /tmp/a.sh && bash /tmp/a.sh # Works
echo -e '#!/bin/bash\necho "hello"' > /tmp/b.sh && bash /tmp/b.sh # Should also work
Error Messages/Logs
No error messages - that's the problem. Commands execute silently with exit code 0:
$ bash /tmp/script-with-shebang.sh
(no output)
$ echo $?
0
The Bash tool reports: "Tool ran without output or errors"
Steps to Reproduce
- Open Claude Code on Windows with PowerShell
Note:
Claude Code explicitly spawns /usr/bin/bash with its own flags (-c -l), sources its own snapshot, and redirects stdin from /dev/null.
The parent shell (PowerShell) is not involved in the bash execution.
- Create a script without a shebang and run it:
echo 'echo "no shebang"' > /tmp/no-shebang.sh
bash /tmp/no-shebang.sh
Result: Outputs "no shebang" ✓
- Create a script with a shebang and run it:
echo -e '#!/bin/bash\necho "has shebang"' > /tmp/has-shebang.sh
bash /tmp/has-shebang.sh
Result: No output ✗
- Verify the shebang script is valid by sourcing it:
source /tmp/has-shebang.sh
Result: Outputs "has shebang" ✓ (proves script content is correct)
- Demonstrate real-world impact with npm:
# This produces no output:
"/c/Program Files/nodejs/npm" --version
# This works:
"/c/Program Files/nodejs/npm.cmd" --version
# Output: 11.6.2
The npm bash script (/c/Program Files/nodejs/npm) starts with #!/usr/bin/env bash, causing its output to be lost. The batch file equivalent (npm.cmd) has no shebang and works correctly.
Minimal test case:
# One-liner to demonstrate the bug:
echo 'echo works' > /tmp/a.sh && echo -e '#!/bin/bash\necho broken' > /tmp/b.sh && echo "Without shebang:" && bash /tmp/a.sh && echo "With shebang:" && bash /tmp/b.sh && echo "Done"
Expected output:
Without shebang:
works
With shebang:
broken
Done
Actual output:
Without shebang:
works
With shebang:
Done
Verified:
All test cases work correctly in both native Git Bash and PowerShell invoking Git Bash, tested manually by me (the user).
The issue only occurs within Claude Code's Bash tool, confirming the bug is in Claude Code's output capture mechanism, not the underlying shell environment.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
Not sure exactly, definitely before 2.1, somewhere between 2.1.0 and 2.1.7 it broke, maybe 2.1.5
Claude Code Version
2.1.11 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
Below is a screenshot of when Claude found the issue, along with a Git Bash terminal with a shebang test I ran, showing them working outside of Claude's environment.
The current workaround is to manually set aliases in bashrc, the session from this screenshot uses a bash capture after the alias was added, which is why Claude confirms the alias working.
<img width="1685" height="590" alt="Image" src="https://github.com/user-attachments/assets/2ddf14a6-6fc3-44e9-9ac3-4453d7eeb1b7" />
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗