Bug Report: Closing a "Task" Window Fails with git branch -D -- main Error
Summary
When attempting to close a task window for a task that has already been merged/committed to main, the application throws an unhandled error and the window does not close. The error originates from the tool invoking git branch -D -- main, which git refuses to execute because main is the active branch in a linked git worktree.
Error Message
Error: Error invoking remote method 'delete_task': Error: Command failed:
git branch -D -- main
error: cannot delete branch 'main' used by worktree at '/home/<user>/.git/<project>'
Steps to Reproduce
- Open the application and navigate to a task that has already been completed and merged into
main.
- Attempt to close the task's window (e.g., click the close/dismiss button).
- Observe the error dialog instead of the window closing cleanly.
Expected Behavior
The task window closes cleanly. If delete_task involves branch cleanup, it should either:
- Skip deleting
main (it should never delete a protected branch like main), or
- Detect that the branch is currently checked out in a worktree and handle the error gracefully.
Actual Behavior
The window fails to close. An error is surfaced:
Error: Error invoking remote method 'delete_task': Error: Command failed:
git branch -D -- main
error: cannot delete branch 'main' used by worktree at '/home/<user>/.git/<project>'
The UI is left in a broken state — the window stays open with no recovery path visible to the user.
Impact
- Severity: Medium — blocks basic UI flow for completed tasks
- Workaround: None apparent through the UI; requires manual
git worktree remove from the terminal
- Effect: Completed tasks cannot be dismissed; window remains open indefinitely, polluting the workspace
Root Cause Analysis (user-observed)
The repository has a linked git worktree at a path outside the project directory (under ~/.git/<project>), which has main checked out. This was likely created by the application itself in a prior session.
When delete_task runs git branch -D -- main, git rejects it because main is the active branch of that external worktree. The command should never attempt to delete main at all — it is the default/protected branch — and it should additionally check whether any worktree has the target branch checked out before attempting deletion.
System Configuration
| Field |
Value |
| OS |
macOS 26.4.1 (Build 25E253) |
| git version |
2.50.1 (Apple Git-155) |
| Repo location |
Google Drive (via macOS filesystem mount) |
| Sandbox |
Disabled |
Git Worktree State at Time of Error
<redacted-home>/.git/<project> 95f120d [main] ← stale/orphaned worktree
<project-root>/.worktrees/task/implement-task-048-... ccb3337 [task/implement-task-048-...]
<project-root>/.worktrees/task/the-heckle-history-... 5dcdfb7 [task/the-heckle-history-...]
Git Branches at Time of Error
* main
+ task/implement-task-048-settings-screen-3a2461
+ task/the-heckle-history-currently-adds-entries-to-the-top-of-the-list-instead-21c5ed
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/task/create-an-icon-and-whatever-other-c8a487
Suggested Fix
- Never pass
main (or any default/protected branch name) to git branch -D — the delete_task flow should only delete the task's feature branch, not main.
- Before calling
git branch -D <branch>, check git worktree list to confirm no worktree has that branch active; if one does, either skip deletion or remove the worktree first.
- Handle the error gracefully — if branch deletion fails for any reason, catch the error and still allow the UI window to close so the user is not stuck.
Bug Report: Closing a "Task" Window Fails with
git branch -D -- mainErrorSummary
When attempting to close a task window for a task that has already been merged/committed to
main, the application throws an unhandled error and the window does not close. The error originates from the tool invokinggit branch -D -- main, which git refuses to execute becausemainis the active branch in a linked git worktree.Error Message
Steps to Reproduce
main.Expected Behavior
The task window closes cleanly. If
delete_taskinvolves branch cleanup, it should either:main(it should never delete a protected branch likemain), orActual Behavior
The window fails to close. An error is surfaced:
The UI is left in a broken state — the window stays open with no recovery path visible to the user.
Impact
git worktree removefrom the terminalRoot Cause Analysis (user-observed)
The repository has a linked git worktree at a path outside the project directory (under
~/.git/<project>), which hasmainchecked out. This was likely created by the application itself in a prior session.When
delete_taskrunsgit branch -D -- main, git rejects it becausemainis the active branch of that external worktree. The command should never attempt to deletemainat all — it is the default/protected branch — and it should additionally check whether any worktree has the target branch checked out before attempting deletion.System Configuration
Git Worktree State at Time of Error
Git Branches at Time of Error
Suggested Fix
main(or any default/protected branch name) togit branch -D— thedelete_taskflow should only delete the task's feature branch, notmain.git branch -D <branch>, checkgit worktree listto confirm no worktree has that branch active; if one does, either skip deletion or remove the worktree first.