claude-code - 💡(How to fix) Fix Worktree isolation breaks bare-repo worktree layouts by setting extensions.worktreeConfig [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45201Fetched 2026-04-09 08:10:55
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

Root Cause

When creating the isolated worktree, Claude Code:

  1. Sets extensions.worktreeConfig = true in the shared git config (.bare/config)
  2. Writes core.longpaths = true to the new worktree's config.worktree file
  3. Does not create config.worktree files for existing worktrees

Once extensions.worktreeConfig = true is set, core.bare becomes a per-worktree setting. The shared config has core.bare = true (it's a bare repo). Existing worktrees that don't have a config.worktree with core.bare = false now inherit core.bare = true and break.

Code Example

git clone --bare git@github.com:org/repo.git repo/.bare
   echo "gitdir: ./.bare" > repo/.git
   git -C repo worktree add main
   git -C repo worktree add feature/my-branch
RAW_BUFFERClick to expand / collapse

Bug Description

Claude Code's worktree isolation feature (isolation: "worktree") breaks existing worktrees in bare-repo layouts by setting extensions.worktreeConfig = true in the shared git config without updating existing worktrees.

Steps to Reproduce

  1. Set up a bare-repo worktree layout:

    git clone --bare [email protected]:org/repo.git repo/.bare
    echo "gitdir: ./.bare" > repo/.git
    git -C repo worktree add main
    git -C repo worktree add feature/my-branch
  2. Use Claude Code in one of the worktrees

  3. Claude Code's plan mode (or agent with isolation: "worktree") creates an isolated worktree under .claude/worktrees/<name>

  4. All existing worktrees (main, feature/my-branch) break — git commands fail or behave as if the repo is bare

Root Cause

When creating the isolated worktree, Claude Code:

  1. Sets extensions.worktreeConfig = true in the shared git config (.bare/config)
  2. Writes core.longpaths = true to the new worktree's config.worktree file
  3. Does not create config.worktree files for existing worktrees

Once extensions.worktreeConfig = true is set, core.bare becomes a per-worktree setting. The shared config has core.bare = true (it's a bare repo). Existing worktrees that don't have a config.worktree with core.bare = false now inherit core.bare = true and break.

Additional Issues

  • core.longpaths is a Windows-only setting (enables paths > 260 chars). Setting it on macOS/Linux is unnecessary and should be skipped on non-Windows platforms.
  • extensions.worktreeConfig is never set automatically by any git command — this is an explicit action by the Claude Code agent infrastructure.

Evidence

All three files modified at the same timestamp (Apr 7 17:50:05 2026):

  • .bare/configextensions.worktreeConfig = true added
  • .bare/worktrees/affectionate-borg/config.worktreecore.longpaths = true
  • .bare/worktrees/affectionate-borg/HEAD — worktree creation

Existing worktrees (main, azure-iac) had no config.worktree files and broke immediately.

Expected Behavior

When creating an isolated worktree in a bare-repo layout, Claude Code should either:

  1. Not set extensions.worktreeConfig if the only per-worktree config is core.longpaths on a non-Windows platform (skip the setting entirely)
  2. If extensions.worktreeConfig must be set, create config.worktree files with core.bare = false for all existing worktrees first

Environment

  • Platform: macOS (Darwin 25.4.0, Apple Silicon)
  • Git version: 2.49.0
  • Claude Code model: claude-opus-4-6 (1M context)
  • Repo layout: Bare repo with linked worktrees (git clone --bare pattern)

extent analysis

TL;DR

To fix the issue, Claude Code should create config.worktree files with core.bare = false for all existing worktrees before setting extensions.worktreeConfig = true in the shared git config.

Guidance

  • Verify that the issue is caused by the missing config.worktree files for existing worktrees by checking if core.bare = true is inherited from the shared config.
  • Create config.worktree files with core.bare = false for all existing worktrees manually to confirm that this resolves the issue.
  • Modify Claude Code to create these files automatically when setting extensions.worktreeConfig = true in the shared git config.
  • Consider skipping the setting of extensions.worktreeConfig if the only per-worktree config is core.longpaths on a non-Windows platform.

Example

# Create a config.worktree file for an existing worktree
echo "core.bare = false" > .bare/worktrees/main/config.worktree

Notes

The fix assumes that the issue is specific to the bare-repo layout with linked worktrees and may not apply to other repository layouts. Additionally, the core.longpaths setting should be skipped on non-Windows platforms.

Recommendation

Apply a workaround by creating config.worktree files with core.bare = false for all existing worktrees before using Claude Code in a bare-repo layout. This will prevent the existing worktrees from breaking due to the inherited core.bare = true setting.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Worktree isolation breaks bare-repo worktree layouts by setting extensions.worktreeConfig [1 participants]