Skip to content

Add Claude Code hooks for git worktree safety and toolchain setup#7261

Merged
jstirnaman merged 3 commits into
masterfrom
claude/search-skills-instructions-Y8BUd
May 26, 2026
Merged

Add Claude Code hooks for git worktree safety and toolchain setup#7261
jstirnaman merged 3 commits into
masterfrom
claude/search-skills-instructions-Y8BUd

Conversation

@jstirnaman
Copy link
Copy Markdown
Contributor

Summary

Adds three new Claude Code hooks to enforce git worktree isolation and ensure the lint toolchain is available in remote environments:

  1. 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.

  2. session-start.sh — SessionStart hook that installs Node dependencies and ShellCheck v0.10.0 in remote (web) environments, ensuring linting works without manual intervention.

  3. 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.json to register these hooks with appropriate matchers, timeouts, and status messages.

Checklist

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

claude added 2 commits May 22, 2026 22:44
- 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
@jstirnaman jstirnaman requested a review from a team as a code owner May 26, 2026 14:42
@jstirnaman jstirnaman requested review from sanderson and removed request for a team May 26, 2026 14:42
@jstirnaman jstirnaman merged commit 42df2c4 into master May 26, 2026
10 checks passed
@jstirnaman jstirnaman deleted the claude/search-skills-instructions-Y8BUd branch May 26, 2026 20:15
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.

2 participants