D7: Hooks for Guardrails & Deterministic Actions
Claude Certified Developer – Foundations exam practice questions · 10 flashcards
Question
What are hooks in Claude Code / Agent SDK?
1 / 10
Tip: Space flips the card, ← / → navigate.
Show all 10 Hooks for Guardrails & Deterministic Actions practice questions and answers
- What are hooks in Claude Code / Agent SDK?User-defined commands or functions that run automatically at specific lifecycle events.
- Which hook runs before a tool executes?PreToolUse.
- Which hook runs after a tool executes?PostToolUse.
- Name other hook events.UserPromptSubmit, Stop, SubagentStop, SessionStart, SessionEnd, PreCompact and Notification.
- How can a PreToolUse hook block a destructive command?Inspect the tool input (e.g. rm -rf) and return a blocking decision (e.g. exit code 2) with a reason fed back to Claude.
- Why use hooks instead of prompt rules for safety?Hooks are deterministic and run every time; prompts can be ignored or overridden.
- What's a good PostToolUse hook example?Auto-running a formatter or linter after file edits.
- Where are Claude Code hooks configured?In settings.json (user, project or local scope).
- Why review hook scripts carefully?They run with your user's permissions automatically.
- How can hooks support auditing?Log every tool call and its inputs for monitoring and review.