[BUG] Bash onecmd option causes npm script output to be lost on Windows
Environment
- Claude Code version: VS Code Extension (latest)
- Operating System: Windows 11
- Shell: Git Bash (via CLAUDE_CODE_GIT_BASH_PATH)
- Node version: v24.x
Bug Description
When running npm scripts (like npm run build) through Claude Code's Bash tool, the output is completely lost/invisible. The commands execute successfully but return no output to Claude.
Root Cause
Claude Code sets the bash onecmd option (equivalent to set -t) in SHELLOPTS when spawning bash processes. This option causes bash to exit after reading and executing one command.
When npm runs scripts with shebang (e.g., #!/usr/bin/env node), the onecmd option causes the parent shell to exit before the script can produce output.
Evidence:
$ echo $SHELLOPTS
braceexpand:hashall:igncr:interactive-comments:monitor:onecmd
Even spawning a fresh bash instance shows onecmd is set:
$ bash -c 'echo $SHELLOPTS'
braceexpand:hashall:igncr:interactive-comments:onecmd
Steps to Reproduce
- Open Claude Code in VS Code on Windows with Git Bash configured
- Ask Claude to run
npm run build(or any npm script that uses node) - Observe that the command completes but no output is shown
Expected Behavior
npm script output should be visible to Claude, showing compilation results, errors, etc.
Actual Behavior
Commands execute but return empty output or "no content", making it impossible to verify build success or diagnose errors.
Workaround
Prefix all bash commands with set +o onecmd;:
set +o onecmd; npm run build 2>&1
This disables the onecmd option before running the actual command.
Suggested Fix
Don't set the onecmd (-t) option when spawning bash processes, or provide a configuration option to control shell options.
Related Issues
- #5041 - Bash output not getting picked up (closed as duplicate, but root cause not identified)
- #4507 - Git Bash path issues
6 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Closing as duplicate of #19057 which has a more detailed root cause analysis. The issue is the same:
set -o onecmdin shell snapshots breaks npm/subprocess stdout on Windows/Git Bash.Still broken in v2.1.19 on Windows 11 + Git Bash.
Reproduction:
npm view @anthropic-ai/claude-code version→ no outputclaude --version→ no outputnode -e "console.log(require('child_process').execSync('...').toString())"Workaround for others: Use the node execSync wrapper instead of direct commands.
This is blocking basic version checking and update workflows.
This is still an issue on Claude Code 2.1.x, Windows 11, Node v24.12.0 with Git Bash. Running npm run test (vitest) through the Bash tool returns empty output and exit code 0 even when tests are failing. This caused broken code to be pushed to CI multiple times because Claude believed tests passed when they didn't.
Still broken
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.