-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix Windows startup hook failure caused by inherited SHELLOPTS #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
On Windows with Git Bash, Claude Code can inherit a SHELLOPTS environment variable that includes the 'onecmd' option. When bash inherits this exported variable, it enables onecmd mode which causes scripts to exit after processing one compound command - breaking any script that uses 'set -euo pipefail'. This causes the SessionStart hook to fail with: "SessionStart:startup hook error" The fix uses 'env -u SHELLOPTS' to unset this variable before invoking bash, ensuring the script runs in a clean environment. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe session-start hook command is modified to execute the bash script with an unmodified shell environment by wrapping it with Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I tested this fix and it did not work on my setup.
|
|
In my case the best I could come up with was to use Git Bash's full path instead of /bin/bash. It seems to be some conflict between Git Bash and WSL bash (I am not running CC on WSL though). Obviously this won't work for Linux. Final working config: {
"hooks": {
"SessionStart": [
{
"matcher": "startup|resume|clear|compact",
"hooks": [
{
"type": "command",
"command": "\"C:\\Program Files\\Git\\bin\\bash.exe\" -c \"source \\\"$(cygpath \\\"$CLAUDE_PLUGIN_ROOT\\\")/hooks/session-start.sh\\\"\""
}
]
}
]
}
} |
Problem
On Windows with Git Bash, the superpowers
SessionStarthook fails with:This happens because Claude Code's shell environment exports
SHELLOPTSwith theonecmdoption enabled:When bash inherits this exported variable and runs
session-start.sh, theonecmdoption causes bash to exit after processing one compound command. Combined withset -euo pipefailin the script, this causes the script to exit before producing any output.Root Cause Analysis
SHELLOPTSis exported withonecmdbash session-start.sh, bash inheritsSHELLOPTSand enables all those optionsonecmdoption (equivalent toset -t) causes bash to "exit after reading and executing one command"set -euo pipefailruns, the script exits immediatelyReproduction
Solution
Use
env -u SHELLOPTSto unset the problematic environment variable before invoking bash. This ensures the script runs in a clean environment regardless of what shell options are inherited.Testing
Tested on Windows 11 with Git Bash 5.1.16 and Claude Code 2.1.x. After applying this fix, the startup hook works correctly and the "SessionStart:startup hook error" message no longer appears.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.