Skip to content

Fix run-hook.cmd script directory resolution on Unix#484

Open
njt wants to merge 1 commit intoobra:devfrom
njt:fix/run-hook-cmd-script-dir-resolution
Open

Fix run-hook.cmd script directory resolution on Unix#484
njt wants to merge 1 commit intoobra:devfrom
njt:fix/run-hook-cmd-script-dir-resolution

Conversation

@njt
Copy link

@njt njt commented Feb 16, 2026

Summary

  • run-hook.cmd uses ${BASH_SOURCE[0]:-$0} to find its own directory, but when Claude Code invokes the command via sh -c, BASH_SOURCE is unavailable and $0 resolves to the cwd instead of the script's location
  • This causes exec bash "${SCRIPT_DIR}/session-start" to look in the wrong directory, producing SessionStart:startup hook error on every session start
  • Fix: prefer $CLAUDE_PLUGIN_ROOT (which Claude Code sets as an env var) when available, falling back to the existing $0-based resolution for direct invocation

How it was diagnosed

  • Debug instrumentation revealed SCRIPT_DIR resolving to the user's cwd (e.g. ~/Source/some-project) rather than the plugin cache directory
  • The session-start script never executed — the wrapper failed before reaching it
  • Confirmed by testing in a tmux child session where the cwd differed from the plugin cache path

Test plan

  • Start a Claude Code session from a directory that is NOT the plugin cache — no SessionStart:startup hook error should appear
  • Verify the superpowers skill content is injected into the session context
  • Direct invocation of run-hook.cmd session-start from CLI should still work (fallback path)

🤖 Generated with Claude Code

When Claude Code invokes run-hook.cmd via sh -c, BASH_SOURCE is
unavailable and $0 resolves to the cwd rather than the script location.
This causes the hook to look for session-start in the wrong directory,
producing a SessionStart:startup hook error on every session.

Use CLAUDE_PLUGIN_ROOT (set by Claude Code as an env var) when available,
falling back to the existing $0-based resolution for direct invocation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

Comments