claude-code - 💡(How to fix) Fix Agent tool `isolation: "worktree"` dispatch may corrupt parent repo `core.bare` flag [2 comments, 2 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#51930Fetched 2026-04-23 07:41:06
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2closed ×1

Error Message

  • No error is emitted during the dispatch itself — the problem surfaces only on the next normal git command, which may be minutes or hours later

Root Cause

  1. Parent .git/config initially had no core.bare entry. git worktree list at session start showed normal branch output (primary in attached state at HEAD @ 095f12315e27)
  2. Two subagent dispatches with isolation: "worktree" executed in quick succession within the same CC session. Workloads performed inside the isolated worktrees:
    • Dispatch 1: git checkout -b, file creation, bash scripts/safe-commit.sh (commit succeeded)
    • Dispatch 2: same as above + bash scripts/write-review-marker.sh + npm install (142 packages, needed because subagent worktree lacked node_modules) + vitest test runner execution + git push (blocked at pre-push hook)
  3. After dispatch 2, parent cleanup via git worktree remove --force /home/adminaag/agentant/.claude/worktrees/agent-<uuid>
  4. Subsequent commands in parent shell: git status failed; git worktree list showed parent as (bare); .git/config contained core.bare = true

Fix Action

Fix / Workaround

After dispatching a subagent via the Agent tool with isolation: "worktree" parameter, the parent repository's .git/config contained core.bare = true. This rendered the primary worktree inoperative:

  • Claude Code CLI: as of 2026-04-22
  • OS: Linux Ubuntu 24.04
  • Repository: standard (non-bare) multi-worktree setup (primary + one secondary at time of dispatch)
  1. Parent .git/config initially had no core.bare entry. git worktree list at session start showed normal branch output (primary in attached state at HEAD @ 095f12315e27)
  2. Two subagent dispatches with isolation: "worktree" executed in quick succession within the same CC session. Workloads performed inside the isolated worktrees:
    • Dispatch 1: git checkout -b, file creation, bash scripts/safe-commit.sh (commit succeeded)
    • Dispatch 2: same as above + bash scripts/write-review-marker.sh + npm install (142 packages, needed because subagent worktree lacked node_modules) + vitest test runner execution + git push (blocked at pre-push hook)
  3. After dispatch 2, parent cleanup via git worktree remove --force /home/adminaag/agentant/.claude/worktrees/agent-<uuid>
  4. Subsequent commands in parent shell: git status failed; git worktree list showed parent as (bare); .git/config contained core.bare = true
RAW_BUFFERClick to expand / collapse

Observation

After dispatching a subagent via the Agent tool with isolation: "worktree" parameter, the parent repository's .git/config contained core.bare = true. This rendered the primary worktree inoperative:

  • git worktree list showed (bare) next to the primary worktree path
  • git status failed with fatal: this operation must be run in a work tree
  • Read-only commands (git rev-parse HEAD, git branch --show-current) continued to work
  • git fsck reported HEALTHY (objects + index intact)

Environment

  • Claude Code CLI: as of 2026-04-22
  • OS: Linux Ubuntu 24.04
  • Repository: standard (non-bare) multi-worktree setup (primary + one secondary at time of dispatch)

Timeline

  1. Parent .git/config initially had no core.bare entry. git worktree list at session start showed normal branch output (primary in attached state at HEAD @ 095f12315e27)
  2. Two subagent dispatches with isolation: "worktree" executed in quick succession within the same CC session. Workloads performed inside the isolated worktrees:
    • Dispatch 1: git checkout -b, file creation, bash scripts/safe-commit.sh (commit succeeded)
    • Dispatch 2: same as above + bash scripts/write-review-marker.sh + npm install (142 packages, needed because subagent worktree lacked node_modules) + vitest test runner execution + git push (blocked at pre-push hook)
  3. After dispatch 2, parent cleanup via git worktree remove --force /home/adminaag/agentant/.claude/worktrees/agent-<uuid>
  4. Subsequent commands in parent shell: git status failed; git worktree list showed parent as (bare); .git/config contained core.bare = true

Recovery

git config --unset core.bare restored normal operation. No data loss. Working tree content intact.

Impact

Even though recovery is trivial once identified, the corruption is severe:

  • Any repo-level git operations fail silently in interactive sessions that follow the corruption
  • In a multi-worktree setup (common for parallel CC-session workflows where the primary worktree is where most work happens), this breaks the entire primary session context
  • No error is emitted during the dispatch itself — the problem surfaces only on the next normal git command, which may be minutes or hours later

Not reproduced after initial observation

I deliberately did not attempt to reproduce this after the initial cleanup, to avoid risking repeated parent corruption in a production-adjacent development environment. Reproducer pattern (if attempted in a throw-away repo):

  1. From a CC session in a normal git repo with at least one secondary worktree, dispatch Agent({isolation: "worktree", prompt: "..."}) twice
  2. Subagent 1 workload: git checkout -b <branch>, write a file, safe-commit
  3. Subagent 2 workload: same as 1 + npm install + vitest run + git push (any failing condition at pre-push is fine)
  4. Parent cleanup: git worktree remove --force for each subagent worktree
  5. Parent check: git worktree list and grep bare .git/config

Related observations during the same session

Two other issues surfaced in the isolated worktree context (may or may not be related to the main core.bare issue):

  1. node_modules not bootstrapped: the isolated worktree had no node_modules directory, forcing the subagent to run npm install before any test or script that required dependencies
  2. Test subprocess core.hooksPath inheritance: within the isolated worktree, test subprocesses that did git init in a /tmp/sandbox (for vitest) inherited the parent repo's absolute core.hooksPath pointer, causing hook scripts to be invoked with relative paths that failed to resolve against the /tmp sandbox. Same test code passes from the user's primary or secondary (git worktree add-style) worktrees.

These three observations together made isolation: "worktree" unusable for our production workflows. We have adopted a separate CC session per tmux window pattern (git worktree add + parallel claude processes) which avoids all three issues.

Suggested direction

Whatever Agent tool path performs subagent worktree setup/teardown should:

  1. Either fully isolate the subagent's git operations from the parent's .git/config
  2. Or document precisely which config mutations can propagate upward
  3. On cleanup, restore the parent to a known-good state rather than leaving core.bare = true behind

I'm happy to provide more detail or help debug further — the initial incident is captured in a local memory record (can share context on request). The concern is primarily about silent corruption, not the specific flag.

extent analysis

TL;DR

The core.bare = true issue in the parent repository's .git/config can be fixed by ensuring the Agent tool properly isolates subagent git operations or restores the parent repository to a known-good state after cleanup.

Guidance

  • Verify that the Agent tool's subagent worktree setup and teardown processes do not modify the parent repository's .git/config file.
  • Consider using a separate git configuration for the subagent worktree to prevent config mutations from propagating upward.
  • After subagent cleanup, use git config --unset core.bare to restore the parent repository to a non-bare state if necessary.
  • Review the Agent tool's documentation to ensure it accurately describes potential config mutations and their effects on the parent repository.

Example

No code snippet is provided as the issue is related to the Agent tool's behavior and git configuration.

Notes

The root cause of the issue is likely related to the Agent tool's handling of subagent worktree setup and teardown. The provided reproducer pattern may help identify the exact cause, but it has not been attempted due to concerns about repeated parent corruption.

Recommendation

Apply a workaround by using a separate CC session per tmux window pattern (git worktree add + parallel claude processes) to avoid the core.bare = true issue, as this approach has been shown to be effective in preventing the problem.

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 Agent tool `isolation: "worktree"` dispatch may corrupt parent repo `core.bare` flag [2 comments, 2 participants]