Skip to main content
Glama

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

NameRequiredDescriptionDefault
keepNoList of branch names, worktree directory names/paths, or task IDs to preserve unconditionally.
scopeNoResources to clean up: any of ['worktrees', 'branches', 'processes']. Defaults to all three.
dry_runNoIf True (default), only reports candidates, kept items, and leftovers with a plan_hash. If False, executes the plan.
plan_hashNoRequired when dry_run=False: must match the plan_hash returned by the preceding dry-run.
base_branchNoBase target branch to test merge status against (default: repo default branch or main/master).
prune_orphansNoIf True, runs prune mode: audits and cleans orphan Qdrant collections whose worktrees were removed.
delete_sessionsNoIf True (default False), deletes Kilo sessions associated with removed worktrees via `kilo session delete`.
delete_collectionNoIf True (default), deletes the removed worktrees' Qdrant vector collections through the REST API.
working_directoryNoRoot directory of the git repository to clean up. Defaults to current working directory.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so thoroughly: 404-tolerance and non-blocking errors for collection deletion, positive-identification-only for orphan pruning, safety guards against uncommitted/unmerged work, avoidance of destructive git flags, and an audit log on execution.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A front-loaded summary sentence followed by scannable feature bullets, all of which add relevant behavior. It is dense but each bullet earns its place; minor verbosity in the parenthetical REST/CLI details keeps it from a 5.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Complete for a complex 9-parameter mutation tool: the safety model, workflow sequencing, defaults, and edge-case handling are all covered, and the presence of an output schema means return values need not be re-explained.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so parameters are already documented, but the description adds meaningful semantics beyond the schema — the plan_hash race-condition rationale, the 404-tolerated/never-block behavior of delete_collection, and how prune_orphans identifies collections to delete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and three concrete resources (git worktrees, merged feature branches, orphan dev processes) plus provenance ('created by delegated Kilo runs'). An agent immediately knows what the tool does and its scope, though sibling differentiation is implicit since no sibling performs cleanup.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear procedural context: dry-run first, plan_hash required to apply, and prune mode is opt-in. It does not name an explicit alternative tool to use instead, but there is no obvious substitute, so the workflow guidance is strong with only that exclusion gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.