---
name: multi-agent-kill
description: "Stop the given task, then remove its worktree and branch. Asks for confirmation. Invoked only when the user types it."
user-invocable: true
argument-hint: "#id [--yes]  -  task ID to delete (e.g. #2); --yes answers the confirmation"
metadata:
  language: en
---

# multi-agent kill  -  Stop and Delete Task

**Access check, before anything else.** This command can write outside this machine, so a login the site closed is stopped here, before any question or write.

```bash
ACCESS_LINE=$(node "$HOME/.copilot/scripts/usage-access.mjs"); ACCESS_RC=$?
```

`ACCESS_RC` 3: print `$ACCESS_LINE` as written and stop: no question, no write, attended or unattended. Any other exit continues (the check fails open). Contract: `$HOME/.claude/multi-agent-refs/features/usage-reporting.md` "The access check".

**Input**: $ARGUMENTS

Stop the task's session, then remove its worktree and local branch. The remote branch and the run's logs are never deleted. Destructive operation  -  always asks for confirmation, unless `--yes` answered it.

**`--yes` (non-interactive).** For a caller that already asked - a client whose own confirm step ran, a script - `--yes` answers step 3 and nothing else. Step 2 still prints what is being deleted. The list of candidates with their disk use is `node "$HOME/.claude/scripts/worktrees.mjs" --json --measure`.

Both steps run `run-kill.mjs`, the same script `POST /v1/runs/{id}/kill` runs, so the command and a client remove the same things.

## Steps

1. **Find the task**  -  parse `#N` or `PROJ-XXXXX` from the argument; that is `<taskId>` below.

2. **Show what goes**:
   ```bash
   node "$HOME/.claude/scripts/run-kill.mjs" preview "<taskId>" --json
   ```
   Exit 4 means no such run: say so and stop. Print the worktree, the branch, its size, and, when non-zero, the uncommitted files and the commits on no remote (both are lost with the worktree), plus whether the session is still running.

3. **Get confirmation**: "Are you sure?" (skipped with `--yes`)
   - If not sure → cancel.

4. **Kill**:
   ```bash
   node "$HOME/.claude/scripts/run-kill.mjs" apply "<taskId>" --json
   ```
   It stops a live session, removes the worktree only when it is a linked worktree inside its repository, deletes the local branch unless it is the base branch, the main checkout's branch or main / master / develop, and marks the run `abandoned`. A field reading `false` is something it left in place; name it.

5. **Confirm**: `❌ Task #N (PROJ-{id}) killed`, and that the remote branch and the logs are kept.
