---
title: Task Tracking Enforcer Hook component_type: hook version: 1.0.0 audience: contributor status: active summary: Enforces task ID tracking in TodoWrite and captures task→message linking keywords:
- enforcement
- task-tracking
- todowrite
- compliance tokens: ~2500 created: 2026-01-04 updated: 2026-01-04
Task Tracking Enforcer - Ensures Framework Compliance
This hook enforces that agents and skills use proper task tracking:
- VALIDATION: Checks TodoWrite calls for task ID format [X.X.X]
- CAPTURE: Records task state changes to database
- LINKING: Associates messages with active tasks
- WARNING: Alerts when tasks are missing IDs
Enforcement Levels:
- warn: Log warning but allow (default)
- soft: Log + add reminder to output
- strict: Block operation if no task ID
Hook Events:
- PreToolUse: Validate TodoWrite before execution
- PostToolUse: Capture task state after execution
- Notification: Alert on compliance issues
Usage in .claude/settings.json: { "hooks": { "PreToolUse": [ { "matcher": "TodoWrite", "hooks": ["python3 hooks/task-tracking-enforcer.py --event pre --level soft"] } ], "PostToolUse": [ { "matcher": "TodoWrite", "hooks": ["python3 hooks/task-tracking-enforcer.py --event post"] } ] } }
File: task-tracking-enforcer.py
Classes
TaskTrackingEnforcer
Enforces task ID tracking and captures task state.
Functions
main()
Main entry point for hook.
get_db_connection()
Get database connection.
ensure_schema()
Ensure task_tracking table exists.
extract_task_ids(todos)
Extract task IDs from todo items.
validate_todos(todos)
Validate that todos have proper task IDs.
record_task_state(todos)
Record task state changes to database.
handle_pre_tool_use(tool_input)
Handle PreToolUse event for TodoWrite.
handle_post_tool_use(tool_input, tool_result)
Handle PostToolUse event - capture task state.
Usage
python task-tracking-enforcer.py