Demonstrates all SDK session lifecycle hooks firing during a typical prompt–tool–response cycle.
| Hook | When It Fires | Purpose |
|---|---|---|
onSessionStart |
Session is created | Initialize logging, metrics, or state |
onSessionEnd |
Session is destroyed | Clean up resources, flush logs |
onPreToolUse |
Before a tool executes | Approve/deny tool calls, audit usage |
onPostToolUse |
After a tool executes | Log results, collect metrics |
onUserPromptSubmitted |
User sends a prompt | Transform, validate, or log prompts |
onErrorOccurred |
An error is raised | Centralized error handling |
- Creates a session with all lifecycle hooks registered.
- Each hook appends its name to a log list when invoked.
- Sends a prompt that triggers tool use (glob file listing).
- Prints the model's response followed by the hook execution log showing which hooks fired and in what order.
# TypeScript
cd typescript && npm install && npm run build && node dist/index.js
# Python
cd python && pip install -r requirements.txt && python3 main.py
# Go
cd go && go run ../verify.sh