Stop hook config leaks across git worktree sessions

Status Open
Maintainer reply None cached
Activity 2 comments · opened Aug 11, 2026

Description

A Stop hook configured in one git worktree's .claude/settings.json fires in a Claude Code session running in a different worktree of the same repository — even though that worktree's own checked-out branch has no Stop hook entry and no hook script on disk.

Setup

  • A repo has two git worktree checkouts:
  • Worktree A: branch feature/GD-3505, whose .claude/settings.json defines a Stop hook (python3 .claude/hooks/prompt_stop_guard.py), and whose working tree contains .claude/hooks/prompt_stop_guard.py.
  • Worktree B: a different branch that predates the commit adding that hook. Its .claude/settings.json has no hooks key at all, and .claude/hooks/prompt_stop_guard.py does not exist anywhere in its checked-out tree.
  • Both worktrees share the same underlying .git (created via git worktree add).

Expected

A Claude Code session running with cwd inside Worktree B should only apply project settings/hooks from Worktree B's own checked-out .claude/settings.json.

Actual

The session running in Worktree B triggers Worktree A's Stop hook, which fails because the hook script's relative path doesn't resolve against Worktree B's cwd:

Stop hook error: Hook script appears to be missing — "python3 .claude/hooks/prompt_stop_guard.py" exited 2 with: python3: can't open file '<worktree-B-path>/.claude/hooks/prompt_stop_guard.py': [Errno 2] No such file or directory. Treating as non-blocking. If this is a plugin hook, check the plugin install (run /plugin).

The error is currently treated as non-blocking, so functionally harmless, but it's confusing/noisy and indicates settings resolution isn't fully scoped per-worktree.

Guess at root cause

Project settings resolution may be keyed off the repository's common .git directory (shared across worktrees) rather than the specific worktree's own working directory, so it picks up whichever worktree's .claude/settings.json was resolved as "the" project settings, while still executing hook commands with the actual session's cwd.

View original on GitHub ↗

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