Block Task Creation That Duplicates an Open Task
A simple de-duplication guard for a multi-agent setup where more than one agent can independently decide the same work needs doing — cheap to implement, and it keeps a shared task queue from filling up with near-identical entries that different reviewers end up resolving separately.
1. Save this as the hook script
#!/usr/bin/env python3
"""TaskCreated hook — blocks creating a task with a title matching an
already-open task. Reads/writes .claude/open_tasks.json."""
import json, sys
from pathlib import Path
data = json.load(sys.stdin)
task = data.get("task") or {}
title = task.get("title", "")
tasks_path = Path(data.get("cwd", ".")) / ".claude" / "open_task_titles.json"
existing = json.loads(tasks_path.read_text()) if tasks_path.exists() else []
if title in existing:
print(f"BLOCKED: a task titled '{title}' is already open.", file=sys.stderr)
sys.exit(2)
existing.append(title)
tasks_path.parent.mkdir(parents=True, exist_ok=True)
tasks_path.write_text(json.dumps(existing))
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/block-duplicate-task-creation.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"TaskCreated": [
{
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/block-duplicate-task-creation.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