This lesson covers three related Domain 1 topics: Agent SDK hooks for deterministic policy enforcement, task decomposition strategies (fixed vs adaptive), and session management techniques (resume, fork, fresh-start) for long-running work.
Agent SDK Hooks
Hooks intercept the agent loop at specific points. PostToolUse hooks run after a tool returns but before Claude sees the result, allowing you to normalize or rewrite the output. Tool call interception hooks run before a tool executes, allowing you to block the call or redirect.
Hooks provide deterministic guarantees. Prompts provide probabilistic compliance. The pattern: anything you absolutely need to happen, encode as a hook. Anything that's a soft preference, encode in the system prompt.
Common Hook Use Cases
- PostToolUse normalization. Three weather APIs return Unix timestamps, ISO 8601 strings, and numeric status codes. A
PostToolUsehook normalizes all three into a single canonical format before Claude sees them. - Policy enforcement. Block
process_refundcalls whereamount > $500and instead route toescalate_to_human. The model's prompt may say "escalate large refunds," but the hook guarantees it. - Audit logging. Capture every tool call's parameters and outcome for compliance review.
Task Decomposition: Fixed vs Adaptive
Two decomposition strategies exist, suited to different problem shapes:
| Strategy | When to use |
|---|---|
| Fixed sequential pipeline | Predictable multi-aspect work like code review (security pass → performance pass → style pass) |
| Dynamic adaptive decomposition | Open-ended investigation where subtasks are determined by what's discovered in earlier steps |
For a code review of a known repository, fixed pipelines win — you know what passes you need. For research investigating an unfamiliar codebase, adaptive wins — you can't enumerate the right subtasks until you've mapped the structure.
Session Management
Three techniques for handling continuity across long-running work:
| Technique | When to use |
|---|---|
--resume <session-name> | Prior context is mostly valid. Continue an existing conversation. |
| Fresh session + structured summary | Prior tool results are stale (files have changed significantly). Resuming with stale state causes the model to act on wrong assumptions. |
fork_session | Exploring divergent approaches from a shared analysis baseline. Each fork can experiment without polluting the others. |
Critical: When resuming after code modifications, you must inform the agent that files have changed. Resuming a session that has tool results referencing files the user has since edited gives the agent a stale model of reality. Starting fresh with a structured summary is more reliable than resuming.
Skills to Develop
- Choose hooks over prompt instructions when guaranteed compliance is required.
- Use
PostToolUseto normalize heterogeneous tool outputs before they enter the model's context. - Pick fixed pipelines for predictable multi-aspect work; adaptive decomposition for open-ended investigation.
- Choose between
--resume, fresh start with summary, andfork_sessionbased on whether prior tool results are still valid.