---
name: shutdown
description: "End-of-day shutdown protocol. Cleans up all active sessions, kills sub-agents, logs the day, and reports costs. Trigger: 'shutdown', 'goodnight', 'end of day', 'close everything', 'go to sleep', 'wrap up'."
---

# Shutdown Protocol

When triggered, execute ALL steps in order. This is a cost-protection protocol.

## Step 1: Kill Sub-Agents
```
Run: subagents action=list
```
Kill any running sub-agents immediately. They cost money idling.

## Step 2: Clean Up Sessions
Run the CLI cleanup to prune stale sessions across all agents:
```bash
openclaw sessions cleanup --all-agents --enforce
```

## Step 3: Audit & Report
Run `sessions_list` with `activeMinutes=1440, messageLimit=0, limit=50` to see everything from the day.

Calculate and report:
- Number of active sessions per agent
- Which model each session is using
- Token counts
- Flag any sessions on Opus that shouldn't be

## Step 4: Log the Day
Write/update `memory/YYYY-MM-DD.md` with:
- Summary of work done
- Active project state
- Decisions made
- Cost concerns or anomalies
- Handover notes for next session

## Step 5: Update QMD
Update `memory/qmd/current.json` — move completed tasks out, keep only active items.

## Step 6: Confirm Shutdown
Post a clean summary to the user:
```
🌙 Shutdown Complete
━━━━━━━━━━━━━━━━━━
Sessions cleaned: X
Sub-agents killed: X  
Day logged: ✅
Active sessions remaining: X (list them)
━━━━━━━━━━━━━━━━━━
System in overnight mode. Goodnight.
```

## Rules
- Do NOT skip steps
- Do NOT start new work after shutdown
- If heartbeat fires after shutdown → HEARTBEAT_OK only
- Next interaction will start fresh sessions naturally
- This shutdown does NOT prevent someone from @mentioning the bot overnight — that requires groupPolicy config changes
