Hook harness passes main checkout cwd instead of worktree cwd in payload

Resolved 💬 2 comments Opened Jun 2, 2026 by Abacin Closed Jun 6, 2026

Bug description

When a Claude Code session works inside a git worktree (created via git worktree add), the hook harness passes the main checkout path as cwd in the JSON payload to PreToolUse/PostToolUse hooks, instead of the actual worktree path where the session is operating.

This causes governance hooks that rely on cwd to determine the current branch to see main instead of the feature branch, leading to false positives (e.g. you are committing directly on main when the session is actually on a feature branch in a worktree).

Steps to reproduce

  1. Have a repo with Claude Code hooks configured in .claude/settings.json
  2. Create a worktree: git worktree add ../my-worktree feat/my-feature
  3. Start a Claude Code session that operates in the worktree
  4. The hook receives cwd pointing to the original repo checkout (on main), not ../my-worktree (on feat/my-feature)

Expected behavior

The cwd field in the hook JSON payload should reflect the actual working directory of the session. If the session is in a worktree, cwd should point to the worktree path.

Workaround

Sessions use git -C worktree-path for commit/push operations, bypassing the hook branch detection. This works but means hooks cannot enforce branch-level governance in worktree scenarios.

Environment

  • Claude Code on macOS (Tahoe 26.5)
  • Claude Opus 4.8 (1M context)
  • Multiple concurrent sessions using worktrees for isolation

View original on GitHub ↗

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