Skip to main content
Back to Exercises
Advanced advanced 40 min

Hook Suite

Build a comprehensive hook suite that enforces your project standards.

Objectives

  • Implement validation hooks for code standards
  • Create session lifecycle hooks
  • Handle exit codes appropriately (0, 1, 2)
  • Test hook behavior with simulated inputs

Beads Tasks

Create these tasks in Beads before starting. You learn Beads by using Beads.

bd create "Praxis: Build hook suite for [project]" --type=feature--labels=learn,advanced
bd create "Design hook architecture (which events, what actions)" --type=task--labels=learn
bd create "Implement validation hook (exit code 0/1/2)" --type=task--labels=learn
bd create "Implement session lifecycle hook" --type=task--labels=learn
bd create "Test hooks with simulated inputs" --type=task--labels=learn
bd create "Document hook behavior for team" --type=task--labels=learn

Claude Code Prompt

Copy this prompt into Claude Code to build YOUR own version:

## Setup: Track this exercise with Beads

```bash
bd create "Praxis: Build hook suite for [project]" --type=feature --labels=learn,advanced
bd create "Design hook architecture (which events, what actions)" --type=task --labels=learn
bd create "Implement validation hook (exit code 0/1/2)" --type=task --labels=learn
bd create "Implement session lifecycle hook" --type=task --labels=learn
bd create "Test hooks with simulated inputs" --type=task --labels=learn
bd create "Document hook behavior for team" --type=task --labels=learn
```

---

Help me build MY hook suite that enforces my project standards automatically.

I'm creating hooks that make Claude Code enforce MY rules. Guide me through:

1. **Identify standards to enforce**:
   What rules do I want automatically checked?
   - Code formatting?
   - Type safety?
   - Test coverage?
   - Commit message format?
   - File naming conventions?

2. **Design hook architecture**:
   | Event | Hook Purpose | Exit Behavior |
   |-------|--------------|---------------|
   | pre-commit | Lint & format | Block if fails |
   | post-edit | Type check | Warn only |
   | session-start | Load context | Always continue |

3. **Implement validation hooks**:
   Create scripts that use exit codes correctly:
   - **Exit 0**: Success, continue
   - **Exit 1**: Failure, block and show message
   - **Exit 2**: Failure, block and stop

   Example pre-commit hook:
   ```bash
   #!/bin/bash
   npm run lint || exit 1
   npm run typecheck || exit 1
   exit 0
   ```

4. **Implement lifecycle hooks**:
   - Session start: Load project context, run bd prime
   - Session end: Sync work, remind about uncommitted changes

5. **Configure in Claude Code**:
   ```json
   {
     "hooks": {
       "PreToolUse": [{ "matcher": "Edit|Write", "hooks": ["./hooks/pre-edit.sh"] }],
       "PostToolUse": [{ "matcher": "Edit|Write", "hooks": ["./hooks/post-edit.sh"] }]
     }
   }
   ```

6. **Test thoroughly**:
   - Simulate passing conditions
   - Simulate failing conditions
   - Verify exit codes work correctly

7. **Document MY hook suite**:
   - What does each hook do?
   - When do they run?
   - How do I bypass them if needed?

Project: [YOUR_PROJECT]
Standards to enforce: [YOUR_STANDARDS]

Your Solution

Write code that addresses the objectives above. Apply the principles from the Advanced path.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15