[FEATURE] Task-level lifecycle hooks (PreTask / PostTask) for per-task analytics
Summary
Current hooks operate at session level (SessionStart) or tool level (PreToolUse/PostToolUse). There is nothing in between — no signal when a logical unit of work starts or ends within a session.
A single session often contains multiple tasks: "fix the bug", "add tests", "refactor the helper". Without task-level boundaries, plugins cannot compute per-task metrics.
Current hook granularity
Session level: SessionStart ─────────────────────── Stop
│
Task level: (nothing) ← THE GAP
│
Turn level: UserPromptSubmit ─── UserPromptSubmit
│ │
Tool level: Pre/PostToolUse Pre/PostToolUse
Proposed: PreTask / PostTask hooks
TaskStart
Fires when Claude begins working on a distinct task.
{
"event": "TaskStart",
"task_id": "...",
"session_id": "...",
"prompt_preview": "Fix the null pointer in parser.rs"
}
TaskEnd
Fires when a task reaches a natural conclusion.
{
"event": "TaskEnd",
"task_id": "...",
"outcome": "completed",
"turn_count": 8,
"tool_calls": 5,
"duration_seconds": 180
}
What defines a "task"?
Possible heuristics (any combination):
- User explicitly labels it: "Now fix the login bug"
- Significant topic shift in user prompt
- User invokes a workflow command (slash command = new task boundary)
- Plugin declares it via a hook response field
A pragmatic first step: let plugins signal task boundaries, and fire TaskEnd when the next TaskStart occurs or the session ends.
Why this matters
Per-task cost: "Fixing the bug cost $0.35 / 8 turns. Adding tests cost $0.12 / 3 turns."
Per-task FTR: Session-level FTR is meaningless with 5 tasks. Need: "3 of 5 tasks first-try."
Pattern detection: "Tasks starting with analysis complete 22% faster. Tasks that skip it have 3x corrections."
Related
- #47612 — Pre-exit hook (session-level, different scope)
- #11008 — Token usage in hooks (complementary — tokens + task boundaries = per-task cost)
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗