anomalyco / anomalyco/opencode
.git/index.lock stuck with "Resource busy" (EBUSY) — opencode holds `.git` dir open on encrypted APFS volume
Open
@rekram1-node is already working on this.
Since Aug 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
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, andpython os.unlink()on.git/index.lockall 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
.gitdirectory open as
directory file descriptors (e.g.49r,54r,55r→.gitand 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_EXCLand 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
.gitdirectory open as a directory watcher? If so, is it
expected that this prevents.git/index.lockfrom being unlinked on macOS? - Should opencode clean up stray
.git/index.lockfiles (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.lockfile 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
.gitdirectory open:
lsof -p <opencode-pid> | grep '\.git'→ DIR fds on.gitand repo cwd. - Any subsequent
git add/git commitinside 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.