← ClaudeAtlas

gh-pr-create-orchestration-cwd-wrong-headlisted

Diagnose and prevent `gh pr create` opening a PR against the WRONG head branch when invoked from a parallel-orchestration setup with multiple worktrees. Use when: (1) you've dispatched subagents to work in sub-worktrees but you're finalizing PRs from a separate orchestration worktree, (2) `gh pr create` succeeds but `gh pr view --json headRefName` shows your orchestration worktree's branch (e.g. `docs/sNNN-handoff`) instead of the feature branch the subagent committed to (e.g. `fix/issue-X`), (3) two PRs exist for the same logical change because a revived subagent opened a second one on the correct branch. Trigger: PR title is correct (heredoc body matches your intent) but the PR's `headRefName` doesn't match the feature worktree's branch — your CWD when invoking `gh` overrode the head selection.
wan-huiyan/agent-traffic-control · ★ 2 · AI & Automation · score 79
Install: claude install-skill wan-huiyan/agent-traffic-control
# `gh pr create` from orchestration worktree picks wrong head branch ## Problem In a parallel-execution setup, an orchestrator dispatches sub-agents to feature worktrees (`<repo>/.claude/worktrees/feature-A/`, `feature-B/`, etc.) and waits on their completion. When the orchestrator then runs `gh pr create` to open the PR for one of those features, **it gets opened against whatever branch is currently checked out in the orchestrator's CWD** — not the feature branch the subagent committed to. Result: a PR with the right title and body but the wrong head branch (typically the orchestrator's `docs/sNNN-handoff` or `main`-tracking branch). The PR's diff is unrelated to the change description, and the actual feature work never gets a PR. ## Trigger conditions You're hitting this skill if **all** of: 1. Your workflow has multiple worktrees: one orchestrator + N feature worktrees. 2. You ran `gh pr create` (with title + body via heredoc) from the orchestrator's working directory. 3. `gh pr view <N> --json headRefName` returns your orchestrator's branch (e.g. `docs/sNNN-handoff`), NOT the feature branch (e.g. `fix/issue-XXX`). 4. The PR's diff in `gh pr diff <N>` doesn't match the body text. Optional secondary signal: - A revived subagent later opens a SECOND PR on the correct branch (because it ran `gh pr create` from the feature worktree where its CWD was). Now you have two PRs. ## Root cause `gh pr create` defaults `--head` to the **current branch in the C