← All hooks

Worktree Guard

blockingstable

Enforces worktree-based feature development per Common.md §U17. Rule 1: blocks ‘git checkout -b’ and ‘git switch -c’ in the primary worktree — feature work must live in a linked worktree so the primary repo stays on main. Rule 2: blocks ‘git worktree add’ to non-canonical paths. Canonical paths: <repo>/.worktrees/<name>/ for single-repo work, <repo>/.claude/worktrees/<name>/ for Claude Code's native EnterWorktree tool, ~/.ai/worktrees/<name>/ for cross-repo or persistent worktrees.

ID hook/worktree-guardVersion 1.3.0Author convergent-systems-key
ai hooks run worktree-guard
EventPreToolUseLanguagepythonTriggertool-nameBashSide effects
  • blocks new-branch creation (checkout -b / switch -c) in the primary worktree with worktree-add guidance
  • blocks non-canonical worktree placement with path guidance
linuxmacoswindowsLogic is cross-platform. Wiring: use ‘ai hooks run worktree-guard’ in settings.json — the ai binary discovers Python on each OS. Inspects git command strings via Python. Path separators handled by pathlib. Works on all platforms.
gitworktreegovernanceclaude-code
Attribution: convergent-systems-key.