claude-code - ✅(Solved) Fix Agent tool isolation: "worktree" forks from default branch instead of caller's current HEAD [1 pull requests, 1 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#45371Fetched 2026-04-09 08:06:58
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Timeline (top)
labeled ×4referenced ×2commented ×1cross-referenced ×1

When dispatching a subagent via the Agent tool with isolation: "worktree" from a non-default branch, the resulting worktree consistently forks from the default branch (main) instead of the caller's current branch HEAD. This silently gives subagents the wrong baseline.

Root Cause

When dispatching a subagent via the Agent tool with isolation: "worktree" from a non-default branch, the resulting worktree consistently forks from the default branch (main) instead of the caller's current branch HEAD. This silently gives subagents the wrong baseline.

Fix Action

Workaround

Have the subagent run `git checkout <current-branch> -- <paths>` and commit a "baseline-sync" as its first action, then extract only its incremental work via `git diff baseline-sync HEAD` on merge.

PR fix notes

PR #4: Syndicate run-1: cross-project promotion + token discipline + live validation

Description (problem / solution / changelog)

Six-generation self-improvement run on the syndicate plugin itself. Job mode. Converged.

Goal

Improve the syndicate plugin. Priority: user-level cross-project promotion so every run potentially improves every future run. Beyond that, propose and implement other improvements grounded in online research.

What Landed

Cross-project promotion (gen-1-a): Learned agents and domain skills promote to ~/.claude/agents/ and ~/.claude/skills/ by default. Collision policy: fall back to project-level install and log, never silently overwrite prior runs' work. Discovery at Gen 0 lazy-loads full artifact contents only when trigger conditions match. User manifest schema includes provenance + empirical fields (uses_count, score_deltas, avg_score_delta, last_used, flagged).

Token discipline (gen-2-c): Editorial pass shrank SKILL.md by ~10%, loop.md by ~4%, task.md by ~13%. Zero load-bearing content removed. Per Anthropic context engineering guidance, LLMLingua-2 (ACL 2024), Chroma Context Rot (2025): redundant phrasing is a distractor, not just wasted tokens.

Live validation + bootstrap fixes (gen-3-b): Executed the bootstrap procedure twice in disposable scratch projects. Found and fixed three real bugs:

  1. git symbolic-ref refs/remotes/origin/HEAD can exit non-zero even with a remote; added explicit fallback.
  2. Gen 0 discovery under-specified when ~/.claude/syndicate-manifest.jsonl is missing on a fresh machine; now writes empty discovered.jsonl.
  3. git tag syndicate-seed-<N> fails with fatal: no tag message? under widespread tag.gpgSign=true / tag.forceSignAnnotated=true configs. Fixed with git -c tag.gpgSign=false tag -a -m. This bug actually bit the run at bootstrap time.

Convergence threshold tuning (gen-3-b): Replaced single-clause "4.8+ for 2 consecutive gens" with a dual OR including "4.5+ with delta<0.1 for 3 consecutive gens", grounded in EA plateau-detection literature.

Mutation operator taxonomy (gen-4): Five-operator set {rewrite, constrain, decompose, invert, borrow} required on every variant. Same-operator collisions don't count as diversity. Sourced from PromptBreeder (Fernando 2023, arXiv:2309.16797) and EvoPrompt (Guo 2023, arXiv:2309.08532).

Empirical discovery ranking (gen-4): rank = 0.5 * desc_match + 0.2 * use_signal + 0.3 * quality with cold-start fallback for unproven entries. Auto-flag rule at uses_count >= 3 and avg_score_delta <= 0, reversible. Sourced from Voyager (Wang 2023) and Lifelong LLM Agents roadmap (Zheng 2025, arXiv:2501.07278).

Worktree isolation workaround: Claude Code's isolation: "worktree" currently forks from the default branch rather than the caller's HEAD, silently giving subagents the wrong baseline. Filed upstream as anthropics/claude-code#45371. Mandatory baseline-sync procedure baked into plugin/skills/run/references/loop.md so every future run handles it until upstream ships a fix.

What Did Not Land

Several research-grounded variants were pruned during exploration and banked in syndicate/meta-notes.md:

  • Full pairwise LLM-as-judge scoring procedure (gen-2-a): deferred; expensive at small variant counts.
  • Shared learning layer dual-tier canonical+runtime-mirror (gen-1-c): deferred; Claude Code's native user-level discovery already covers the runtime-surface concern.
  • Ratchet integrity audit + MAST failure-mode taxonomy (gen-3-c): attempted in trimmed form in gen-5, flagged by coherence for bulk-without-gain, reverted.

Score Trajectory

4.20 (gen 1) -> 4.67 (gen 2) -> 4.83 (gen 3) -> 5.00 (gen 4) -> 4.83 flagged+reverted (gen 5) -> 5.00 (gen 6).

Converged: gens 4 and 6 both at 5.0 in convergence phase, gen 5 cleanly reverted with the coherence firewall doing its job.

Full Report

syndicate/reports/final.md

Related

Changed files

  • .gitignore (modified, +1/-0)
  • plugin/agents/task.md (modified, +3/-3)
  • plugin/skills/run/SKILL.md (modified, +47/-47)
  • plugin/skills/run/references/loop.md (modified, +140/-62)
  • syndicate/.pr-target (added, +1/-0)
  • syndicate/archive/.gitkeep (added, +0/-0)
  • syndicate/archive/branches.jsonl (added, +12/-0)
  • syndicate/attempts/.gitkeep (added, +0/-0)
  • syndicate/attempts/gen-1-a/diff-stats.txt (added, +5/-0)
  • syndicate/attempts/gen-1-a/rationale.md (added, +64/-0)
  • syndicate/attempts/gen-1-a/summary.md (added, +20/-0)
  • syndicate/attempts/gen-2-a/diff-stats.txt (added, +4/-0)
  • syndicate/attempts/gen-2-a/rationale.md (added, +56/-0)
  • syndicate/attempts/gen-2-a/summary.md (added, +11/-0)
  • syndicate/attempts/gen-2-b/diff-stats.txt (added, +17/-0)
  • syndicate/attempts/gen-2-b/rationale.md (added, +55/-0)
  • syndicate/attempts/gen-2-b/summary.md (added, +35/-0)
  • syndicate/attempts/gen-2-c/diff-stats.txt (added, +31/-0)
  • syndicate/attempts/gen-2-c/rationale.md (added, +56/-0)
  • syndicate/attempts/gen-3-a/diff-stats.txt (added, +5/-0)
  • syndicate/attempts/gen-3-a/rationale.md (added, +46/-0)
  • syndicate/attempts/gen-3-a/summary.md (added, +12/-0)
  • syndicate/attempts/gen-3-b/checklist.md (added, +40/-0)
  • syndicate/attempts/gen-3-b/diff-stats.txt (added, +8/-0)
  • syndicate/attempts/gen-3-b/rationale.md (added, +82/-0)
  • syndicate/attempts/gen-3-b/summary.md (added, +40/-0)
  • syndicate/attempts/gen-3-b/validation-log.md (added, +171/-0)
  • syndicate/attempts/gen-3-c/diff-stats.txt (added, +5/-0)
  • syndicate/attempts/gen-3-c/rationale.md (added, +60/-0)
  • syndicate/attempts/gen-3-c/summary.md (added, +25/-0)
  • syndicate/criteria.md (added, +21/-0)
  • syndicate/goal.md (added, +7/-0)
  • syndicate/learned-agents/.gitkeep (added, +0/-0)
  • syndicate/learned-agents/registry.jsonl (added, +0/-0)
  • syndicate/meta-notes.md (added, +91/-0)
  • syndicate/metrics/.gitkeep (added, +0/-0)
  • syndicate/metrics/coherence-log.jsonl (added, +6/-0)
  • syndicate/metrics/complexity.jsonl (added, +6/-0)
  • syndicate/metrics/scores.jsonl (added, +6/-0)
  • syndicate/prompts/task.md (added, +3/-0)
  • syndicate/reports/.gitkeep (added, +0/-0)
  • syndicate/reports/final.md (added, +41/-0)
  • syndicate/skills-manifest.jsonl (added, +1/-0)
  • syndicate/skills/approach.md (added, +6/-0)
  • syndicate/skills/domain/.gitkeep (added, +0/-0)
RAW_BUFFERClick to expand / collapse

Summary

When dispatching a subagent via the Agent tool with isolation: "worktree" from a non-default branch, the resulting worktree consistently forks from the default branch (main) instead of the caller's current branch HEAD. This silently gives subagents the wrong baseline.

Environment

  • Claude Code: 2.1.96 (observed in-session)
  • Platform: darwin 25.3.0
  • Repo: standard git repo with main as default, other local branches checked out

Reproduction

  1. git checkout -b feature-branch and make one or more commits on it
  2. Dispatch a subagent from the Agent tool with isolation: "worktree" and any subagent_type
  3. Inside the worktree, the subagent sees git log --oneline -5 showing main's HEAD, not feature-branch's HEAD
  4. Files modified on feature-branch are missing from the subagent's working tree

Observed frequency

In a single session running an iterative multi-agent loop, 8 of 9 dispatches forked from `main` instead of the current branch. One dispatch had no worktree created at all; the agent edited the parent checkout directly.

Expected

Worktree should fork from the caller's current branch HEAD, matching what `git worktree add` does with no explicit ref.

Impact

Subagents receive stale baselines, silently revert or skip work from prior commits, and produce diffs that cannot cleanly merge back. In iterative workflows where each step builds on the previous one, this breaks the pipeline unless every dispatch includes a manual baseline-sync workaround.

Workaround

Have the subagent run `git checkout <current-branch> -- <paths>` and commit a "baseline-sync" as its first action, then extract only its incremental work via `git diff baseline-sync HEAD` on merge.

extent analysis

TL;DR

The most likely fix is to modify the Agent tool to specify the current branch when creating a worktree with isolation: "worktree".

Guidance

  • Verify the current branch before dispatching a subagent and pass it as a parameter to the worktree creation process.
  • Check the git worktree add command used by the Agent tool to ensure it includes the correct branch reference.
  • Consider modifying the subagent's initial actions to include a git checkout command to ensure it is working on the correct branch.
  • Review the iterative multi-agent loop to identify potential issues with the baseline-sync workaround and explore alternative solutions.

Example

# Example of how to specify the current branch when creating a worktree
git worktree add -b <current-branch> <path>

Notes

The provided workaround of having the subagent run git checkout <current-branch> -- <paths> and commit a "baseline-sync" may not be suitable for all use cases and may introduce additional complexity.

Recommendation

Apply workaround: The current workaround of having the subagent run git checkout <current-branch> -- <paths> and commit a "baseline-sync" can help mitigate the issue, but a more robust solution would involve modifying the Agent tool to correctly specify the current branch when creating a worktree.

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