[BUG] Bash tool returns exit 1 with no output for all commands on Windows/MINGW (set -o onecmd injection)
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?
Environment:
- Claude Code version: v2.1.45 (native installer)
- Platform: Windows 10/11, MINGW64 (Git Bash)
- Shell: bash via MINGW64_NT-10.0-26200
Symptoms:
- Every Bash tool call returns exit code 1 with empty output
- Affects all commands including echo "hello", pwd, git status
- Intermittent — works in some sessions, broken in others within the same day
- When broken, persists for the entire session (no recovery)
Root cause (diagnosed):
- Claude Code's shell snapshot mechanism injects set -o onecmd into $SHELLOPTS
- onecmd causes bash to exit after executing one command, which the tool interprets as failure
- Confirmed by comparing $SHELLOPTS in Claude Code (has onecmd) vs Codex in same environment (no onecmd)
Impact:
- All git operations, builds, typechecks, and terminal commands fail
- Skill auto-run commands (backtick blocks) abort entire skill load on first non-zero exit
- Led to ~1 hour of misdiagnosed "Windows/MINGW incompatibility" debugging, producing incorrect workarounds committed to codebase
- Workaround changes to /smart-commit skill were unnecessary — the commands were fine, the shell was broken
Related: #19057 (may be same issue — v2.1.30 changelog claimed a fix but it doesn't work on v2.1.45)
Repro:
- Open Claude Code on Windows/MINGW
- Run any Bash command: echo "hello"
- Observe exit code 1, no output
What Should Happen?
Bash tool commands should execute normally and return their actual exit code and output. echo "hello" should return exit 0 with "hello" as output. pwd should return the current directory. All standard bash commands should work regardless of Claude Code's internal shell state snapshotting.
Error Messages/Logs
Every Bash tool call returns exit code 1 with empty output:
> echo "hello"
Exit code 1
(no output)
> pwd
Exit code 1
(no output)
> git status
Exit code 1
(no output)
Diagnosed root cause: $SHELLOPTS contains "onecmd" which is injected by Claude Code's shell snapshot mechanism. Comparing same environment:
Claude Code $SHELLOPTS: braceexpand:hashall:interactive-comments:onecmd
Codex $SHELLOPTS: braceexpand:hashall:interactive-comments
The "onecmd" option causes bash to exit after a single command, which the Bash tool interprets as failure.
Bug is intermittent across sessions — some sessions work, others are broken from the start with no recovery. When broken, ALL commands fail for the entire session.
Platform: Windows 10/11, MINGW64_NT-10.0-26200 3.6.4, Claude Code v2.1.45 (native installer)
Steps to Reproduce
- Install Claude Code v2.1.45 via native Windows installer (not npm)
- Open Claude Code in a Git Bash / MINGW64 terminal on Windows
- Start a new conversation
- Ask Claude to run any Bash command, e.g.: "run echo hello"
- Observe: exit code 1, no output
Diagnosis step (run in a separate terminal, not through Claude Code):
echo $SHELLOPTS
# Expected: braceexpand:hashall:interactive-comments
# Actual (when bug is active): braceexpand:hashall:interactive-comments:onecmd
Key observations:
- Bug is session-level: if the first command fails, ALL commands fail for that session
- Starting a new conversation sometimes fixes it (new shell snapshot)
- The same terminal/environment works perfectly with Codex CLI
- No .bashrc or .bash_profile changes affect it — the onecmd injection happens inside Claude Code's shell snapshot mechanism
- Workarounds like renaming .bashrc, clearing BASH_ENV, and clearing snapshot cache do NOT fix it
- This is NOT a Windows/MINGW limitation — the same commands work in the same shell outside Claude Code
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.45
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
## System Details
- Terminal: Git Bash (MINGW64) — the default shell for Claude Code native Windows install
- OS: Windows 10, MINGW64_NT-10.0-26200 3.6.4-b9f03e96.x86_64
- Claude Code: v2.1.45 (native installer, not npm)
- Node: installed via pnpm
- Shell: /usr/bin/bash (MSYS2/MINGW64 bash)
Note: Git Bash is not listed in the terminal dropdown, but it's the shell
Claude Code defaults to on Windows native installs.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗