
Gh PR create orchestration cwd wrong head
Stops gh pr create from opening PRs against the wrong branch in multi-worktree setups
Gh PR create orchestration cwd wrong head is an open-source agent skill for developer tools. It is available on Claude Code.
- Scripts
- None
- Platforms
- Claude Code
- GitHub stars
- 5
- Last commit
- License
- MIT
- Listing updated
Similar skills
About Gh PR create orchestration cwd wrong head
This skill documents a specific trap in parallel workflows where an orchestrator dispatches subagents to separate git worktrees and then opens pull requests itself. When gh pr create runs from the orchestrator's directory, it picks up that directory's checked-out branch as the PR head, so the PR can carry the right title and body but point at an unrelated branch.
The guide walks the agent through diagnosing the problem by comparing the PR's head branch against the feature worktree's branch, and through recovery steps such as closing the mistaken PR and reopening the correct one. It also gives two prevention options: running gh from inside the feature worktree, or passing an explicit --head flag. A verification step checks the head reference and spot-checks the diff against the PR description.
The skill relies only on git and the GitHub CLI (gh) and does not run bundled scripts. It is written around a Claude Code orchestration setup with worktrees under a .claude directory, and it includes a worked incident example.
When your agent uses it
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.
From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.
What it can access
From a static check of its 1 file (6 KB) on GitHub on 4 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.
Check another skill before you install it.
Install
This skill ships in the agent-traffic-control plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):
/plugin marketplace add wan-huiyan/agent-traffic-control
/plugin install agent-traffic-control@wan-huiyan-agent-traffic-controlOr copy only this skill to ~/.claude/skills/gh-pr-create-orchestration-cwd-wrong-head:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/gh-pr-create-orchestration-cwd-wrong-head &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-head" ~/.claude/skills/gh-pr-create-orchestration-cwd-wrong-head &&
rm -rf "$tmp"For one project only, put the folder in .claude/skills/gh-pr-create-orchestration-cwd-wrong-head inside it instead.
Copy the skill folder to ~/.agents/skills/gh-pr-create-orchestration-cwd-wrong-head to use it in every repository:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/gh-pr-create-orchestration-cwd-wrong-head &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-head" ~/.agents/skills/gh-pr-create-orchestration-cwd-wrong-head &&
rm -rf "$tmp"For one repository only, put the folder in .agents/skills/gh-pr-create-orchestration-cwd-wrong-head inside it instead.
Copy the skill folder to ~/.cursor/skills/gh-pr-create-orchestration-cwd-wrong-head to use it in every project:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/gh-pr-create-orchestration-cwd-wrong-head &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-head" ~/.cursor/skills/gh-pr-create-orchestration-cwd-wrong-head &&
rm -rf "$tmp"For one project only, put the folder in .cursor/skills/gh-pr-create-orchestration-cwd-wrong-head inside it instead.
Run in a terminal (add --scope workspace to install it for the current workspace only):
gemini skills install https://github.com/wan-huiyan/agent-traffic-control.git --path plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-headOr copy the folder to ~/.gemini/skills/gh-pr-create-orchestration-cwd-wrong-head yourself.
For GitHub Copilot in VS Code, copy the skill folder to ~/.copilot/skills/gh-pr-create-orchestration-cwd-wrong-head:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/gh-pr-create-orchestration-cwd-wrong-head &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-head" ~/.copilot/skills/gh-pr-create-orchestration-cwd-wrong-head &&
rm -rf "$tmp"For one project only, put the folder in .github/skills/gh-pr-create-orchestration-cwd-wrong-head inside it instead.
Get the folder:
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.gitThen copy agent-traffic-control/plugins/agent-traffic-control/skills/gh-pr-create-orchestration-cwd-wrong-head into your agent's skills folder as gh-pr-create-orchestration-cwd-wrong-head. Agents that support SKILL.md read one folder per skill.
What it does
- Wrong head detection
- Explains how to spot a PR whose headRefName does not match the feature worktree's branch.
- Explicit head fix
- Shows how to pass --head so gh targets the intended feature branch regardless of current directory.
- Worktree directory approach
- Describes running gh from inside the feature worktree so its checked-out branch is used.
- Recovery steps
- Covers closing a mistaken PR with a comment and reopening the correct one.
- Post-create verification
- Lists commands to compare the PR head with the local branch and check the diff.
- Related orchestration patterns
- Points to neighbouring failure modes such as subagents running cd into the wrong worktree.
Good for
- Open a pull request for a change a subagent committed in a separate worktree
- Check whether an existing PR points at the correct head branch
- Close a pull request that was opened against the wrong branch and reopen it correctly
- Confirm a PR's diff matches its description before merging
Gh PR create orchestration cwd wrong head FAQ
What problem does Gh PR create orchestration cwd wrong head address?
When gh pr create is run from an orchestrator worktree, the PR can be opened against that worktree's branch instead of the feature branch a subagent committed to, even though the title and body look correct.
What tools does Gh PR create orchestration cwd wrong head need?
It uses git and the GitHub CLI (gh). It bundles no scripts and does not set an allowed-tools list.
How can the problem be prevented?
Either run gh pr create from inside the feature worktree, or pass --head with the feature branch name explicitly.
How do I check whether a PR has the wrong head?
Compare gh pr view with --json headRefName against the branch shown by git branch --show-current in the feature worktree; they should match.
How do I install Gh PR create orchestration cwd wrong head in Claude Code?
Copy the skill folder from GitHub to ~/.claude/skills/gh-pr-create-orchestration-cwd-wrong-head to use it in all your projects, or to .claude/skills/gh-pr-create-orchestration-cwd-wrong-head in one project. Or install the agent-traffic-control plugin, which includes it: /plugin marketplace add wan-huiyan/agent-traffic-control, then /plugin install agent-traffic-control@wan-huiyan-agent-traffic-control.
Does Gh PR create orchestration cwd wrong head run scripts?
No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.
Which AI agents can use Gh PR create orchestration cwd wrong head?
Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.
What are the best alternatives to Gh PR create orchestration cwd wrong head?
The closest alternatives to Gh PR create orchestration cwd wrong head are Gh PR merge worktree checkout trap, Git PR, Gh PR pickup designated branch supersede, Gha PR merge ref shows upstream changes and Gh PR merge unstable state needs auto and watch branch deletes.
Where this comes from
- Description: from the skill's own SKILL.md.
More from wan-huiyan/agent-traffic-control

Teaches agents to refuse a flawed instruction only with measured evidence attached
- Open source
- 5 GitHub stars
- Developer tools

Catches silent deletions when a subagent edits large files with repeated blocks
- Open source
- 5 GitHub stars
- Developer tools

Holds a pull request from merging by stopping its agent, disarming auto-merge, then
- Open source
- 5 GitHub stars
- Developer tools

Checks that a batch of pull requests does not cite file paths that will never exist
- Open source
- 5 GitHub stars
- Developer tools

Checks whether a pull request truly landed by comparing file content, not commit subjects
- Open source
- 5 GitHub stars
- Developer tools

Checks a branch for stale-base changes that would silently undo newer main work
- Open source
- 5 GitHub stars
- Developer tools


