Prevent an Idle Teammate From Dropping a Flagged Task

In an agent-team setup, a teammate going idle silently can leave a task stranded with no one actively working it. This checks a simple local task-state file and blocks the idle transition while anything owned by that teammate is still open.

Subagent & Multi-Agent Safety Event: TeammateIdle Claude Code Open source · Free

1. Save this as the hook script

#!/usr/bin/env python3
"""TeammateIdle hook — blocks going idle while an owned task is open.
Reads a project-maintained .claude/open_tasks.json of {task_id: owner}."""
import json, sys
from pathlib import Path

data = json.load(sys.stdin)
agent_id = data.get("agent_id", "")
tasks_path = Path(data.get("cwd", ".")) / ".claude" / "open_tasks.json"

if not tasks_path.exists():
    sys.exit(0)

tasks = json.loads(tasks_path.read_text())
owned_open = [tid for tid, owner in tasks.items() if owner == agent_id]

if owned_open:
    print(f"BLOCKED: teammate {agent_id} still owns open task(s) {owned_open} "
          f"— cannot go idle until they're reassigned or closed.", file=sys.stderr)
    sys.exit(2)

sys.exit(0)

Save to a path inside your project, e.g. .claude/hooks/prevent-idle-teammate-dropping-task.sh, then chmod +x it.

2. Wire it into .claude/settings.json

{
  "hooks": {
    "TeammateIdle": [
      {
        "hooks": [
          {"type": "command", "command": "python3 .claude/hooks/prevent-idle-teammate-dropping-task.py"}
        ]
      }
    ]
  }
}

Before you use this

A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.

Related hooks

← All hooks
FEEDBACK