Skip to main content

๐Ÿช Custom Hooks Development

Welcome to the Custom Hooks tutorial! In this course, you'll learn how to create your own ECC hooks to automate repetitive tasks โ€” making your development workflow run like a Swiss watch.

Prerequisites

We recommend familiarizing yourself with Hooks core concepts first.

๐ŸŽฎ Experience the Hook Systemโ€‹

ECC hooks trigger automatically at specific moments. Try these commands to explore different hook types:

ECC Command Simulator
โฏ
Available Commands:

๐Ÿ“š Create a Custom Hook from Scratchโ€‹

Let's create a practical custom hook step by step:

Create an auto-format Hook

Step 1 of 5
1

Understand Hook Structure

Every ECC hook consists of 4 core properties: name (identifier), trigger (trigger condition), filePattern (file matching), and command (execution command). Think of it like setting an alarm โ€” what time (trigger), which days (filePattern), what ringtone (command).

// Hook structure
{
  "name": "hook-name",        // Unique identifier
  "trigger": "edit_file",      // When to trigger
  "filePattern": "*.{ts,tsx}",  // Which files to watch
  "command": "npx prettier --write ${file}"  // What to execute
}
๐Ÿ’ก${file} is a built-in variable that automatically resolves to the edited file path

๐Ÿ’ป Write Your Own Hookโ€‹

Write a complete hook configuration in the code playground. Try adding your own rules:

Custom Hook Configurationjson
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

โ“ Knowledge Checkโ€‹

โ“

Which hook type is best suited for 'automatically running Prettier after each file save'?

โ“

If a preCommit hook detects console.log, what's the best practice?

โ“

What is the key difference between stop hooks and preCommit hooks?

๐ŸŽ‰ Congratulations!โ€‹

You've completed the Custom Hooks tutorial! You've mastered:

  • โœ… Three hook types: postToolUse, preCommit, stop
  • โœ… Core hook configuration structure
  • โœ… Auto-formatting and type-checking hooks
  • โœ… console.log detection and commit blocking
  • โœ… Session-end audit hooks

๐Ÿ“– Next Stepsโ€‹