Deleting a thread and its worktree on Windows fails with "failed to delete" because the provider's processes still run in the worktree#27018

opened12d agobyCchristopher-buss

What happened

On Windows, I delete a thread and choose to delete its worktree too. T3 shows:

1Could not remove t3-xxxxxxxx. Git command failed in GitVcsDriver.removeWorktree (<project root>): fatal: failed to delete '<t3 worktrees>\<project>\t3-xxxxxxxx'

The thread is deleted, but the worktree stays on disk, with part of its files deleted. If I retry a few minutes later, the remove works.

Diagnosis

useThreadActions.ts waits for stopThreadSession, then calls vcs.removeWorktree at once. The stop only signals the provider. The Claude adapter's closeClaudeQuery calls queryRuntime.close() and does not wait for the process tree to exit. On Windows, a folder that is a process's working directory, or that has open files, cannot be deleted. So removeLinkedWorktree (fileSystem.remove(worktreePath, { recursive: true })) fails partway and puts .git back.

The processes that kept the folder open:

  • Claude thread: claude.exe, and a project stdio MCP server that pnpm started (node running tsx, a child node, and esbuild.exe).
  • Codex thread: codex.exe app-server, started by T3 with its working directory in the worktree, with child processes node_repl.exe, node.exe (cua-repl) and an MCP node.exe.

handle.exe showed these processes holding the worktree folder at the time of the failure. A few minutes later, it showed no handles and the remove worked. Automatic cleanup after settle runs much later, so it probably does not hit this.

Steps to reproduce

  1. On Windows, open a project whose agent config starts a stdio MCP server, or use a Codex thread.
  2. Start a new thread in a new worktree. Send one message and let the turn complete.
  3. Delete the thread and confirm "Delete the worktree too?".
  4. T3 shows "failed to delete". The folder stays, with part of its files deleted.

Version

0.1.5-nightly.20261029.3877 (desktop, local server)

Environment

Windows 11 x64 (10.0.26100), Node v24.22.1, Git 2.56.0.windows.3, Claude Code 2.1.312, codex-cli 0.165.0

Evidence

115:46:42.860 provider (claudeAgent): session stop for the thread
215:46:42.957 vcs.removeWorktree start
315:46:42.998 GitWorkflowService.removeWorktree Failure: GitCommandError: fatal: failed to delete '<t3 worktrees>\<project>\t3-18261db2'
  • #21354: Codex MCP servers live until the app-server exits. Related, but that issue is about process leaks, not removal order.
  • #3089 (closed): MCP processes not killed on conversation close.
  • #5614, #20355, #14990 (closed): other worktree-remove failures on Windows. None of them is about running processes.

Fix applied or workaround

Retry the delete after the provider processes exit, or stop them first (for example, taskkill /PID <pid> /T /F), then run git worktree remove --force.

Possible fix: before the remove, wait for the thread's provider process tree to exit, and kill the tree on Windows. Or retry the remove with a backoff.

Filed by

Claude Code (Claude Opus 5.5), from t3 triage.

Synced from GitHub

This was generated by AI during triage.

Filed via t3 triage. The via-triage label could not be applied because the filing account has no triage access. Could a maintainer add it?