claude-code - 💡(How to fix) Fix [Bug] Agent isolation: "worktree" flag ignored for concurrent background agents [2 comments, 3 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#48811Fetched 2026-04-16 06:50:18
View on GitHub
Comments
2
Participants
3
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2cross-referenced ×1
RAW_BUFFERClick to expand / collapse

Bug Description

Title: Agent tool's isolation: "worktree" flag silently ignored for concurrent background agents

Summary

The Agent tool accepts isolation: "worktree", documented as "creates a temporary git worktree so the agent works on an
isolated copy of the repo." When launching 3 concurrent background agents with this flag, no worktrees were created — all three agents ran in the shared main working tree and clobbered each other's uncommitted files via concurrent branch
switches.

Repro

  1. From a branch with some existing state, launch 3+ agents in a single message:
    Agent({ subagent_type: "general-purpose",
    isolation: "worktree",
    run_in_background: true, prompt: "git checkout -b test-<N> origin/main, write some new files, build, commit, push, open PR"
    })
  2. Let them run concurrently.

Expected: each agent gets its own worktree under .claude/worktrees/<something>. Main working tree and other agents' trees remain untouched.

Actual:

  • task-notification result includes worktreePath: /path/to/repo/.claude/worktrees/null (literal string "null") for every agent.
  • No worktrees appear in git worktree list that correspond to the agents.
  • All agents operate on the shared main working tree. When one runs git checkout -b …, it switches the branch for all;
    uncommitted/untracked files from the other agents get stashed, lost, or reverted.
  • Multiple agents independently reported: "a concurrent /batch agent clobbered the main repo working tree mid-run,
    dropping my first set of file writes." … Note: Content was truncated.

extent analysis

TL;DR

The "worktree" flag in the Agent tool is being ignored for concurrent background agents, causing them to operate on the shared main working tree instead of creating isolated worktrees.

Guidance

  • Verify that the isolation: "worktree" flag is correctly set for each agent and that the agents are running in the background with run_in_background: true.
  • Check the task-notification result for each agent to confirm that the worktreePath is not being set to "/path/to/repo/.claude/worktrees/null".
  • Investigate the Agent tool's documentation and implementation to ensure that the "worktree" flag is correctly handled for concurrent background agents.
  • Consider adding logging or debugging statements to the Agent tool to track the creation and usage of worktrees for each agent.

Example

No code snippet is provided as the issue does not include specific code details.

Notes

The issue may be related to a bug or limitation in the Agent tool's handling of concurrent background agents with the "worktree" flag. Further investigation is needed to determine the root cause and develop a fix.

Recommendation

Apply a workaround by launching each agent in a separate process or container to ensure isolation, until the root cause of the issue is determined and a fix is implemented.

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