Claude Desktop creates session worktrees inside the repo root, ignoring CLAUDE.md rules and WorktreeCreate hook block decisions

Resolved 💬 3 comments Opened Apr 17, 2026 by yichen Closed Apr 21, 2026

Environment

  • Claude Desktop (macOS)
  • Repo uses git worktrees extensively; project CLAUDE.md mandates worktrees live as sibling directories of the main repo, not as subdirectories of it.

Expected

When starting a new Claude Desktop session on a linked repo, the session worktree should be creatable outside the main repo — either via a user-level "worktree parent directory" preference, or by respecting a project-level hook that rejects a path.

Actual

The app hardcodes worktreePath = originCwd + "/" + <random-slug> with no user-facing override. Each new session creates a new subdirectory inside the main repo root, e.g.:

<repo-root>/
  thirsty-leavitt-21670b/   ← session worktree
  kind-khayyam-174f8e/      ← another session worktree
  ...

This pollutes git status (each slug dir shows as untracked in the main repo), violates project conventions that require sibling layout, and makes manual cleanup tedious.

What I tried

  1. PreToolUse Bash hook that blocks git worktree add <path> when <path> is inside the repo. Doesn't fire — the app creates the worktree through native machinery, not a Bash tool call.
  2. WorktreeCreate hook returning {"decision":"block","reason":"..."}. Also doesn't fire in time — the worktree is already created on disk when a subsequent session starts inside it.

Session JSON under ~/Library/Application Support/Claude/claude-code-sessions/.../local_*.json confirms the path layout:

{
  "originCwd": "/Users/<me>/<repo-root>",
  "worktreePath": "/Users/<me>/<repo-root>/<slug>",
  "worktreeName": "<slug>",
  "sourceBranch": "main",
  "branch": "claude/<slug>"
}

Requested fixes (any one would resolve this)

  1. Honor decision: "block" on WorktreeCreate hooks and abort session startup when blocked.
  2. Add a user-level setting (e.g. coworkWorktreeParentDir in ~/.claude/settings.json or ~/Library/Application Support/Claude/config.json) to override where session worktrees are placed.
  3. Default to sibling-directory placement (<repo-parent>/<repo-name>-<slug>) since co-located subdirectories are almost always wrong — they inflate the main repo's git status, conflict with build/test caches, and aren't a shape most projects want.

Why it matters

  • Breaks projects whose CLAUDE.md explicitly forbids in-repo worktrees.
  • Forces manual cleanup after every session.
  • Untracked slug directories risk being accidentally git add'd.

View original on GitHub ↗

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