pr-hijack-via-stale-worktree-branch-ref

pr-hijack-via-stale-worktree-branch-ref is a skill for Claude Code from wan-huiyan/agent-traffic-control. It costs 305 tokens per session (2,721 once invoked), scanned A, original, MIT.

A recovery guide for a Git worktree mistake that replaces the branch behind someone else’s open pull request. A worktree is a separate checkout of the same repository.

In plain words
What is it for?
Use it to inspect reflogs, recover an orphaned commit, restore a remote branch, and repair a pull request whose title and changes no longer match.
Why use it?
It helps find the original commit and restore the correct pull request after Git silently accepted a push that pointed the remote branch at the wrong work.

Skill for Claude Code

Written for Claude Code: disable-model-invocation in frontmatter. Also seen: mentions Claude Code.

Part of the agent-traffic-control plugin — 105 skills shipped together

Good fit Use it to inspect reflogs, recover an orphaned commit, restore a remote branch, and repair a pull request whose title and changes no longer match.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add wan-huiyan/agent-traffic-control --skill pr-hijack-via-stale-worktree-branch-ref
Clone the repo
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control

Made for: Claude Code.

Or install agent-traffic-control, the plugin that ships this one along with the rest of its 105 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pr-hijack-via-stale-worktree-branch-ref

README.md
[![agentmods](https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref/github.svg)](https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref)
Your own site
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pr-hijack-via-stale-worktree-branch-ref

Your own site · 80×15
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/pr-hijack-via-stale-worktree-branch-ref.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 305 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,721 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00305 $0.02721
Opus 5 $0.00152 $0.01360
Sonnet 5 $0.00061 $0.00544
Haiku 4.5 $0.00030 $0.00272

Measured 12d ago against content hash 4c12739ca0e0, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

pr-hijack-via-stale-worktree-branch-ref scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/agent-traffic-control/skills/pr-hijack-via-stale-worktree-branch-ref/SKILL.md · 257 lines

How it starts

The opening of the file, as written. The whole thing — 257 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PR-Hijack via Stale Worktree Branch Ref

Problem

In a long-lived git worktree (especially .claude/worktrees/<name>/ patterns created by a parallel-session harness), a same-named local branch can be created via git checkout -b X origin/main even when branch X already exists upstream with an open PR. Pushing that local branch with git push -u origin X succeeds — git reports * [new branch] — and silently replaces the remote ref. The result:

  • The remote branch ref now points at YOUR commit
  • The open PR (call it #N) on that branch now lists YOUR commit
  • PR #N's title and body still describe the ORIGINAL author's work
  • The original author's commit is orphaned on the remote but still reachable in YOUR local reflog (because the worktree's reflog captured it earlier)
  • gh pr create fails with a pull request for branch "X" into "main" already exists and surfaces PR #N — which is now an artefact of two unrelated commits

The hijack is silent on both sides: git's push output doesn't warn, gh doesn't either, and the PR's web view shows a perfectly plausible (but wrong) state.

Context / Trigger Conditions

Surfaces when ALL of:

  1. You are working in a worktree (typically .claude/worktrees/<name>/) that has been used by a previous session
  2. The session-start git status banner shows a branch name that does NOT match git status -sb once you actually run it (stale banner)
  3. A prior session in the same worktree opened a PR on a generically-named feature branch (e.g., feat/drivers-headline-and-stripe-removal, feat/refactor-foo, fix/bar-bug)
  4. The worktree's local refs were reset between sessions (git reset --hard, branch deletion, or worktree-recreation) WITHOUT a corresponding git push --force to clean up the remote
  5. You create a local branch by the same generic name

Exact failure-signature triad:

# Symptom 1 — push reports new-branch despite upstream existing
$ git push -u origin feat/<name>
* [new branch]        feat/<name> -> feat/<name>

# Symptom 2 — gh pr create rejects with already-exists
$ gh pr create ...
a pull request for branch "feat/<name>" into branch "main" already exists:
https://github.com/<org>/<repo>/pull/N

# Symptom 3 — that PR's commits don't match its title/body
$ gh pr view N --json commits
{ "commits": [{ "oid": "<YOUR-SHA>", "messageHeadline": "<YOUR WORK>" }] }

Read the full file on GitHub · 257 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 257 lines · 305 tokens per session scan A 4c12739ca0e0

Subscribe to this mod's changes

pr-hijack-via-stale-worktree-branch-ref is a skill published in the GitHub repository wan-huiyan/agent-traffic-control (3 stars, last pushed today), licensed MIT. It adds 305 tokens to every session and 2,721 once invoked, about $0.0015 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

ql-housekeep

Detect repo-hygiene issues that accumulate during long-running autonomous development (merge-conflict markers, orphan worktrees, CPC-variant duplicates, stale branches, version-manifest drift). Detection-only by default — reports findings, never deletes or modifies without explicit user confirmation.

andyzengmath/quantum-loop · 57 tokens

nazgul:doctor

Run the Nazgul read-only preflight diagnostic — checks jq/gh presence and auth, git-hooks drift, cache-vs-repo plugin version, the bash-vs-zsh hazard, the NAZGULDIR footgun, config-schema staleness, either install mode's .gitignore Nazgul-block drift (stamp and flush-left region), cross-session messaging and Remote…

OrodruinLabs/nazgul · 151 tokens

hotfix

Emergency fix workflow that bypasses normal sprint processes with a full audit trail. Creates hotfix branch, tracks approvals, and ensures the fix is backported correctly.

IdoCohen560/claude-unity-game-studio · 35 tokens

cloudflare-workers-ci-cd

Complete CI/CD guide for Cloudflare Workers using GitHub Actions and GitLab CI. Use for automated testing, deployment pipelines, preview environments, secrets management, or encountering deployment failures, workflow errors, environment configuration issues.

secondsky/claude-skills · 50 tokens

cloudflare-workers-observability

Cloudflare Workers observability with logging, Analytics Engine, Tail Workers, metrics, and alerting. Use for monitoring, debugging, tracing, or encountering log parsing, metric aggregation, alert configuration errors.

secondsky/claude-skills · 47 tokens

cloudflare-workers-dev-experience

Cloudflare Workers local development with Wrangler, Miniflare, hot reload, debugging. Use for project setup, wrangler.jsonc configuration, or encountering local dev, HMR, binding simulation errors.

secondsky/claude-skills · 47 tokens