/agent-traffic-control:git-auto-maintenance-recurring-worktree-index-lockfrom agent-traffic-control
Fix a RECURRING `fatal: Unable to create '.../worktrees/<name>/index.lock': File exists` that comes back after you `rm` it — in a busy/multi-worktree repo where your OWN git commands keep spawning `git maintenance run --auto` (→ `git gc --auto` / `git repack` / `git pack-objects`). Use when: (1) a `git checkout`/`add`/`commit` fails with "Another git process seems to be running … index.lock: File exists", (2) deleting the lock works ONCE then it returns on the next git command, (3) `pgrep -fl 'git (gc|maintenance|repack|pack-objects)'` shows background maintenance running, (4) the repo has many loose objects from heavy fetch/checkout/commit churn (many worktrees, frequent rebases), OR (5) a PARALLEL session's commit was killed mid-flight and left a stale 0-byte lock blocking all sessions in the shared worktree. Includes the cause-agnostic forensic test for whether a lock is SAFE to remove (lsof-unheld + 0-byte + old mtime). NOT for: stale lock from a crashed async POST-COMMIT hook (see `recover-from-an-async-post-commit-hook`), nor "branch checked out elsewhere" merge errors.
Trending skills
7-day visitors to each skill page
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
index.lock from git auto-maintenanceIn a repo with many worktrees and heavy object churn, git's automatic
maintenance (maintenance.auto / gc.auto, enabled by default) fires at the
start of routine commands once loose-object thresholds are hit. The spawned
git gc --auto / git repack / git pack-objects run concurrently with your
add/commit/checkout, and the contention leaves a stale
.git/worktrees/<name>/index.lock. You rm it, the command works, then the
NEXT git command spawns maintenance again and the lock returns — an infuriating
loop that looks like "another git process is running" when the other process is
git maintaining itself on your behalf.
fatal: Unable to create '.../worktrees/<name>/index.lock': File exists /
"Another git process seems to be running … remove the file manually to continue"pgrep -fl "git (gc|maintenance|repack|pack-objects)" shows live maintenance procsgit checkout -b before any commit (rules out a
post-commit hook as the cause — that's the key discriminator vs the
async-post-commit-hook skills)Confirm the lock is STALE, then clear it once. Don't blindly rm — a genuinely
in-progress commit would be corrupted. Three cause-agnostic forensics PROVE staleness
(any cause: auto-maintenance contention, OR a parallel session's killed/crashed commit):
LOCK=.git/worktrees/<name>/index.lock # or .git/index.lock in a plain clone
lsof "$LOCK" # NO output => no process holds it open
[ -s "$LOCK" ] && echo NONEMPTY || echo EMPTY # 0 bytes => process died before writing the index snapshot
ls -la --time-style=full-iso "$LOCK" # mtime minutes old => not an active commit
pgrep -fl "git (commit|add|write-tree|gc|maintenance|repack|pack-objects)" | grep -v pgrep
| grep -v pgrep is not enough on a machine several sessions share. It drops the
pgrep process; it does not drop the WRAPPER SHELL that carries the pattern, because the
Bash tool runs every command inside a /bin/zsh -c '<whole command text>'. So this line
can report git work in progress when the only thing it found was itself, or a peer session
that merely typed the same words — read each hit's argv and discard any beginning
/bin/zsh -c. waiter-pgrep-matches-its-own-command-line has the full trap and the
ownership checks (lsof -a -p <pid> -d cwd -Fn) that settle whose process it is.
lsof "$LOCK" is the load-bearing forensic here and cannot self-match; weight it over
the process search.
Unheld (lsof empty) + 0-byte + minutes-old = textbook stale → safe rm -f "$LOCK" (git's
own error literally says "remove the file manually to continue"). Re-check lsof/size
immediately before the rm, then stage-by-explicit-path + commit at once to minimise the
re-lock window. NOTE the background gc/pack-objects use their OWN locks (gc.pid, pack
lock), NOT index.lock — their mere presence is not a reason to wait.
Stop YOUR commands from spawning maintenance — pass the flags INLINE on every git write command for the rest of the session:
git -c gc.auto=0 -c maintenance.auto=false add <paths>
git -c gc.auto=0 -c maintenance.auto=false commit -F - <<'EOF'
...
EOF
git -c gc.auto=0 -c maintenance.auto=false checkout -b <branch> origin/main
git -c gc.auto=0 -c maintenance.auto=false push -u origin <branch>
The background gc/repack on the shared object store use their OWN locks
(gc.pid, objects pack lock) — separate from the worktree index.lock — so
they don't block reads; only your index writes contend. Disabling
auto-maintenance on your commands removes the collision.
The same add/commit/checkout that was failing now succeeds, and it stays
fixed across subsequent commands (no recurrence) — because none of them spawns a
new maintenance run.
GIT="git -c gc.auto=0 -c maintenance.auto=false"; $GIT add … FAILS in zsh with
command not found: git -c gc.auto=0 … — zsh tries to exec a binary literally
named "git -c …". Write the flags inline on each invocation (or use a shell
function / array), never a string variable.
recover-from-an-async-post-commit-hook explicitly defers to. That
skill is for fatal: unable to read <sha> / cache-tree corruption from a
crashed async post-commit hook; THIS skill is for a recurring lock file
from auto-maintenance. Same family (worktree + background git), different
cause + different fix.git config maintenance.auto false; git config gc.auto 0) but per-command
inline flags are safer (don't mutate shared config other worktrees read).gc/repack — let them finish; they're not the
blocker once your commands stop spawning new ones.git commit is killed
mid-operation leaves a 0-byte index.lock (it died before writing the index snapshot)
that NEVER clears on its own and blocks EVERY session. Same Unable to create index.lock
symptom, different root cause: it does NOT recur after rm (it's a one-shot orphan, not the
maintenance loop). The Step-1 forensic test (lsof-unheld + 0-byte + minutes-old mtime)
identifies BOTH causes as safe-to-remove; removing it unblocks the parallel sessions too.
Always stage by explicit path / never git add -A in a shared worktree, so a parallel
session's uncommitted work isn't swept into your commit (or yours into theirs).
(Confirmed 2026-06-23: a 9-min-old 0-byte lock from a parallel session's killed commit
blocked all commits; forensically confirmed stale + removed; all sessions resumed.)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.