Description
What happened
While working in a repository on an encrypted APFS volume, opencode performed git
operations (status/diff/log, then later a commit attempt). A .git/index.lock file
appeared and became permanently stuck:
rm, mv, and python os.unlink() on .git/index.lock all fail with
Resource busy (errno 16 / EBUSY).
lsof .git/index.lock (and a search by inode) reports no holder.
- The lock file is 0 bytes.
Evidence / diagnosis
- The opencode process holds the repository root and the
.git directory open as
directory file descriptors (e.g. 49r, 54r, 55r → .git and repo cwd),
even when it is not actively running a git command.
- The 0-byte lock suggests a git process created it via
O_CREAT|O_EXCL and was
interrupted before writing its content.
- On this encrypted APFS volume, unlinking a file inside a directory that another
process keeps open (combined with fseventsd/mds activity) returns EBUSY, so the
lock cannot be cleared without terminating the holder.
Workaround
Bypassed the lock by pointing git at a temporary index file:
export GIT_INDEX_FILE=/tmp/idx-myproject
git read-tree HEAD
git add <file>
git write-tree
git commit-tree <tree> -p HEAD
git update-ref HEAD <commit>
This works, but every subsequent normal git invocation inside the repo still hits
the stuck lock.
Questions / requested behavior
- Does opencode keep the
.git directory open as a directory watcher? If so, is it
expected that this prevents .git/index.lock from being unlinked on macOS?
- Should opencode clean up stray
.git/index.lock files (or detect a dead lock)
before running git operations?
- Any known interaction with encrypted APFS volumes causing EBUSY on unlink?
Plugins
No response
OpenCode version
1.18.18 (installed via Homebrew, /opt/homebrew/bin/opencode)
Steps to reproduce
- On macOS, clone a repository onto an encrypted APFS volume (Cryptomator WebDav)
(/Volumes/CRYPT/...).
- Open the repo with opencode (
opencode, v1.18.18) and let it run its normal
startup git inspection (git status, git diff, git log).
- Attempt a commit from within the opencode session (e.g.
git add + git commit)
while opencode is still running.
- Interrupt / let the session move on — a
.git/index.lock file is left behind
(0 bytes).
- Observe:
ls -la .git/index.lock → file present, 0 bytes.
rm .git/index.lock → rm: .git/index.lock: Resource busy.
python3 -c "import os; os.unlink('.git/index.lock')" → OSError: [Errno 16] Resource busy.
lsof .git/index.lock → no output (no visible holder).
- Confirm opencode still holds the
.git directory open:
lsof -p <opencode-pid> | grep '\.git' → DIR fds on .git and repo cwd.
- Any subsequent
git add/git commit inside the repo now fails with
fatal: Unable to create '.../.git/index.lock': File exists..
av(
Screenshot and/or share link
No response
Operating System
macOS 15.7.9, Apple Silicon
Terminal
No response
Description
What happened
While working in a repository on an encrypted APFS volume, opencode performed git
operations (status/diff/log, then later a commit attempt). A
.git/index.lockfileappeared and became permanently stuck:
rm,mv, andpython os.unlink()on.git/index.lockall fail withResource busy(errno 16 / EBUSY).lsof .git/index.lock(and a search by inode) reports no holder.Evidence / diagnosis
.gitdirectory open asdirectory file descriptors (e.g.
49r,54r,55r→.gitand repo cwd),even when it is not actively running a git command.
O_CREAT|O_EXCLand wasinterrupted before writing its content.
process keeps open (combined with fseventsd/mds activity) returns EBUSY, so the
lock cannot be cleared without terminating the holder.
Workaround
Bypassed the lock by pointing git at a temporary index file:
This works, but every subsequent normal
gitinvocation inside the repo still hitsthe stuck lock.
Questions / requested behavior
.gitdirectory open as a directory watcher? If so, is itexpected that this prevents
.git/index.lockfrom being unlinked on macOS?.git/index.lockfiles (or detect a dead lock)before running git operations?
Plugins
No response
OpenCode version
1.18.18 (installed via Homebrew,
/opt/homebrew/bin/opencode)Steps to reproduce
(
/Volumes/CRYPT/...).opencode, v1.18.18) and let it run its normalstartup git inspection (
git status,git diff,git log).git add+git commit)while opencode is still running.
.git/index.lockfile is left behind(0 bytes).
ls -la .git/index.lock→ file present, 0 bytes.rm .git/index.lock→rm: .git/index.lock: Resource busy.python3 -c "import os; os.unlink('.git/index.lock')"→OSError: [Errno 16] Resource busy.lsof .git/index.lock→ no output (no visible holder)..gitdirectory open:lsof -p <opencode-pid> | grep '\.git'→ DIR fds on.gitand repo cwd.git add/git commitinside the repo now fails withfatal: Unable to create '.../.git/index.lock': File exists..av(
Screenshot and/or share link
No response
Operating System
macOS 15.7.9, Apple Silicon
Terminal
No response