EnterWorktree mid-session breaks Stop-hook execution (sandbox scope not updated, EPERM)

Status Open
Maintainer reply None cached
Activity 0 comments · opened Aug 27, 2026

Description

After calling the EnterWorktree tool mid-session (switching the session's cwd into a newly
created git worktree under .claude/worktrees/<name>/), all subsequent automatic hook
executions (observed with Stop hooks) fail with "Operation not permitted", even though the
exact same scripts ran fine seconds earlier via the interactive Bash tool from within the same
worktree.

Hypothesis

Hook execution seems to run under a separate sandbox scope from the interactive Bash tool,
fixed at session start. EnterWorktree moves the session into a new worktree mid-session, but
this scope doesn't get updated — so hook-triggered executions fall outside the allow-list and
fail with EPERM for the rest of the session.

Environment

macOS (Apple Silicon), hooks registered via project .claude/settings.json and user-local
.claude/settings.local.json, worktree created via the EnterWorktree tool mid-session.

Possibly related

#33657, #53891, #51303

View original on GitHub ↗