Study guide
Hooks: rules the harness enforces so the agent cannot forget
The main points of the lesson, for review.
Key terms
- Advice: instructions the agent usually follows (CLAUDE.md, rules files, prompts)
- Enforcement: rules the harness checks every time (hooks, deny rules, managed settings)
- Hook: a command the harness runs at a fixed moment in a session
- Matcher: a filter that limits a hook to certain tools, such as Edit|Write
- Exit code: the number a command returns; 0 means carry on, 2 means block
Facts that move (checked November 24, 2026)
- Main Claude Code hook events: SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop (Anthropic hooks reference)
- Claude Code settings files: ~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json (Anthropic)
- Cursor hooks: .cursor/hooks.json or ~/.cursor/hooks.json; user-level hooks do not run in cloud agents (Cursor)
- A Stop hook that blocks eight times in a row no longer holds the turn (Anthropic best practices)
Rules worth moving into hooks first
- A notification when the agent is waiting
- No edits to protected folders or credential files
- No destructive commands
- A secrets scan before files are saved or sent
- No finishing while the check fails