fix(host-service,cli): release a workspace's git branch on delete so its name is reusable
Fixes #6380
Problem
workspace.delete — the legacy surface used by the CLI, SDK, and MCP — hardcoded deleteBranch: false. Deleting a workspace therefore removed the worktree and the row but left the local git branch in the parent repo.
Because the branch survived, creating a new workspace with the same name silently picked a suffixed branch (<name>-2, then -3, ...) while the workspace name stayed the same, so the name and branch no longer agreed. In the desktop app the flow was worse: delete + recreate with the same name landed on a stale "Workspace not found" screen showing the old workspace ID.
Root cause
packages/host-service/src/trpc/router/workspace/workspace.ts — the delete mutation always passed deleteBranch: false:
return destroyWorkspace(ctx, {
workspaceId: input.id,
deleteBranch: false,
force: true,
teardownMode: "best-effort",
});
The v2 destroy path (used by the renderer) already lets the caller choose; the legacy delete surface never did, and the cleanup saga only deletes the branch when input.deleteBranch is set (Step 5, workspace-cleanup.ts:520).
Fix
workspace.deletenow accepts an optionaldeleteBranch(defaulttrue), so a deleted workspace releases its branch by default and the name is genuinely free to reuse. Callers that need to keep the branch (e.g. unmerged work they intend to salvage) passfalseexplicitly.superset ws deletekeeps its existing non-interactive contract (still defaults to deleting the branch) and adds a--keep-branchflag for the salvage case.
The v2 destroy path is untouched.
Verification
tsc --noEmitclean onhost-service,cli,sdk, andmcp(the SDK/MCP/CLI all consumeworkspace.deleteand compile against the new optional field).biome checkclean on both edited files.- The existing
destroy/deleteBranchbehavior in the v2 path and its integration tests are unchanged.
Summary by cubic
Fixes #6380 by aligning workspace deletion with the desktop UI: deleting a workspace now keeps its git branch by default, and an opt-in flag releases the name for reuse.
workspace.deleteaccepts optionaldeleteBranch, defaulting tofalseso silent callers don't lose unpushed commits.superset ws deleteadds--delete-branchto opt into branch removal; the flag is rejected with--cloudbecause cloud sandboxes have no workspace git branch to release.
Summary by CodeRabbit
-
New Features
- Added the
--delete-branchoption to workspace deletion. - Workspace branches are kept by default when deleting a workspace.
- Branches are deleted only when
--delete-branchis explicitly specified.
- Added the
-
Bug Fixes
- Workspace cleanup now consistently follows the selected branch deletion behavior.
- Deleted workspaces that retain their branches no longer block creating a new workspace with the same branch.