Hooks
Hooks let you run custom shell commands at specific points in the Code CLI lifecycle. They are configured in codecli.json under the hooks section.
Hook Types
| Type | Trigger | Use Case |
|---|---|---|
| pre_tool_use | Before a tool executes | Validate commands, block dangerous operations |
| post_tool_use | After a tool executes | Auto-format, run linters, notify on changes |
| session_start | When a session begins | Load environment, set up context |
| stop_hook | When a session ends | Cleanup, generate reports, commit changes |
Configuration
Pattern Matching
| Pattern | Matches |
|---|---|
| * | All tool calls |
| bash(*) | All bash commands |
| bash(git commit:*) | Git commit commands |
| write(src/**/*.ts) | Writes to TypeScript files in src/ |
| edit(*) | All edit operations |
Captured groups from patterns are available as $1, $2, etc.