Update SessionStart hook command to handle CLAUDE_PLUGIN_ROOT template substitution path across Linux, Windows with WSL bash.exe and Windows with Git Bash#421
Conversation
📝 WalkthroughWalkthroughReplaces the SessionStart hook command in Changes
Sequence Diagram(s)(Skipped — change is a single-file hook command replacement without multi-component sequential interactions requiring diagramming.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@hooks/hooks.json`:
- Line 32: The command string uses RAW="${CLAUDE_PLUGIN_ROOT}" which leaves the
substituted path open to further bash expansion; change the RAW assignment to
use single quotes so the substituted value is single-quoted (e.g.,
RAW='${CLAUDE_PLUGIN_ROOT}') and adjust the outer quoting/escaping in the
"command" value so the shell-level single-quote wrapping remains valid; update
the same quoted occurrences that consume RAW (PLUGIN_UNIX_PATH, DRIVE, REST,
RESOLVED and the final call to hooks/session-start.sh) to continue to work with
the single-quoted RAW value and ensure no additional bash interpolation occurs.
🧹 Nitpick comments (1)
hooks/hooks.json (1)
30-30: Debug field is defined but not invoked.The
_debug_echofield stores a useful debug snippet, but it isn't executed by thecommand. Consider adding a brief note in the_commentexplaining how to use it (e.g., "paste into command afterRAW=...;to debug"), or alternatively, you could provide a separatecommand_debugvariant that includes it inline.
There was a problem hiding this comment.
Pull request overview
This PR updates the SessionStart hook to handle CLAUDE_PLUGIN_ROOT template substitution and path conversion across three bash environments: Git Bash on Windows, WSL bash, and native Linux bash. The change addresses Windows path handling issues (#420), HCS sandbox blocking (#417), and improves reliability of bash execution on Windows.
Changes:
- Replaced direct script invocation with inline bash command that performs path conversion
- Added logic to detect platform (Git Bash vs WSL vs Linux) and convert Windows paths to appropriate Unix-style formats (/c/... for Git Bash, /mnt/c/... for WSL)
- Avoided .sh extension in command to bypass Claude Code 2.1.x's automatic bash routing through HCS sandbox
- Included comprehensive documentation in comments explaining the template substitution and path conversion logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@hooks/hooks.json`:
- Line 32: The REST variable can lack a leading slash when backslashes are
stripped; inside the command where RAW, PLUGIN_UNIX_PATH, DRIVE, REST and
RESOLVED are computed, normalize REST to ensure exactly one leading slash (e.g.,
set REST="/${REST#/}" after computing REST and before using it to build
RESOLVED) so paths like C:Users... become /c/Users... and existing /Users/...
stay unchanged.
|
Thank you for this — the path normalization logic (detecting drive letters, converting for Git Bash vs WSL vs native Linux) is well thought out. Unfortunately the core issue is that Claude Code strips backslashes from We've addressed the fixable parts with |
Claude Code injects
CLAUDE_PLUGIN_ROOTvia template substitution BEFORE the shell runs therefore. Furthermore, command lines that match regex\.sh(\s|$|")are automatically handed over to bash for execution, even on Windows. The choice of which bash instance will be used on Windows depends on the user's + system's PATH sort order and if they have WSL installed with a distro or not. Finally, Windows paths contain backslashes and they conflict with Bash's string escaping.This command must work across three bash environments:
The command was augmented to parse the
OSenvironment variable to differentiate between WSL and Git Bash and parse the plugin path to detect if it's running on Linux. The final script does not require any dependency such asnodeorpythonto work.Motivation and Context
The
SessionStarthook is important to ensure that Claude Code will use its new skills consistently from the beginning.How Has This Been Tested?
claude.exe --debugand inspect the logs for the hook output.C:\Program Files\Git\binto top of system's PATH. Runclaude.exe --debugand inspect the logs for the hook output.claude --debugon Ubuntu 24.04.3 LTSTypes of changes
Checklist
Fixes #420, #417, #414, #413
Summary by CodeRabbit