[BUG] Bash tool doesn't capture stdout from shell script files on Windows
Description
On Windows, the Bash tool does not capture stdout from shell script files. This affects all shell scripts, including npm CLI shims, custom scripts, and any executable shell script.
Environment
- OS: Windows 11 (10.0.26200)
- Node: v22.21.0
- Claude Code: Started occurring around v2.1.x
- Shell: Git Bash (MINGW64)
Reproduction Steps
# Create a simple shell script
cat > /tmp/test.sh << EOF
#!/bin/sh
echo "hello from script"
EOF
chmod +x /tmp/test.sh
# These produce NO output:
/tmp/test.sh
sh /tmp/test.sh
bash /tmp/test.sh
# But these WORK:
sh -c "echo hello"
echo "echo hello" | sh
bash -c "echo hello"
Expected Behavior
Shell script files should have their stdout captured and returned, same as inline commands.
Actual Behavior
| Command Type | Output Captured? |
|--------------|------------------|
| sh -c "echo hello" | ✅ Yes |
| bash -c "echo hello" | ✅ Yes |
| echo "cmd" \| sh | ✅ Yes |
| node /path/to/script.js | ✅ Yes |
| /path/to/script.sh | ❌ No |
| sh /path/to/script.sh | ❌ No |
| bash /path/to/script.sh | ❌ No |
Exit code is 0 (success), but stdout is empty.
Impact
This breaks all npm CLI tools on Windows because npm creates shell shims like:
#!/bin/sh
basedir=$(dirname ...)
exec node "$basedir/node_modules/pkg/dist/main.js" "$@"
When Claude Code runs linearis, prettier, eslint, or any npm-installed CLI, no output is returned.
Workaround
Call node directly, bypassing the shell shim:
# Instead of: linearis issues read LC-123
node /c/Users/Owner/AppData/Roaming/npm/node_modules/linearis/dist/main.js issues read LC-123
Or use PowerShell wrapper:
powershell.exe -Command "linearis issues read LC-123"
Possibly Related Changelog Entries
- v2.1.2: "Changed large bash command outputs to be saved to disk instead of truncated"
- v2.1.0: "Added unified Ctrl+B backgrounding for both bash commands and agents"
These changes may have affected how stdout is captured from shell script file execution vs inline commands.
75 Comments
Additional Context from Changelog
After reviewing the changelog, these changes may be related:
v2.1.2:
This changed how bash output is captured—from in-memory to disk-based storage.
v2.1.0:
This restructured the Bash tool's execution model for background task handling.
Hypothesis: The exec-substituted process's stdout may not be properly piped to the disk-based capture mechanism, or the exec'd process is being incorrectly detected/handled as a background task.
The npm shim pattern is:
When
execreplaces the shell process with node, the new process's stdout might not be connected to whatever file/pipe Claude Code is reading from.Root Cause Identified
After more debugging, the issue is broader than npm shims - it affects all shell script files on Windows.
What Works
sh -c "echo hello"- Output capturedecho "echo hello" | sh- Output capturedbash -c "echo hello"- Output capturednode /path/to/main.js- Output capturedWhat Does NOT Work
/tmp/script.sh- No outputsh /tmp/script.sh- No outputbash /tmp/script.sh- No output/c/path/to/npm/shim- No output (because it is a shell script file)Test Case
Conclusion
The bug is NOT about exec in npm shims - it is that stdout from shell script file execution is not being captured on Windows. This affects all shell scripts, including npm shims, custom scripts, etc.
The
sh -cand pipe-to-sh workarounds work because they do not execute a script file.i have the same problem, 2.1.9
Can confirm this not working. The stable version v2.1.2 does not appear to have this issue.
<img width="1227" height="917" alt="Image" src="https://github.com/user-attachments/assets/2d4ef9e8-6bb1-4804-9c0d-2d141a6d9d2f" />
<img width="1171" height="801" alt="Image" src="https://github.com/user-attachments/assets/ff883a8b-ed2d-4ebf-908f-6ce2d82d5557" />
<img width="1226" height="317" alt="Image" src="https://github.com/user-attachments/assets/6f6fa585-4448-4535-9b8f-df7d4bbbebf1" />
<img width="912" height="113" alt="Image" src="https://github.com/user-attachments/assets/605d2aee-b397-45f7-833a-54655ce7fac4" />
This also is broken for me as of updating today.
I’m also hitting this issue starting today after updating to v2.1.9 on Windows 11.
Also encountering this issue starting today. Workaround for now, at least for npm/npx, is to append .cmd (e.g., 'npm.cmd run lint' outputs fine).
Confirming this still happening on v2.1.11
This seems like it will take some time to get fixed. In the meantime here is a workaround for windows users.
Workaround
(Automatic and simple)
(Manual)
Add to
.claude/settings.jsonOr project's.claude/settings.local.jsonVia Powershell:
Via Windows CMD:
Via WSL / Linux:
I'm on windows and 2.1.7 seems to still work. 2.1.8 breaks.
I have this issue as well v2.1.12, running in CLI on windows
confirmed this workaround works
Closed #18882 and adding findings here:
Additional Findings: Shebang-Specific Behavior
I've done testing on this issue and can confirm some additional details:
Narrowed Root Cause: Shebang Line Specifically
Within Claude Code, I found that the shebang line itself is the trigger:
Same script content, only difference is the shebang. Exit code is 0 in both cases.
Terminal Verification (Bug is 100% Claude Code Specific)
Ran identical tests in native Git Bash and PowerShell → Git Bash. All tests pass outside Claude Code:
Sourcing Workaround Confirms Script Validity
Running source "/c/Program Files/nodejs/npm" --version outputs 11.6.2 correctly.
When sourced (runs in current shell), output is captured. When executed as subprocess (bash interprets shebang, spawns
child), output is lost.
Conclusion
The bug appears to be in how Claude Code captures stdout when bash spawns a child process via shebang interpretation.
The disk-based capture mechanism mentioned in this issue likely isn't receiving the stdout file descriptor from the shebang-spawned subprocess.
Working Workaround
Run the following on a 2nd terminal after claude code launches
OR
Within Claude Code itself via the Bash mode
!<img width="338" height="115" alt="Image" src="https://github.com/user-attachments/assets/fed9bb83-647e-4e19-92b0-eb9976ea0d95" />
Issue is still present in 2.1.14
Issue is still present in 2.1.15, since 2.1.7 / 8 versions / 6-7 days that have passed that left claude code and the VSCode extension in a broken state with workarounds that can only do so much and don't account for edge cases. No response or update from Anthropic.
Thanks for the workarounds. Is using version 2.1.7 the go-to for now, or is your workaround with the latest version recommended? Do you think regular users are missing out on many new features compared to the latest version?
https://github.com/anthropics/claude-code/issues/13361 Reading a file with Read Tool on Windows takes 2-3 seconds, which is extremely slow, while it only takes 100ms on Mac/Linux. Claude has never fixed this issue. Moreover, they are planning to discontinue releasing via npm, so if bugs appear in claude code later, no one will know what the problem is. I've already switched to opencode . @BarisGc
claude code is the software with the most bugs I've ever encountered, terrible.
Your milage may vary but I am unable to continue until this is fixed due to edge cases, missing features, broken features on previous / stable versions.
They still don't have QA testing to prevent this, still not fixed. You also have to adjust your expectations regarding this in general as it isn't 5 years ago when developing depended on human work; this is with the claim they make that Opus 4.5 / AI is so powerful that it writes better code and will replace programmers and makes it faster to fix bugs and catch bugs, yet at the moment it seems they are going in a loop of fixing features that break the previous broken features in a never ending cycle.
The tipping point is that I am still charged for my Max subscription with no option to pause until they fix this, and don't make them laugh by trying to get some sort of compensation due to a reasonable issue.
@ant-kurt @bogini
Still not fixed in 2.1.17
Additional Finding: Piped stdin to Node.js
Related to this bug, I found that piping input to Node.js also has stdout capture issues in Git Bash:
This affects Claude Code hooks which receive JSON input via pipe. Claude Code shows "hook error" messages in the terminal output because hook stdout is being routed to stderr, which Claude Code interprets as an error.
Test Matrix
| Input Method | Shell | stdout Destination |
|--------------|-------|-------------------|
|
echo \| node| Git Bash | stderr (BUG) ||
node < file| Git Bash | stdout (OK) ||
node <<< str| Git Bash | stdout (OK) ||
echo \| node| PowerShell | stdout (OK) |Impact on Hooks
The existing workarounds (
.cmd/.exesuffixes, BASH_ENV) don't help for this piped stdin case since it's Node.js execution, not a shell script shim.Potential fix: Claude Code could check stderr for valid JSON when stdout is empty and exit code is 0, or use file-based IPC instead of pipes on Windows/Git Bash.
Still not fixed in 2.1.17
setx SHELLOPTS "braceexpand" can fix it. @levnikolaevich
set env
"SHELLOPTS": "braceexpand"
in claude code settings.json
There are too many bugs in the latest version, especially when using Claude Code in Windows environments. It is recommended to use version 2.1.7
I've been using this workaround which solve some problems, but doesn't fix problems when using other scripts.
https://github.com/anthropics/claude-code/issues/18748#issuecomment-3762646331
IMPORTANT: This bug also exists in your
settings.jsonhooks. Claude is not capturing output from hook commands that use scripts.@codemile try this
Workaround: set +o onecmd; npm run build 2>&1
Fixes npm / npx issues at the very least
This is the worst timeline we live in. $200 / mo. software becomes unusable for days on end with no recourse.
@boognish24
does this fix many, even all problems for a now?
{
"terminal.integrated.defaultProfile.windows": "Git Bash"
}
Was hit by this issue, switching to stable / 2.1.7 works.
latesthas way too many problems - evenclaude doctorwouldn't run to completion in git bash and hangs at exit - that's maybe an easy regression test to add for each supported shell envShell outputs still broken for me with 2.1.7, I previously used npm to install CC and never had issues, and nothing works on native now.
+1 still struggling with this
@orro3790 try this work if not
Setting SHELLOPTS to braceexpand doesn't work for me.
@bcherny @fvolcic Good afternoon! Please take a look at this issue. It has become difficult to work on Windows.
For what it's worth, I've been working around this issue (just for NPM) by adding the following to my
CLAUDE.md:This is a gnarly problem though because when Claude isn't seeing stdout, it'll churn and churn, flailing with increasingly elaborate solutions, when it's simply not seeing the output of its commands.
Best solution I have found so far, is to launch
claude, then run/configand change "Auto-update channel" to "stable". Then close the session and runclaude installin a new terminal - then launch claude again (which should be v2.1.7 at the time of writing) and it should work.Still broken in v2.1.20
@jake-r-smith-dev downgrading to 2.1.7 didn't work for me. Can you share your
settings.json<img width="641" height="406" alt="Image" src="https://github.com/user-attachments/assets/89562f7a-d2bb-493d-a9c7-dda93bcfeedb" />
@codemile I just downgraded to 2.1.7 to check this for you and I did not encounter the same result, it returned the output.
Perhaps try opening it in a new terminal to see if it is a cache issue.
@amdcq the 2.1.7 version is working for me now, but I had to first uninstall Claude via Windows Settings and remove
~/.claude, then I could do a fresh install and switch to the stable channel. Now it works.It seems if you switch to 2.1.7 and it's not working, then it's a cache related problem. You either reinstall Claude or figure out how to clear that cache.
v2.1.7 just works for me with both powershell and bash in windows 11. Could
be a cache problem as mentioned before.
On Tue, Jan 27, 2026 at 5:04 PM Nick Foscarini @.***>
wrote:
v2.1.7 works for me too
I am noticing a difference in the quality of Opus with 2.1.7 compared to when I used 2.1.19, and we don't have the feature to clear context when launching a plan. My assumptions are that the system prompts for 2.1.7 are not as good as the latest versions.
Is there anyone here with an Enterprise account who can use it to file a support request to get this fix?
Would it be safe to assume that there are no humans from Anthropic monitoring GitHub issues and this entire repo is just a fake facade to showcase their vibe coding pipeline?
God, I hope this isn't the future of software engineering.
Not to turn this into a reddit thread but I suspect a few things are at play:
1) I doubt they have any idea this is broken.
2) Anthropic uses Macs. So if you could get their attention, I suspect their answer is "get a mac, bro." or "Gentoo".
3) I also think they are in a race and not really looking back over their shoulder, so features > bugfixes. They just got a new raise and are probably focused on getting people signed up & metrics
4) I dont think humans are looking at issues
I switched to running claude code under WSL. It is so much better. All the annoying bugs with the powershell version are non-existent in that version. Anthropic doesn't show much love for windows. I recommend to others that if possible, run it under WSL as it works so much better.
I've uninstalled it and switched to opencode. Downgrading claude code to 2.1.7, npm --version still doesn't work, although it worked before. . Who knows what this software is doing in the background.
@codemile Currently, claude code is also having issues on my end; deleting the .claude directory and reinstalling doesn't work either.
If you switched from latest to stable in /config and then started a new claude code session and it still did not work. Try running the following which should resolve the cache issue
Launch claude code and then in a different terminal run
This is the current work around for using the latest version with the downside that there may be edge cases where this workaround doesn't work and as well as having to do this every time prior to launching claude code.
This workaround should hopefully fix it and you shouldn't have to run this every time since you aren't running the latest version.
@amdcq bug also in macos https://github.com/anthropics/claude-code/issues/19663
in \.claude\shell-snapshots snapshot-bash-xxx.sh . if remove set -o onecmd, every thing ok.
in windows , remove ~/.bashrc and ~/.bash_profile , will fix it. @codemile
@caozhiyuan Why would you remove ~/.bashrc instead of renaming it temporarily? There are custom instructions / settings stored here, i.e aliases, oh my bash, path exports, and so on
@amdcq There is no configuration in my two files. claude code bash automatically loads PATH, so no configuration is needed
@karl-keysingularity You do have a point. They mention first looking at issues submitted via /feedback and Github issues after that.
What I would recommend everyone doing is briefly updating to the newest version, starting a new claude code session and ask Claude Code to run something equivalent to
npm --versionor entering Bash mode by pressing ! and typingnpm --version(this does the same thing, just bypasses asking Claude Code to run it)After getting the expected output of "(No content)" proceed to create a bug report using /feedback via Claude Code
@caozhiyuan sorry, I don't understand what the fix is here. Are you saying removing
~/.bashrcand~/.bash_profileare the fixes, if so, why does it fix it?@codemile seems all bug raise by .claude shell snapshot dir sh file content. in windows delete .bashrc will cause sh content changed.
Huh, so I see its closed, but does that mean it's fixed, or it means "Im closing tickets that are open too long?"
It's fixed for me in 2.1.23.
Hi, I'm Kashyap with the Claude Code team. I've tried repro'ing this bug a few times across different versions (including latest), and haven't been able to repro it.
In case you're still facing this issue please send the following info which will make it easier to debug
bash --versionwinverclaude --versionecho $SHELLwhich bashbash -c -l "eval 'sh /path/to/script.sh' \< /dev/null"@km-anthropic Hey Kashyap, thanks for engaging on this. Respectfully, you should re-open this ticket; closing it as can't reproduce with so much active discussion and repros from paying customers sends the wrong signal and a lot of us are having to work around this daily in every session which is quite frustrating.
I'm still observing the issue with npm commands in Claude Code v2.1.23 on Windows (native):
<img width="1057" height="825" alt="Image" src="https://github.com/user-attachments/assets/beb1fb43-ccae-4f37-887c-bcb32c766e0c" />
Here is the additional diagnostic information you requested:
@evanwon try it. The latest version has more bugs and is very slow. suggest use 2.1.7
@caozhiyuan thanks, I'll test in the morning. I'm excited to see someone from Anthropic in the thread @km-anthropic thank you!
@km-anthropic I agree with what @evanwon has said, it doesn't make sense to close the issue, it's equivalent to "it works on my machine"
However I identified a reproducible process (which was one of the workarounds I put in this thread)
Setup
irm https://claude.ai/install.ps1 | iexThis works by default however once you have a .bashrc created (either by oh-my-bash or other common tools or setups) it causes the issue in this thread. The .bashrc created in the video (through claude code bash mode for convenience) does not matter if it is blank or has actual settings / instructions inside of it.
Removing or renaming .bashrc i.e
mv ~/.bashrc ~/.bashrc_backupand restarting Claude Code makes commands work properly again i.enpm.cmd -v>>npm -vORdocker.exe --version>>docker --versionand on Claude Code v2.1.7 you can have both ~/.bashrc and Claude Code work normally.Currently this breaks Claude Code for all Windows 11 Native users that have the .bashrc file. This breaks
https://github.com/user-attachments/assets/e5acffdf-87db-41c7-b75d-1089d0ab7dc5
Desktop App - Claude 1.1.1520
<img width="946" height="811" alt="Image" src="https://github.com/user-attachments/assets/a0b4a2c7-eca9-4443-8925-683583a1269e" />
VScode Extension - v2.1.25
<img width="491" height="892" alt="Image" src="https://github.com/user-attachments/assets/60bf8b6b-f45f-48ce-99bb-524a90c94fe4" />
Hey folks, given some users mentioned it was working in the latest release I'd closed it. Thanks for letting me know it's still occurring, @ant-kurt and I are taking a look.
Thanks for the addl. details @evanwon and @amdcq
Thanks @km-anthropic!
Further confirming what @amdcq and others have identified, today I tried removing my
~/.bashrcfile and it immediately resolved the issue. So it does seem like when.bashrcis present , or apparently even empty (in my case it just hadexport TERM=xterm-256colorin it), Claude is no longer able to see stdout from things like npm.<img width="989" height="381" alt="Image" src="https://github.com/user-attachments/assets/4e9e8676-e81e-49e3-ab61-358bf98688b0" />
Hey folks, we found a repro & hotfixed it (it was in-fact due to some nuances with the presence of ~/.bashrc). Please claude update to get to the latest version. The fix is also noted in our changelog here.
I'll still leave this open for another day or two to confirm it's resolved. Thanks for your patience y'all!
Fixed / working for me personally as of v2.1.27
<img width="619" height="464" alt="Image" src="https://github.com/user-attachments/assets/217f184e-0df7-434c-8b9f-0bdfc62d1e70" />
Confirmed working perfectly on my side. I tested both version 2.1.27 and now 2.1.29, and the issue is fully resolved in both cases. Thanks @km-anthropic !!!
This issue was fixed as of version 2.1.27.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.