Skip to content
Module
Module 4 of 5Lesson 2 of 2~22 min

Hooks: rules that always apply

An instruction written in a memory file is still a request the agent can forget during a long task. This lesson teaches you to turn your critical rules into Claude Code hooks that run every time, to test them before trusting them and to weigh the risks they introduce into your workflow.

Lesson objective

By the end of this lesson, you will be able to write and test simple hooks that block a forbidden action, format or verify automatically, choose the right event, and assess a hook's risks before installing it.

Topics covered

  • Claude Code hooks
  • automation
  • AI agent guardrails
  • repository security
  • AI coding agent

Where it fits

Put guardrails in place that hold

What can the agent do without asking me, and how do I enforce what must never happen?

Lessons in this module

  1. Permissions: what the agent may do without asking you
  2. Hooks: rules that always apply (this lesson)

What you will learn in this module

This lesson is part of the course Work with Claude Code on a real project: context, planning, review

  • Choose a permission mode and write allow, ask and deny rules suited to the project's risks, in the right settings file.
  • Write simple hooks as deterministic guardrails (block, format, verify) and know their risks and limits.