Add Claude Code hooks for git worktree safety and toolchain setup#7261
Merged
Conversation
- check-bash-worktree.sh: PreToolUse Bash matcher that blocks commands referencing the main clone instead of the active worktree (parses absolute paths from tool_input.command). - worktree-context.sh: UserPromptSubmit hook that injects a one-line reminder of the active worktree on every user prompt, so the rule survives compaction and attention decay. - settings.json: register both hooks. Reminder + deterministic block give belt-and-suspenders coverage — the reminder shapes behavior, the block catches lapses. https://claude.ai/code/session_01Wo4ETjsNM4ggHqFSqRTyPN
Move the inline yarn-install SessionStart command into a dedicated .claude/hooks/session-start.sh and add ShellCheck installation. The pre-commit `shellcheck` Lefthook step requires shellcheck >= 0.10.0 and otherwise falls back to Docker. The Claude Code on the web container ships neither, so shell-script commits previously failed until shellcheck was installed by hand. The hook now installs the pinned binary (matching .ci/shellcheck/shellcheck.sh) so linting works on a cold start. Remote-only (CLAUDE_CODE_REMOTE), idempotent, and synchronous so deps are guaranteed ready before the session begins. https://claude.ai/code/session_01Wo4ETjsNM4ggHqFSqRTyPN
This was referenced May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three new Claude Code hooks to enforce git worktree isolation and ensure the lint toolchain is available in remote environments:
check-bash-worktree.sh— PreToolUse hook that blocks Bash commands referencing the main clone instead of the active worktree, preventing accidental operations outside the intended workspace.session-start.sh— SessionStart hook that installs Node dependencies and ShellCheck v0.10.0 in remote (web) environments, ensuring linting works without manual intervention.worktree-context.sh— UserPromptSubmit hook that injects worktree awareness into every user prompt, helping Claude understand the active workspace and avoid path confusion in long sessions.Updates
.claude/settings.jsonto register these hooks with appropriate matchers, timeouts, and status messages.Checklist
npx hugo --quiet)Test Plan
No testing needed — these are Claude Code configuration hooks that run in the Claude Code environment. The hooks are idempotent and safe to re-run; they exit cleanly when conditions don't apply (e.g., non-worktree repos, non-remote environments).
https://claude.ai/code/session_01Wo4ETjsNM4ggHqFSqRTyPN