PrepGenAICerts

The Full Hook Event Lifecycle

Advanced

Configure behavior and permissions via settings.json · Difficulty 2/5

0%
hookslifecycle-eventssession-startuser-prompt-submit

Explanation

More Than Just PreToolUse and PostToolUse

PreToolUse and PostToolUse are the two hook events that come up most because they're the ones that sit directly on the tool-call boundary -- one gates whether a call happens, the other gates what comes back. But the agent lifecycle has several more hook events, each bound to a different moment in a session, and each configured the same way: in settings.json, as a lifecycle event plus a command that runs when it fires.

EventFiresTypical use
PreToolUseBefore a tool call executesBlock or approve the call before it runs
PostToolUseAfter a tool call completesFormat, validate, log -- side effects on a call that already happened
UserPromptSubmitBefore the model processes a submitted promptInject context, or validate the incoming prompt before any work starts
StopWhen the model finishes respondingNotifications, cleanup, committing an audit-log entry
NotificationOn a permission request, or after 60 seconds of idle timeForward that event to a monitoring channel, chat integration, or audit log
SessionStartAt session init (start or resume)Validate environment variables, confirm dependent services are reachable
SessionEndAt session teardownFinal audit writes, teardown tasks, close-out notifications

Why the Full Set Matters

Each event covers a different kind of guarantee. PreToolUse/PostToolUse bracket a single tool call. UserPromptSubmit and Stop bracket a single turn. SessionStart and SessionEnd bracket the whole session. Notification is the odd one out -- it doesn't bracket anything; it fires on a specific signal (a permission request, or 60 seconds of idle time) regardless of where in the lifecycle that signal occurs. An exam item that describes "validate that a required service is reachable before the agent starts working" is describing SessionStart, not PreToolUse -- the check needs to happen once, at the very beginning of the session, not before every individual tool call.

All of these run as deterministic code, exactly like PreToolUse/PostToolUse -- they fire every time the event occurs, regardless of what the model decides. The full lifecycle is what makes it possible to enforce a hard rule (or automate a side effect) at literally any point in a session's life, not just around tool calls.

Common exam traps

  • Assuming hooks only exist at the tool-call boundary. UserPromptSubmit, Stop, Notification, SessionStart, and SessionEnd are all real, distinct hook events covering the rest of the session lifecycle.
  • Reaching for PreToolUse to validate environment variables or confirm a dependent service is reachable -- that's a session-level concern, which is exactly what SessionStart exists for.
  • Confusing Stop (fires when the model finishes responding, mid-session) with SessionEnd (fires at session teardown) -- they bracket different scopes.

Key Takeaways

  • The full hook lifecycle is PreToolUse, PostToolUse, UserPromptSubmit, Stop, Notification, SessionStart, and SessionEnd
  • UserPromptSubmit fires before the model processes a submitted prompt -- for injecting context or validating the request
  • Stop fires when the model finishes responding -- for notifications, cleanup, or committing an audit-log entry
  • Notification fires on a permission request or after 60 seconds of idle time
  • SessionStart fires at session init -- for validating env vars or confirming dependent services are reachable; SessionEnd fires at teardown for final audit writes
  • All hook events are deterministic code that fires every time the event occurs, regardless of the model's decision

Glossary Terms

Related Concepts

PrepGenAICerts is an independent exam-prep site. It is not affiliated with, endorsed by, or sponsored by Anthropic, PBC. Claude and Anthropic are trademarks of Anthropic, PBC. Exam details are taken from publicly available Anthropic and Pearson documentation. About PrepGenAICerts.