[BUG] Stale .git/index.lock left behind in worktrees during normal CLI operation (macOS)

Open 💬 5 comments Opened May 7, 2026 by pmatseykanets

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code CLI repeatedly leaves stale .git/index.lock files behind during normal operation. This happens in git worktrees, where the lock file ends up in the main repo's .git/worktrees/<name>/index.lock rather than the working directory's .git/.

The lock files are 0 bytes and appear to be left by background git operations (likely status polling for the status bar or conversation context). They block all subsequent git commands (git stash, git commit, git add, etc.) until manually removed.

This happens frequently enough during a single session that it becomes a recurring interruption.

What Should Happen?

Background git operations should use GIT_OPTIONAL_LOCKS=0 for read-only queries, or ensure lock files are cleaned up if the process is interrupted.

Error Messages/Logs

$ git stash
error: could not write index

The cause is a stale 0-byte lock file:

$ ls -la .git/worktrees/<name>/index.lock
-rw-r--r--  1 user  staff  0 May  7 16:12 .git/worktrees/<name>/index.lock

Steps to Reproduce

  1. Create a git worktree (git worktree add)
  2. Open Claude Code CLI in the worktree
  3. Work normally for a while (read files, edit, run commands)
  4. Attempt a git operation — intermittently fails with index.lock error
  5. Remove the lock file, continue working — it reappears later

Claude Code Version

2.1.119

Platform

Anthropic API

Operating System

macOS (Darwin 25.2.0)

Terminal/Shell

zsh

Related Issues

  • #37198 — same symptom from Claude Desktop App's git polling
  • #28546 — same symptom on Windows from Bash tool git commands

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗