Hooks not triggered when working in a git worktree

Resolved 💬 4 comments Opened Apr 11, 2026 by yuankuns Closed May 24, 2026

Summary

Claude Code hooks defined in .claude/settings.json are not triggered when the active working directory is a git worktree (created via git worktree add).

Environment

  • Claude Code CLI
  • Git worktree setup: main repo at /path/to/repo, worktree at /path/to/repo/worktrees/feature-branch

Steps to reproduce

  1. Set up a hook in .claude/settings.json at the main repo root, e.g. a PreToolUse hook on Bash that intercepts git commit
  2. Create a git worktree: git worktree add worktrees/my-feature -b my-feature
  3. Open a Claude Code session with the worktree as the working directory
  4. Run git commit from within the session

Expected: The PreToolUse hook fires and runs the configured command.

Actual: The hook is silently skipped. Claude Code does not find .claude/settings.json because it looks relative to the current working directory, not the git repository root.

Root cause

In a git worktree, the .git entry is a file (not a directory) that points back to the main repo. The .claude/ directory lives in the main repo root, not in the worktree directory. Claude Code appears to resolve .claude/settings.json relative to the process working directory rather than using git rev-parse --show-toplevel to locate the repository root and find .claude/ from there.

Impact

Any project that uses .claude/hooks/ for pre-commit checks, linters, or test runners will silently lose those guardrails whenever a developer works inside a git worktree. In our case, a PreToolUse hook runs cargo test inside Docker before every commit — this hook was bypassed in the worktree, causing tests to run directly on the host and inadvertently interact with the local tmux session.

Suggested fix

When resolving .claude/settings.json, fall back to git rev-parse --show-toplevel to find the repository root and look for .claude/ there, so hooks work consistently whether the session is started from the main worktree or any linked worktree.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗