Agent tool `isolation: "worktree"` dispatch may corrupt parent repo `core.bare` flag
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 listshowed(bare)next to the primary worktree pathgit statusfailed withfatal: this operation must be run in a work tree- Read-only commands (
git rev-parse HEAD,git branch --show-current) continued to work git fsckreported 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
- Parent
.git/configinitially had nocore.bareentry.git worktree listat session start showed normal branch output (primary in attached state at HEAD @095f12315e27) - 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 lackednode_modules) +vitesttest runner execution +git push(blocked at pre-push hook)
- After dispatch 2, parent cleanup via
git worktree remove --force /home/adminaag/agentant/.claude/worktrees/agent-<uuid> - Subsequent commands in parent shell:
git statusfailed;git worktree listshowed parent as(bare);.git/configcontainedcore.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):
- From a CC session in a normal git repo with at least one secondary worktree, dispatch
Agent({isolation: "worktree", prompt: "..."})twice - Subagent 1 workload:
git checkout -b <branch>, write a file, safe-commit - Subagent 2 workload: same as 1 +
npm install+vitest run+git push(any failing condition at pre-push is fine) - Parent cleanup:
git worktree remove --forcefor each subagent worktree - Parent check:
git worktree listandgrep 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):
node_modulesnot bootstrapped: the isolated worktree had nonode_modulesdirectory, forcing the subagent to runnpm installbefore any test or script that required dependencies- Test subprocess
core.hooksPathinheritance: within the isolated worktree, test subprocesses that didgit initin a/tmp/sandbox(for vitest) inherited the parent repo's absolutecore.hooksPathpointer, causing hook scripts to be invoked with relative paths that failed to resolve against the/tmpsandbox. 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:
- Either fully isolate the subagent's git operations from the parent's
.git/config - Or document precisely which config mutations can propagate upward
- On cleanup, restore the parent to a known-good state rather than leaving
core.bare = truebehind
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.
3 Comments
Found 1 possible duplicate issue:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
On reflection with the project owner, retracting this report — the observations were likely a use-case mismatch on my end rather than a tool bug.
What I was actually trying to do: run 3 parallel long-running subagents (each performing a full PR workflow: npm install + vitest + git push + gh pr create, 3-4 hours of work each) inside a single parent CC session via
Agent({isolation: "worktree"}). The tool's design intent appears oriented toward shorter, parent-reviewed changes — not fully autonomous long-running workflows running concurrently. For our parallel long-running scenario we already had a proven pattern (separate tmux windows, each running its ownclaudeprocess withgit worktree add), which I should have stuck with from the start.On the
core.bareobservation specifically: I had only temporal correlation between isolation dispatches and the flag appearing, not direct causation evidence. Multiple other operations ran in the same window (subagent'ssafe-commit,npm install,vitesthooks,git pushpre-push hook, my owngit fetch). Any of them could have written the flag; I did not systematically eliminate them. Filing a bug report on that basis was premature.On the other two sub-observations (
node_modulesmissing in the isolated worktree, test helper absolutecore.hooksPathinheritance): the first is a reasonable design choice (worktree setup vs. dependency setup are separate concerns); the second is actually a defect in our test helpers (they don't use a hermetic env) and we've fixed it on our side (PR agentant-ops#515).Sorry for the noise and thank you for the thoughtful tool. Closing.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.