# Git auto maintenance recurring worktree index lock

> Git auto maintenance recurring worktree index lock is an open-source agent skill for developer tools. Stops recurring git index.lock errors caused by background auto-maintenance in worktrees. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock
- **Repository:** https://github.com/wan-huiyan/agent-traffic-control
- **GitHub stars:** 5
- **License:** MIT
- **Skill name:** git-auto-maintenance-recurring-worktree-index-lock
- **Collection:** https://github.com/wan-huiyan/agent-traffic-control
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

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-

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock)
- [License: MIT](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/git-auto-maintenance-recurring-worktree-index-lock)

## Features

- **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

## Install

### Claude Code

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):

```sh
/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`:

```sh
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.

### Codex

Copy the skill folder to `~/.agents/skills/git-auto-maintenance-recurring-worktree-index-lock` to use it in every repository:

```sh
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.

### Cursor

Copy the skill folder to `~/.cursor/skills/git-auto-maintenance-recurring-worktree-index-lock` to use it in every project:

```sh
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.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
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.

### VS Code

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

```sh
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.

### Other agents

Get the folder:

```sh
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.

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

## Alternatives

- [Git clean worktrees](https://ai-powered.com/skills/git-clean-worktrees): Git clean worktrees is an open-source agent skill for developer tools.
- [Git worktree](https://ai-powered.com/skills/git-worktree): Git worktree is an open-source agent skill for developer tools.
- [Concurrent session checkout clobbers shared worktree](https://ai-powered.com/skills/concurrent-session-checkout-clobbers-shared-worktree): Concurrent session checkout clobbers shared worktree is an open-source agent skill for developer tools.
- [Harness read write base repo path in worktree stale tree](https://ai-powered.com/skills/harness-read-write-base-repo-path-in-worktree-stale-tree): Harness read write base repo path in worktree stale tree is an open-source agent skill for developer tools.
- [Dispatched bash agent git checkout clobbers uncommitted edit](https://ai-powered.com/skills/dispatched-bash-agent-git-checkout-clobbers-uncommitted-edit): Dispatched bash agent git checkout clobbers uncommitted edit is an open-source agent skill for developer tools.
- [Isolate subagent verification from live worktree](https://ai-powered.com/skills/isolate-subagent-verification-from-live-worktree): Isolate subagent verification from live worktree is an open-source agent skill for developer tools.
- [Repo cleanup loop](https://ai-powered.com/skills/repo-cleanup-loop): Repo cleanup loop is an open-source agent skill for developer tools.
- [Injected claude md is the worktrees copy not mains](https://ai-powered.com/skills/injected-claude-md-is-the-worktrees-copy-not-mains): Injected claude md is the worktrees copy not mains is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/git-auto-maintenance-recurring-worktree-index-lock
