# Quiz 1: Hook Fundamentals

Test your understanding of hooks, the events they cover, and how they differ across Claude Code, Codex, OpenCode, and Pi.

## Question 1: What is a hook?

<Question
  choices={[
    {
      text: "A hook is a model prompt that reminds the agent to run a command",
      explain: "That's a skill, not a hook. Hooks are runtime handlers — the runtime calls them regardless of what the model chose to do."
    },
    {
      text: "A hook is a user-defined handler that runs at a deterministic point in the agent's lifecycle, independent of the model's cooperation",
      explain: "Correct! Hooks fire on events like PreToolUse and Stop, and they run whether or not the model 'wanted' them to.",
      correct: true
    },
    {
      text: "A hook is a way to package skills, MCP servers, and agents into a distributable bundle",
      explain: "That's a plugin. Some plugin systems (like Claude Code's) can bundle hooks, but a hook is not the same as a plugin."
    },
    {
      text: "A hook is a kind of subagent that runs in parallel with the main agent",
      explain: "Subagents are isolated model instances. Hooks are runtime callbacks — much lighter weight and not model calls by default."
    }
  ]}
/>

## Question 2: How do hook surfaces differ across platforms?

<Question
  choices={[
    {
      text: "Claude Code uses PascalCase JSON events (PreToolUse, Stop); Codex uses a smaller PascalCase JSON set behind a feature flag; OpenCode uses TS/JS plugin modules; Pi uses TS/JS extensions with lower_snake_case events like tool_call",
      explain: "Correct! The four platforms share the same lifecycle but differ in syntax and surface.",
      correct: true
    },
    {
      text: "All four platforms use the exact same settings.json format for hook events",
      explain: "False. Only Claude Code uses settings.json. Codex uses hooks.json, OpenCode uses code-first plugins, and Pi uses extensions."
    },
    {
      text: "OpenCode exposes hooks through JSON configuration, like Claude Code",
      explain: "False. OpenCode has no JSON event config — plugins are TS/JS modules exporting hook handlers as object keys."
    },
    {
      text: "Only Claude Code supports HTTP hooks; Codex, OpenCode, and Pi cannot send events to an HTTP receiver",
      explain: "Close but not quite. Claude Code's 'http' handler type is unique, but Codex command hooks can call curl, and OpenCode and Pi extensions can call fetch() — all can deliver events to HTTP."
    }
  ]}
/>

## Question 3: Which lifecycle events matter most?

<Question
  choices={[
    {
      text: "PreToolUse fires after the tool returns, so you can log the result",
      explain: "False. PreToolUse fires *before* the tool call. PostToolUse is the 'after' event."
    },
    {
      text: "UserPromptSubmit fires when the user submits a prompt, before the model sees it — ideal for injecting extra context",
      explain: "Correct! This is the right event for prepending or modifying the prompt. Claude Code and Codex support UserPromptSubmit directly; Pi's nearest equivalent is before_agent_start.",
      correct: true
    },
    {
      text: "Stop fires only at session end, not per turn",
      explain: "False. Stop fires at the end of each turn; SessionEnd (Claude Code) is the session-level event."
    },
    {
      text: "PostToolUse in Codex fires for every possible tool path, just like in Claude Code",
      explain: "False. Codex PreToolUse and PostToolUse cover supported tool calls such as Bash, apply_patch, and MCP tools, but the surface is narrower than Claude Code's."
    }
  ]}
/>

## Question 4: How do hooks block or modify actions?

<Question
  choices={[
    {
      text: "A Claude Code command hook exits with code 2 and writes a reason to stderr to block the action",
      explain: "Correct! Exit 2 + stderr is the documented blocking signal; on PreToolUse it blocks the tool call, on UserPromptSubmit it erases the prompt.",
      correct: true
    },
    {
      text: "A Claude Code hook returns HTTP 500 to block the action",
      explain: "False. Non-2xx responses from HTTP hooks are treated as non-blocking errors, not as explicit block signals."
    },
    {
      text: "An OpenCode hook writes to stdin to block a tool call",
      explain: "False. OpenCode hooks block by throwing an Error. There is no stdin — they are TS/JS functions, not processes."
    },
    {
      text: "Hooks cannot block or modify tool calls; they are observe-only",
      explain: "False. All four platforms support influencing the agent: Claude Code and Codex via exit codes or JSON output, OpenCode via mutating `output` or throwing, and Pi via returned values or event mutation."
    }
  ]}
/>

## Question 5: When should you use hooks instead of skills?

<Question
  choices={[
    {
      text: "Hooks replace skills: once you have hooks, you don't need to write skills anymore",
      explain: "False. Skills teach the model *when* and *how* to do something; hooks fire around every step regardless of what the model chose. They complement each other."
    },
    {
      text: "Hooks are the right surface when you need deterministic behavior — like 'always run the linter after an Edit' — that shouldn't depend on the model remembering",
      explain: "Correct! That's exactly what hooks are for: turning conventions into code so the runtime enforces them.",
      correct: true
    },
    {
      text: "Hooks are mainly for user interface theming",
      explain: "False. A few events (like Claude Code's Notification) relate to UI, but hooks are mostly about observability, guardrails, and automation."
    },
    {
      text: "Hooks only make sense for single-agent workflows",
      explain: "False. SubagentStart / SubagentStop (Claude Code) and session.* events (OpenCode) make hooks useful in multi-agent workflows too."
    }
  ]}
/>

---

## Summary

If you got 4-5 correct, you understand the core hook model well enough to start wiring real guardrails and observability. If not, review the event lifecycle and the platform comparison before continuing.

## Key Takeaways

- Hooks are deterministic runtime handlers, not prompts or plugins
- Claude Code, Codex, OpenCode, and Pi expose similar lifecycle moments with different configuration surfaces
- Hooks are the right tool when behavior must happen every time rather than relying on the model to remember

## Next Steps

Next, wire hooks into a real dashboard so you can see agent activity live.

