/git-workflow:parallel-subagent-git-worktree-racefrom git-workflow
Fix/avoid HEAD+index corruption when running parallel Claude Code subagents (Agent tool) that each mutate git (checkout/rebase/reset) in what you THOUGHT were isolated worktrees. Use when: (1) you spawned 2+ agents with isolation:"worktree" to rebase/merge/commit different branches concurrently; (2) an agent reports "I am NOT in an isolated worktree" — `git rev-parse --git-dir` and `--git-common-dir` both point at the same `.git`, `git worktree list` shows a SINGLE worktree, and `--show-toplevel` is the main checkout; (3) a rebase suddenly appears to be running on the WRONG branch, or the reflog shows a branch reset/checkout you didn't issue during your run; (4) two agents' `git checkout` calls swap HEAD/index underneath each other. Covers detection, the serialize-to-one-owner recovery, and a ref-recheck guard pattern.
Ships in git-workflow. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The Claude Code Agent tool's isolation: "worktree" option is supposed to give
each spawned agent its own git worktree (separate working dir + HEAD + index,
shared object store). In practice it can silently fail to create a separate
worktree — the agents end up running in the same (main) checkout. When two
such agents each run git checkout <their-branch> and git rebase, they share
one HEAD and one index: agent B's checkout switches HEAD out from under agent A,
so A's subsequent git rebase origin/main rebases the WRONG branch, conflict
markers from one task land in the other, and pushes/aborts can clobber the
other agent's work. This corrupts both tasks even though each agent's own
commands look correct in isolation.
Cause of the fallback is not always visible to the agent (a likely trigger is
the sandbox denying git worktree add, per the using-git-worktrees skill's
"sandbox fallback: work in place"). Do not assume the option worked.
isolation: "worktree" to do git-mutating work
(rebase, merge, commit, reset, branch creation) on DIFFERENT branches at once.git rev-parse --git-dir == git rev-parse --git-common-dir (both .git)
AND git worktree list shows only ONE worktree AND git rev-parse --show-toplevel is the main repo path → it is NOT isolated.git rebase is in progress on a branch the agent never checked out.checkout:/reset:/rebase entry at a timestamp
the agent didn't act, i.e. another process moved the ref mid-run.git rebase --abort/--continue, no checkout/reset/commit/push — and to
report the exact commands it ran + current git status. A wrong recovery
move is worse than pausing. (TaskStop may not accept the agent's
name@session id; coordinate via SendMessage instead.)git rebase --abort if one is in
progress; git checkout -f <safe-branch>; git fetch origin --prune; then
reset each target branch to its remote with
git checkout -B <branch> origin/<branch> (this discards any unverified work
a runaway agent committed — usually what you want). Verify git status clean
and local refs == origin refs before proceeding.git rev-parse <branch> immediately BEFORE and AFTER each step (and before
any push). If the ref is anything other than what the owner's own command
set, HALT and report — another agent woke up. This is what catches a late
wakeup before it corrupts the redo.git rev-parse --git-dir vs --git-common-dir +
git worktree list check) and bail to the orchestrator if not isolated —
rather than trusting isolation: "worktree".git show origin/<branch>:<path> and
git diff origin/main...origin/<branch> and never checkout or touch the index.git worktree list shows distinct paths per agent IF you intended isolation.git diff --stat origin/main...HEAD
shows only its own intended change; tests/lint green; the ref-recheck guard
never tripped (or tripped and you halted before damage).Two agents asked to rebase feat/x and fix/y with isolation:"worktree".
Agent for feat/x reports: --git-dir and --git-common-dir both .git,
git worktree list shows one worktree; reflog shows fix/y was reset at a time
it didn't act → shared-tree race confirmed. Orchestrator: STOP both → release
the fix/y agent → make the feat/x agent sole owner → it aborts the stray
rebase, resets both branches to origin, rebases feat/x (push), then fix/y
(push), re-checking git rev-parse before each mutation. Both land cleanly;
the released agent's unverified commit is intentionally discarded.
show, diff, log, rev-parse, cat-file, fetch) is
concurrency-safe in a shared tree; only HEAD/index/worktree-mutating commands
race. Reviews and inspections can stay parallel.git show <ref>:<path> instead of reading files.--force-with-lease to push a rebased PR branch is safe when the lease is
against the untouched origin/<branch>; it does not protect against a peer
agent rewriting your LOCAL ref, which is why the ref-recheck guard exists.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub cajias/claude-skills --plugin git-workflowOther plugins' skills for the same job
6 skills in this plugin
/gh-pr-create-must-push-errorFix for "aborted: you must first push the current branch to a remote, or
use the --head flag" from `gh pr create` when the branch IS already
pushed. Use when: (1) `git push -u origin <branch>` succeeded moments
earlier, (2) `git branch -vv` shows upstream tracking is set, (3) `gh pr
create` still rejects with the must-push message. Workaround: pass
`--head <branch>` explicitly.
/gh-pr-merge-in-worktreesRecover from `gh pr merge --delete-branch` appearing to fail inside a git
worktree. Use when: (1) `gh pr merge 2 --delete-branch` prints
`failed to run git: fatal: '<branch>' is already used by worktree at
'<path>'`, (2) you suspect the PR merged anyway despite the error,
(3) you see a merged PR with its remote branch still present on origin,
(4) working in any multi-worktree setup where `main` is checked out in
a sibling worktree. Explains that `gh pr merge --delete-branch` runs
three separable steps (API merge, local delete, remote delete) and the
middle step failing leaves the merge state inconsistent with the
branch-cleanup state.
/git-deadlock-plumbing-recoveryDiagnose and recover git operations that HANG / DEADLOCK at ~0% CPU on macOS
(APFS) — git commit, git reset, git gc/repack, git push, and even git status
never returning. Use when: (1) a git write op "takes forever" / never finishes;
(2) `ps` shows the git process in interruptible sleep (STAT S/SN) with CPU TIME
frozen across samples; (3) a stale 0-byte `.git/index.lock` is present;
(4) `git push` stalls in "Counting objects" / `git repack -ad` hangs with an
empty pack dir; (5) `git count-objects -v` shows thousands of loose objects and
`packs: 0`; (6) the volume is near-full (`df` ~95%+); (7) `.git/index` went
missing after an interrupted git op. Covers the plumbing-commit workaround
(write-tree → commit-tree → update-ref) that bypasses the hanging working-tree
refresh and hooks, index recovery via read-tree, and the real fixes.