Skip to content
mentoor

Automating agent events with hooks

For engineers

Running format, test, context and block steps automatically when a coding agent starts, calls a tool or stops

See where you stand

110 questions across four stages: Understand, Apply, Solve and Judge.

Try 5 questions

Practice items, not counted towards your mastery. No account needed.

Check yourself · 1 of 5

Which event can stop a tool call before it runs?

Choose one answer

Check yourself · 2 of 5

Which input should an after-edit formatting hook use to find the file?

Choose one answer

Check yourself · 3 of 5

Why is a pre-tool hook stronger than a line in AGENTS.md saying "never edit .env"?

Choose one answer

Check yourself · 4 of 5

A session-start hook is best used for which kind of fact?

Choose one answer

Check yourself · 5 of 5

A hook meant to block an edit exits with code 1. What happens in Claude Code?

Choose one answer

Topics

  1. The agent lifecycle events hooks attach to5 min read · Session start, prompt submit, before and after tool use, stop and subagent stop, with matchers and the JSON a hook receives
  2. Running formatters and tests after agent edits5 min read · After-edit hooks that format files, run fast checks and feed failures back to the agent without slowing every step
  3. Blocking risky tool calls with pre-tool hooks6 min read · Deterministic deny decisions for protected files and dangerous commands, and why a hook is stronger than an instruction
  4. Injecting context at session start and prompt submit5 min read · Adding branch, ticket or environment facts automatically, and keeping injected text short
  5. Debugging hooks that fail, stall or loop6 min read · Debug logs, exit codes, timeouts, slow hooks and stop hooks that keep the agent running forever
  6. Reviewing hooks as code that runs with your permissions6 min read · Hooks run shell commands as you, so hooks from a cloned repo or plugin need the same review as any script

Start here

110 questions · last verified 2026-12