remove_unowned_worktrees

Remove worktree directories no agent answers for, which delete_agents cannot reach: a directory under the worktrees directories whose agent row is gone, or whose row is in AGENT_STATE_FAILED_TO_CLEANUP because git can no longer read the registration.

WorktreewritesidempotentdestructiveMCP tool

Each directory goes and, where the repository can still be read, git worktree prune runs in it; no branch is ever touched, since without a row nothing says whether the branch was adopted. A directory outside the worktrees directories, one a live or archived agent still answers for, one an agent works in or under, or one holding another worktree is refused with the reason and the rest go; delete the agent instead for those. Read list_worktrees first and pass only the directories it reports with no agent.

Calling it#

curl -X POST http://127.0.0.1:8787/worktree.v1.WorktreeService/RemoveUnownedWorktrees \
  -H 'Content-Type: application/json' \
  -d '{
  "dirs": [
    "<dirs>"
  ]
}'

Request#

RemoveUnownedWorktreesRequest#

FieldTypeDescription
dirslist of string

The directories to remove, each as list_worktrees spelled it.

required

Response#

RemoveUnownedWorktreesResponse#

FieldTypeDescription
removedlist of string

The directories that went.

refusedlist of Refusal

The directories that did not, each with the reason.

Types#

Refusal#

FieldTypeDescription
dirstring

The directory that was left alone.

reasonstring

Why, in a sentence.