CHAPTER 12 · Observability, Hooks, and the Agent SDK · 5 / 5
Key takeaways
- A hook is deterministic code that fires on a lifecycle event (
PreToolUse,PostToolUse,Stop,PreCompact,SubagentStop), unlike a skill, which the model chooses. Hooks run in your process and cost no model context. PreToolUsehooks can veto a tool call, complementing Chapter 7's approval policy with custom rules.- Observability comes from the session log (JSONL of every message, tool use, and result), which enables rewind, resume, fork, and audit.
- The Agent SDK exposes
allowed_tools,max_turns,max_budget_usd,effort, andsetting_sources, and returns a resultsubtypelikeerror_max_turns. This makes budget-aware agents an engineering task, not a hope. - Hooks plus budgets are what make an agent safe to run unattended; observability is what lets you debug and audit it.
Original sources: the Claude Code six-layers architecture breakdown and Anthropic's How Claude Code works.