Unable to create `.git/index.lock`

I was hitting this error quite regularly when Claude Code attempted git operations (git add / git checkout / git commit / etc.):

Error: Exit code 128 fatal: Unable to create '/path/to/.git/index.lock': File exists. Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue.

Claude is very determined, so would attempt to work around it by removing the file, waiting, and then trying the process again. And then try other variants until it finally succeeded. This was super slow and annoying. Disk space, which is a common culprit, was not the problem. And I couldn’t find any other obvious causes, so I lived with it for a while.

Eventually, Claude hinted at a background process running git status that could be blocking things. I realized that my Claude statusline script was at fault (a git status call in my statusline refresh was setting a lock and blocking other git operations.)

If you run into the same issue, you can set this env var as part of your statusline script to avoid this: GIT_OPTIONAL_LOCKS = 0 (git docs)

Presentation: Code Review

This slideshow could not be started. Try refreshing the page or viewing it in another browser.

Presentation: WordPress in the Newsroom

This slideshow could not be started. Try refreshing the page or viewing it in another browser.

Presentation: The Database Schema

This slideshow could not be started. Try refreshing the page or viewing it in another browser.

Presentation: Deploys at WordPress.com VIP

This slideshow could not be started. Try refreshing the page or viewing it in another browser.

Presentation: Caching; for fun and profit

This slideshow could not be started. Try refreshing the page or viewing it in another browser.