Skip to content
Claude Certified Developer – Foundations (CCDV-F) Exam Prep

Lesson 23 of 25 · 6 min

x
23/25

Claude Hooks

Video lesson: CCDV-F 23/25: Claude Hooks (Domain 7, 1.0%)

Official scope (Exam Guide v1.0): hooks for guardrails and safety controls to prevent destructive actions. Lowest-weight skill: learn the rules and traps.

What a hook is

User-defined automation that runs at a lifecycle point. Handler types: command, http, mcp_tool, prompt, agent. Deterministic for command and HTTP handlers, unlike an instruction the model may ignore.

When and where

  • Events: per session (SessionStart, SessionEnd), per turn (UserPromptSubmit, Stop), per tool call (PreToolUse, PostToolUse), plus subagent and compaction events.
  • Configured in user, project, local or managed settings, plugin hooks/hooks.json, and skill or subagent frontmatter. Project hooks follow workspace trust. Admins can set allowManagedHooksOnly.
  • Matchers filter by tool name (Bash, Write|Edit, ^mcp__); filter file paths inside the hook.

Exit codes

ExitEffect
0Success; JSON on stdout is applied
2Blocks the action (where the event can block); stderr is the reason. Blocks even if JSON says allow
Anything else (including 1)Non-blocking error; the action proceeds

Structured control: hookSpecificOutput.permissionDecision = allow / deny / ask / defer, plus a reason and optional updatedInput.

Hooks and permissions

A silent hook (exit 0, no output) approves nothing: the call continues through normal permission rules. A timed-out command or HTTP hook does not block unless onFailure: "block" is set. For a hard allow/deny the docs point to the permission system; use hooks for dynamic checks. Use both.

Hooks vs prompts (design guidance)

"Always format after edits" or "never rm -rf": a hook guarantees it runs; a prompt line does not.

Worked example

PreToolUse on Bash: read the command from stdin JSON; if it matches rm -rf, print the reason to stderr and exit 2; otherwise exit 0.

Exam traps

  • exit 1 to block. It does not.
  • A hook as the only control.
  • Assuming a timed-out hook blocks.
  • Matching file paths in matcher.

References

  1. Hooks reference — checked Oct 16, 2026
  2. Hooks in the SDK — checked Oct 16, 2026
  3. Permissions — checked Oct 16, 2026

Check your understanding

  • Hook exits 1 after detecting a forbidden command. Blocked?Show answer

    Answer

    No; use exit 2 or a deny decision.
  • Must always run after edits. Hook or prompt?Show answer

    Answer

    Hook.
  • A hook stays silent; is the call approved?Show answer

    Answer

    No, it goes through normal permission rules.
  • Is a hook enough on its own?Show answer

    Answer

    No; combine with permissions, sandboxing and least privilege.
Previous

Progress is saved in this browser.

Next Lesson