git-auto-maintenance-recurring-worktree-index-lock

git-auto-maintenance-recurring-worktree-index-lock is a skill for Claude Code from wan-huiyan/agent-traffic-control. It costs 323 tokens per session (1,812 once invoked), scanned A, original, MIT.

A guide to a recurring Git `index.lock` error caused by Git's automatic background maintenance, such as cleanup and repacking of repository data.

In plain words
What is it for?
Use it in busy repositories with multiple worktrees or frequent Git activity when checkout, staging, or commits repeatedly fail because an index lock exists.
Why use it?
It explains why deleting the lock fixes only one command when maintenance immediately creates the conflict again.

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 in busy repositories with multiple worktrees or frequent Git activity when checkout, staging, or commits repeatedly fail because an index lock exists.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock
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 git-auto-maintenance-recurring-worktree-index-lock
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 git-auto-maintenance-recurring-worktree-index-lock

README.md
[![agentmods](https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock/github.svg)](https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock)
Your own site
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock/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 git-auto-maintenance-recurring-worktree-index-lock

Your own site · 80×15
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/git-auto-maintenance-recurring-worktree-index-lock.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 323 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,812 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.00323 $0.01812
Opus 5 $0.00161 $0.00906
Sonnet 5 $0.00065 $0.00362
Haiku 4.5 $0.00032 $0.00181

Measured 10d ago against content hash 7aa6a03790df, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

git-auto-maintenance-recurring-worktree-index-lock 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 10d 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/git-auto-maintenance-recurring-worktree-index-lock/SKILL.md · 112 lines

How it starts

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

Recurring worktree index.lock from git auto-maintenance

Problem

In 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.

Context / Trigger Conditions

  • fatal: Unable to create '.../worktrees/<name>/index.lock': File exists / "Another git process seems to be running … remove the file manually to continue"
  • Removing the lock fixes it for exactly one command, then it recurs
  • pgrep -fl "git (gc|maintenance|repack|pack-objects)" shows live maintenance procs
  • Repo has many worktrees / frequent fetches / rebases (lots of loose objects)
  • It even blocks a plain git 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)

Solution

  1. 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
    
    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.
  2. 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>
    
  3. 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.

Read the full file on GitHub · 112 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. 10d ago First seen · 112 lines · 323 tokens per session scan A 7aa6a03790df

Subscribe to this mod's changes

git-auto-maintenance-recurring-worktree-index-lock is a skill published in the GitHub repository wan-huiyan/agent-traffic-control (3 stars, last pushed 5d ago), licensed MIT. It adds 323 tokens to every session and 1,812 once invoked, about $0.0016 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

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

claude-code-bash-patterns

Claude Code Bash tool patterns with hooks, automation, git workflows. Use for PreToolUse hooks, command chaining, CLI orchestration, custom commands, or encountering bash permissions, command failures, security guards, hook configurations.

secondsky/claude-skills · 52 tokens

bump-sdk-version

Bump the FutureSearch SDK version across all files. Use when releasing a new SDK version, updating version numbers, or the user says bump version, release, version bump.

futuresearch/futuresearch-python · 40 tokens

pr-check

PR review compliance: fetch review comments from an open PR, categorize as resolved/unresolved/dismissed, critically evaluate fixable items, implement approved fixes, and reply inline. Pass --unattended to halt on human-judgment items (emitted as Pending-Human) instead of prompting via AskUserQuestion.

rube-de/cc-skills · 67 tokens

babysit

PR babysitter: monitors CI status, auto-rebases when behind, auto-fixes CI where possible, delegates review comment handling to dlc:pr-check, and re-requests review after fixes. Designed for /loop usage with Remote Control.

rube-de/cc-skills · 53 tokens

git-ops

Git hygiene: clean up merged branches, prune stale remotes, and verify repository state.

rube-de/cc-skills · 22 tokens