[PR #12399] fix(opencode): cleanup orphaned worktree directories #14205

Closed
opened 2026-02-16 18:19:01 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12399

State: closed
Merged: Yes


Fixes #11999

Summary

When deleting workspaces in OpenCode Desktop, git sometimes removes files but leaves empty directories and returns an error. This causes the sidebar to still show those worktrees, and retrying deletion fails with "Worktree Not Found".

This PR makes worktree deletion handle orphaned directories by manually cleaning them up when git no longer tracks them.

Changes

  • Modified Worktree.remove() in packages/opencode/src/worktree/index.ts
  • When worktree is not found in git's tracking but directory still exists, manually delete it with fs.rm()
  • Returns success instead of throwing "Worktree not found" error

How I verified it works

Tested manually with OpenCode Desktop:

  1. Created a worktree from the UI
  2. Ran git worktree remove --force manually to simulate the bug (worktree removed from git but directory remains)
  3. Entry stayed in OpenCode Desktop sidebar (orphaned)
  4. Deleted it from the UI - deletion now succeeds and cleans up the orphaned directory
  5. No more "Worktree Not Found" errors on retry
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12399 **State:** closed **Merged:** Yes --- Fixes #11999 ## Summary When deleting workspaces in OpenCode Desktop, git sometimes removes files but leaves empty directories and returns an error. This causes the sidebar to still show those worktrees, and retrying deletion fails with "Worktree Not Found". This PR makes worktree deletion handle orphaned directories by manually cleaning them up when git no longer tracks them. ## Changes - Modified `Worktree.remove()` in `packages/opencode/src/worktree/index.ts` - When worktree is not found in git's tracking but directory still exists, manually delete it with `fs.rm()` - Returns success instead of throwing "Worktree not found" error ## How I verified it works Tested manually with OpenCode Desktop: 1. Created a worktree from the UI 2. Ran `git worktree remove --force` manually to simulate the bug (worktree removed from git but directory remains) 3. Entry stayed in OpenCode Desktop sidebar (orphaned) 4. Deleted it from the UI - deletion now succeeds and cleans up the orphaned directory 5. No more "Worktree Not Found" errors on retry
yindo added the pull-request label 2026-02-16 18:19:01 -05:00
yindo closed this issue 2026-02-16 18:19:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14205