Skip to content

Conversation

@danshapiro
Copy link

@danshapiro danshapiro commented Jan 25, 2026

Problem

On Windows with Git Bash, the superpowers SessionStart hook fails with:

SessionStart:startup hook error

This happens because Claude Code's shell environment exports SHELLOPTS with the onecmd option enabled:

SHELLOPTS=braceexpand:hashall:igncr:interactive-comments:monitor:onecmd

When bash inherits this exported variable and runs session-start.sh, the onecmd option causes bash to exit after processing one compound command. Combined with set -euo pipefail in the script, this causes the script to exit before producing any output.

Root Cause Analysis

  1. Claude Code on Windows runs in an environment where SHELLOPTS is exported with onecmd
  2. When the hook runs bash session-start.sh, bash inherits SHELLOPTS and enables all those options
  3. The onecmd option (equivalent to set -t) causes bash to "exit after reading and executing one command"
  4. When set -euo pipefail runs, the script exits immediately
  5. No JSON output is produced, so Claude Code reports a hook error

Reproduction

# With SHELLOPTS containing onecmd:
$ bash session-start.sh
# (no output, exits silently)

# Without SHELLOPTS:
$ env -u SHELLOPTS bash session-start.sh
{
  "hookSpecificOutput": {
    "hookEventName": "SessionStart",
    ...
  }
}

Solution

Use env -u SHELLOPTS to 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

  • Bug Fixes
    • Improved session initialization hook environment handling to ensure consistent shell configuration during startup.

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

The session-start hook command is modified to execute the bash script with an unmodified shell environment by wrapping it with env -u SHELLOPTS bash, preventing inherited SHELLOPTS from affecting script execution.

Changes

Cohort / File(s) Summary
Session-start hook configuration
hooks/hooks.json
Modified hook invocation to wrap bash script execution with env -u SHELLOPTS, removing inherited shell options from the environment

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 A hop through the shell, so clean and so bright,
We strip away options that cloud up the night,
With env and SHELLOPTS gone from the way,
Our hooks now start fresh, hip-hip-hooray!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: fixing a Windows startup hook failure caused by inherited SHELLOPTS environment variable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant