Description
When Worktree.create fails during its deferred bootstrap phase (the setTimeout(..., 0) at line 357 of packages/opencode/src/worktree/index.ts), no cleanup runs. The synchronous setup that already completed — directory creation, git worktree add, git branch, and Project.addSandbox() — is left behind permanently.
There are three failure points that all have this problem:
git reset --hard exits non-zero (line 359-372) — logs + emits event, returns without cleanup
Instance.provide() throws (line 375-394) — logs + emits event, returns without cleanup
- Unexpected exception in the outer
start() promise (line 411-413) — logs, no cleanup
Each failed attempt generates a unique random name (brave-cabin, calm-cactus, etc.), so retries never reuse the previous directory. Every failure leaves behind:
- A worktree directory at
~/.local/share/opencode/worktree/<project-id>/<name>/ containing a full repo clone
- A git worktree entry in
.git/worktrees/
- A git branch
opencode/<name>
- A sandbox record in the project database
There is no startup garbage collection, no periodic pruning, and no detection of orphaned worktrees. For a large repo, each orphan can be hundreds of MB. Users experiencing repeated bootstrap failures (network issues, disk pressure, permission errors) will see unbounded disk consumption until the volume fills up.
Plugins
None
OpenCode version
Latest // v1.2.10
Steps to reproduce
- Open a git repository in opencode
- Create a worktree (any method that triggers
Worktree.create)
- Have the bootstrap fail — this can happen due to network issues, disk pressure, permission errors, or a corrupt repo state causing
git reset --hard or Instance.provide() to fail
- Observe that the worktree directory remains at
~/.local/share/opencode/worktree/<project-id>/<random-name>/
- Run
git worktree list in the parent repo — the orphaned entry is still registered
- Run
git branch -a | grep opencode/ — the orphaned branch is still present
- Retry creating a worktree — a new random name is generated, the previous orphan is never cleaned up
- Repeat — each failure adds another full repo clone to disk with no upper bound
Screenshot and/or share link
N/A
Operating System
Linux (reproducible on all platforms)
Terminal
Any
Description
When
Worktree.createfails during its deferred bootstrap phase (thesetTimeout(..., 0)at line 357 ofpackages/opencode/src/worktree/index.ts), no cleanup runs. The synchronous setup that already completed — directory creation,git worktree add,git branch, andProject.addSandbox()— is left behind permanently.There are three failure points that all have this problem:
git reset --hardexits non-zero (line 359-372) — logs + emits event, returns without cleanupInstance.provide()throws (line 375-394) — logs + emits event, returns without cleanupstart()promise (line 411-413) — logs, no cleanupEach failed attempt generates a unique random name (
brave-cabin,calm-cactus, etc.), so retries never reuse the previous directory. Every failure leaves behind:~/.local/share/opencode/worktree/<project-id>/<name>/containing a full repo clone.git/worktrees/opencode/<name>There is no startup garbage collection, no periodic pruning, and no detection of orphaned worktrees. For a large repo, each orphan can be hundreds of MB. Users experiencing repeated bootstrap failures (network issues, disk pressure, permission errors) will see unbounded disk consumption until the volume fills up.
Plugins
None
OpenCode version
Latest //
v1.2.10Steps to reproduce
Worktree.create)git reset --hardorInstance.provide()to fail~/.local/share/opencode/worktree/<project-id>/<random-name>/git worktree listin the parent repo — the orphaned entry is still registeredgit branch -a | grep opencode/— the orphaned branch is still presentScreenshot and/or share link
N/A
Operating System
Linux (reproducible on all platforms)
Terminal
Any