Skip to content
Skill

Git auto maintenance recurring worktree index lock

Stops recurring git index.lock errors caused by background auto-maintenance in worktrees

Git auto maintenance recurring worktree index lock 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 Git auto maintenance recurring worktree index lock

This skill helps an agent recover from a repeating worktree index.lock failure in git repositories that have many worktrees and heavy object churn. It explains that git's automatic maintenance can start gc, repack or pack-objects during routine commands and leave a stale index lock that reappears after it is deleted. The workflow has the agent check whether the lock is safe to remove by testing whether any process holds it open, whether it is empty, and how old it is, before clearing it once.

After clearing the lock, the skill has the agent run add, commit and checkout with auto-maintenance disabled through inline git config flags on each command, rather than changing shared repository config. It also warns that shell variables holding these flags fail in zsh, and advises staging by explicit path in shared worktrees. It covers a related case where a killed commit from a parallel session leaves a 0-byte lock that blocks every session.

The skill runs only standard git, lsof and pgrep commands in a shell. It expects a git repository with worktrees and access to inspect running processes.

When your agent uses it

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-

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 (7 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-control

Or copy only this skill to ~/.claude/skills/git-auto-maintenance-recurring-worktree-index-lock:

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/git-auto-maintenance-recurring-worktree-index-lock &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock" ~/.claude/skills/git-auto-maintenance-recurring-worktree-index-lock &&
rm -rf "$tmp"

For one project only, put the folder in .claude/skills/git-auto-maintenance-recurring-worktree-index-lock inside it instead.

Claude Code docs on skills

Copy the skill folder to ~/.agents/skills/git-auto-maintenance-recurring-worktree-index-lock 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/git-auto-maintenance-recurring-worktree-index-lock &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock" ~/.agents/skills/git-auto-maintenance-recurring-worktree-index-lock &&
rm -rf "$tmp"

For one repository only, put the folder in .agents/skills/git-auto-maintenance-recurring-worktree-index-lock inside it instead.

Codex docs on skills

Copy the skill folder to ~/.cursor/skills/git-auto-maintenance-recurring-worktree-index-lock 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/git-auto-maintenance-recurring-worktree-index-lock &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock" ~/.cursor/skills/git-auto-maintenance-recurring-worktree-index-lock &&
rm -rf "$tmp"

For one project only, put the folder in .cursor/skills/git-auto-maintenance-recurring-worktree-index-lock inside it instead.

Cursor docs on skills

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/git-auto-maintenance-recurring-worktree-index-lock

Or copy the folder to ~/.gemini/skills/git-auto-maintenance-recurring-worktree-index-lock yourself.

Gemini CLI docs on skills

For GitHub Copilot in VS Code, copy the skill folder to ~/.copilot/skills/git-auto-maintenance-recurring-worktree-index-lock:

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/git-auto-maintenance-recurring-worktree-index-lock &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock" ~/.copilot/skills/git-auto-maintenance-recurring-worktree-index-lock &&
rm -rf "$tmp"

For one project only, put the folder in .github/skills/git-auto-maintenance-recurring-worktree-index-lock inside it instead.

VS Code docs on skills

Get the folder:

git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git

Then copy agent-traffic-control/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock into your agent's skills folder as git-auto-maintenance-recurring-worktree-index-lock. Agents that support SKILL.md read one folder per skill.

The SKILL.md format

What it does

Lock staleness forensics
Checks whether an index.lock is held by a process, its size and its age before removal.
Auto-maintenance suppression
Passes gc.auto and maintenance.auto overrides inline on each git write command.
Recurring lock diagnosis
Distinguishes a lock that returns after deletion from a one-off orphaned lock.
Parallel session safety
Advises explicit path staging so concurrent sessions in one worktree do not mix changes.
Zsh flag pitfall
Explains why git flags stored in a shell variable fail in zsh and how to avoid it.

Good for

  • Fix a git checkout that fails with index.lock file exists in a multi-worktree repo
  • Find out whether a leftover git index.lock is safe to delete
  • Stop background git gc from re-creating the lock on every commit
  • Recover a shared worktree after a parallel session's commit was killed

Git auto maintenance recurring worktree index lock FAQ

When does Git auto maintenance recurring worktree index lock apply?

It applies when a git add, commit or checkout fails with an index.lock error that returns after the lock is deleted, especially when background git maintenance processes are running.

Does Git auto maintenance recurring worktree index lock remove the lock automatically?

No. The workflow tells the agent to run lsof, size and age checks first and to remove the lock only when no process holds it and it is a minutes-old empty file.

Does Git auto maintenance recurring worktree index lock change my repository config?

It recommends passing the maintenance flags inline per command rather than setting them in git config, because shared config affects other worktrees.

Is Git auto maintenance recurring worktree index lock for post-commit hook errors?

No. The skill says stale locks from a crashed async post-commit hook belong to a different skill, and it excludes branch-checked-out-elsewhere merge errors.

How do I install Git auto maintenance recurring worktree index lock in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/git-auto-maintenance-recurring-worktree-index-lock to use it in all your projects, or to .claude/skills/git-auto-maintenance-recurring-worktree-index-lock 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 Git auto maintenance recurring worktree index lock 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 Git auto maintenance recurring worktree index lock?

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 Git auto maintenance recurring worktree index lock?

The closest alternatives to Git auto maintenance recurring worktree index lock are Git clean worktrees, Git worktree, Concurrent session checkout clobbers shared worktree, Harness read write base repo path in worktree stale tree and Dispatched bash agent git checkout clobbers uncommitted edit.

Where this comes from

  • Description: from the skill's own SKILL.md.

More from wan-huiyan/agent-traffic-control