kilo_cleanup
Safely removes stale git worktrees, merged feature branches, and orphan dev server processes from delegated Kilo runs using dry-run plans and uncommitted-work safeguards.
Instructions
Safely cleans up stale git worktrees, merged feature branches, and orphan background dev server processes created by delegated Kilo runs.
Features:
By default (delete_collection=True), removes each deleted worktree's Qdrant vector collection (ws-<sha256[:16]>) via the REST API (404 is tolerated; errors never block worktree removal).
Optionally (delete_sessions=True), deletes Kilo sessions run in the removed worktree via the Kilo CLI (
kilo session delete <id>).Prune mode (prune_orphans=True): audits Qdrant collections named
ws-*whose source path no longer exists and deletes only those positively identified as belonging to a removed worktree (.kilo/worktrees/ paths); unknown hashes are reported, never deleted.Dry-run first (returns candidates, kept items, leftover work, and a plan_hash).
Requires plan_hash to apply (preventing race conditions or accidental deletions).
NEVER deletes worktrees with uncommitted changes or unmerged commits (reported as 'leftover_work').
NEVER uses git branch -D or git clean -f: only safe git branch -d.
Writes an audit log to .kilo/cleanup-.json upon execution.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "kilo_cleanup"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keep | No | List of branch names, worktree directory names/paths, or task IDs to preserve unconditionally. | |
| scope | No | Resources to clean up: any of ['worktrees', 'branches', 'processes']. Defaults to all three. | |
| dry_run | No | If True (default), only reports candidates, kept items, and leftovers with a plan_hash. If False, executes the plan. | |
| plan_hash | No | Required when dry_run=False: must match the plan_hash returned by the preceding dry-run. | |
| base_branch | No | Base target branch to test merge status against (default: repo default branch or main/master). | |
| prune_orphans | No | If True, runs prune mode: audits and cleans orphan Qdrant collections whose worktrees were removed. | |
| delete_sessions | No | If True (default False), deletes Kilo sessions associated with removed worktrees via `kilo session delete`. | |
| delete_collection | No | If True (default), deletes the removed worktrees' Qdrant vector collections through the REST API. | |
| working_directory | No | Root directory of the git repository to clean up. Defaults to current working directory. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |