[BUG] EnterWorktree fails for sub-repo worktrees in multi-repo workspaces (background session isolation deadlock)

Open 💬 0 comments Opened Jul 3, 2026 by sdx-BRE

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Bug Description

Title: EnterWorktree fails for sub-repo worktrees in multi-repo workspaces (background session isolation deadlock)

Related issues (checked, not duplicates):

  • #64635 — same symptom (Edit/Write blocked, same workaround), but root cause is an

interactive CLI session being wrongly classified as a background job. Our case is a
correctly-classified background job where EnterWorktree is structurally unable to
resolve the path.

  • #64640 — same symptom again, but root cause is a remote-control session being routed

through the daemon backend and incorrectly inheriting background-job isolation semantics.
Also highlights that bgIsolation: none is undiscoverable until an edit is already
blocked — which is the same secondary issue we describe.

  • #65616 — also involves bgIsolation sequencing, but that report has

bgIsolation: "worktree" set and hits a timing issue (worktree entered too late,
causing one wasted retry). Our case has no setting at all and hits a hard deadlock
with no recovery path.

---

Environment

  • Claude Code v2.1.199
  • macOS
  • Background session (correctly classified as background, unlike #64635)

---

What happened

In a multi-repo workspace where individual sub-repos are separate git repositories nested inside an outer "header" repository, the background session isolation guard permanently blocks all file edits.

Workspace structure:

<path/to>/workspace-directory/           ← outer git repo (session cwd)
  <path/to>/sub-repo/                            ← separate git repo (own .git)
  .worktrees/
    <task-name>/
      <path/to>/sub-repo/                        ← worktree of sub-repo, NOT of outer repo

The deadlock:

  1. Background session starts in t
  2. A project script creates a worered in that sub-repo's git history
  3. Claude's EnterWorktree runs he outer repo's cwd — the

sub-repo worktree is invisible th

  1. EnterWorktree refuses the parmanently blocked
  2. The workaround (bgIsolation: none in settings.local.json) cannot be applied by the assistant because Edit/Write are already blocked

Verification that the worktree is valid (just not visible to the outer repo):

git -C <path/to>/sub-repo worktree list
# correctly lists .worktrees/<tas a registered worktree

---

Expected behavior

EnterWorktree should detect whichn path (by walking up to the owning
.git), run git -C <owning-repo> wpath if it appears there —mirroring how git -C works.

---

Current behavior

Only git worktree list at the sespo worktrees never appear → path
rejected → edits blocked for the

---

Reproduction

  1. Outer git repo at <path/to>/worepo at<path/to>/workspace-directory/<path/to>/sub-repo (own .git)
  2. Create a worktree of the sub-r

git -C <path/to>/sub-repo worktree add ../../.worktrees/my-task/<path/to>/sub-repo my-branch

  1. Start a background Claude sessdirectory
  2. Call EnterWorktree with path .worktrees/my-task/<path/to>/sub-repo
  3. → Error: not a registered worktree of <path/to>/workspace-directory

---

Suggested fix

In EnterWorktree,  before rejecting a path: walk up from the given path to find the owning git repo, then check git -C <owning-repo> worktree list. Accept the path if it appears there.

---

Secondary issue (catch-22)

When this deadlock occurs, the workaround ("worktree": {"bgIsolation": "none"} in settings.local.json) cannot be applied by the assistant — Edit/Write are the very tools that are blocked. The user must manually edit the file.

Suggested mitigation: allow writes to .claude/settings.local.json without the isolation requirement, or detect the catch-22 and print a clear error with the exact line to add.

---

Workaround

Add to .claude/settings.local.json (gitignored, machine-local):
"worktree": { "bgIsolation": "none" }

Note: this must be set by each user manually and cannot be distributed via the checked-in settings.json.

What Should Happen?

EnterWorktree should resolve the owning git repository for a given path by walking up
the directory tree to find the responsible .git, then check
git -C <owning-repo> worktree list instead of only checking the session's cwd.

This mirrors how git -C works and would make sub-repo worktrees visible to the guard.

Example — currently fails, should succeed:

# Sub-repo worktree is valid and registered:
git -C <path/to>/workspace-directory/<path/to>/sub-repo worktree list
# → .worktrees/<task-name>/<path/to>/sub-repo  [my-branch]  ✓

# But EnterWorktree only checks the outer repo and rejects the path:
git -C <path/to>/workspace-directory worktree list
# → path not listed → EnterWorktree fails → Edit/Write permanently blocked

Additionally, the self-blocking situation (assistant cannot write settings.local.json
to disable the guard, because the guard blocks writes) should be addressed — either by
exempting .claude/settings.local.json from the isolation requirement, or by detecting
the situation and printing a clear error with the exact config line to add.

Error Messages/Logs

Steps to Reproduce

  1. Create a multi-repo workspace: an outer git repo containing one or more sub-repos,

each with their own .git:

   <path/to>/workspace-directory/          ← outer git repo (session cwd)
     <path/to>/sub-repo/                           ← separate git repo (own .git)
  1. Create a worktree of the sub-repo (e.g. via a project script or manually):
git -C <path/to>/workspace-directory/<path/to>/sub-repo \
  worktree add ../../.worktrees/<task-name>/<path/to>/sub-repo my-branch
  1. Verify the worktree is correctly registered in the sub-repo:
git -C <path/to>/workspace-directory/<path/to>/sub-repo worktree list
# → .worktrees/<task-name>/<path/to>/sub-repo  [my-branch]  ✓
  1. Start a background Claude session from <path/to>/workspace-directory
  2. Call EnterWorktree with path .worktrees/<task-name>/<path/to>/sub-repo
  3. → Error: not a registered worktree of <path/to>/workspace-directory
  4. All Edit/Write calls are now permanently blocked for the session — no recovery

path exists without manually editing settings.local.json outside the session

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.199

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗