What Are Hooks?
Hooks are event-driven automation points that run at specific moments in your Claude Code workflow. Pro Workflow provides 18 hook events that enable quality gates, learning capture, drift detection, and workflow orchestration. Think of hooks as the nervous system of your AI workflow—they observe, react, and adapt based on what’s happening in your coding session.Hooks run automatically in the background. They don’t interrupt Claude’s work, but they surface helpful reminders and capture metadata for continuous improvement.
Why Hooks Matter
The self-correction loop depends on hooks to:Track Patterns
Monitor edit counts, correction rates, and quality metrics across sessions
Enforce Quality Gates
Remind to run lint, typecheck, and tests at optimal checkpoints
Capture Learnings
Auto-extract
[LEARN] blocks from responses into SQLite databaseDetect Drift
Alert when work diverges from the original task intent
The 18 Hook Events
Session Lifecycle
SessionStart
Loads learned patterns from database, displays recent session stats, checks for parallel worktreesWhen: New session begins
Script:
Use Case: Context restoration, learning replay
Script:
session-start.jsUse Case: Context restoration, learning replay
Tool Execution
| Hook | Trigger | Purpose | Script |
|---|---|---|---|
| PreToolUse | Before Edit/Write | Track edit count, quality gate reminders | quality-gate.js |
| PreToolUse | Before git commit | Remind to run quality gates (lint, typecheck) | Inline script |
| PreToolUse | Before git push | Suggest /wrap-up to capture learnings | Inline script |
| PostToolUse | After code edits | Check for console.log, TODOs, secrets | post-edit-check.js |
| PostToolUse | After tests | Suggest [LEARN] blocks from test failures | Inline script |
| PostToolUseFailure | Tool execution fails | Track failures, suggest debugging learnings | Inline script |
User Interaction
UserPromptSubmit
When: Each user prompt
Scripts:
Scripts:
prompt-submit.js- Tracks prompts and correction patternsdrift-detector.js- Detects task drift from original intent
Stop
When: Each response completes
Scripts:
Scripts:
session-check.js- Context-aware reminderslearn-capture.js- Auto-capture[LEARN]blocks to database
Agent Orchestration
SubagentStart
Logs when a subagent spawns for observabilityWhen: Agent teams launch background agents
Use Case: Track parallel agent execution in
Use Case: Track parallel agent execution in
/develop workflowsSubagentStop
Logs agent completion and captures resultsWhen: Subagent finishes work
Use Case: Collect outputs from planner, reviewer, scout agents
Use Case: Collect outputs from planner, reviewer, scout agents
Advanced Events
TaskCompleted
Trigger: Task marked complete
Action: Remind to run quality gates before marking done
Use Case: Ensure validation before closing tasks
Action: Remind to run quality gates before marking done
Use Case: Ensure validation before closing tasks
PermissionRequest
Trigger: Permission dialog appears
Action: Flag dangerous operations (rm -rf, deploy, force push)
Use Case: Security gate for destructive commands
Action: Flag dangerous operations (rm -rf, deploy, force push)
Use Case: Security gate for destructive commands
PreCompact
Trigger: Before context compaction
Script:
Use Case: Save context state before compression
Script:
pre-compact.jsUse Case: Save context state before compression
ConfigChange
Trigger: Settings modified mid-session
Script:
Use Case: Detect when quality gates or hooks are changed
Script:
config-watcher.jsUse Case: Detect when quality gates or hooks are changed
Notification
Trigger: System events
Action: Log permission requests
Use Case: Observability for system-level events
Action: Log permission requests
Use Case: Observability for system-level events
Hook Configuration
Hooks are defined inhooks/hooks.json with this structure:
Matcher Syntax
Adaptive Quality Gates
The PreToolUse hook for edits implements adaptive thresholds based on your correction history:High Correction Rate (>25%)
- First checkpoint: 3 edits
- Second checkpoint: 6 edits
- Repeat every: 6 edits
Medium Correction Rate (15-25%)
- First checkpoint: 5 edits
- Second checkpoint: 10 edits
- Repeat every: 10 edits
Low Correction Rate (5-15%)
- First checkpoint: 8 edits
- Second checkpoint: 15 edits
- Repeat every: 15 edits
Correction rates are calculated from the last 10 sessions in your SQLite database. The system learns when to remind you based on your actual mistake frequency.
Database Integration
All hook scripts integrate with the SQLite database at~/.pro-workflow/data.db:
Tracked Metrics
- Session stats: edit count, correction count, prompt count, duration
- Learnings: category, rule, mistake, correction, project context
- Correction rates: used for adaptive quality gates
- Session history: previous session stats for context restoration
Hook Output Format
Hooks output tostderr with the [ProWorkflow] prefix:
stdout).
Next Steps
Hook Lifecycle
Visual guide to hook execution flow and event sequencing
Custom Hooks
Write your own hooks with matchers, scripts, and database integration
Available But Not Configured
These hooks are supported but not included in the defaulthooks.json:
- Setup - One-time initialization
- WorktreeCreate - Set up worktree config
- WorktreeRemove - Cleanup on worktree deletion
hooks.json if you need custom worktree or setup automation.
Hooks are the foundation of the self-correction loop. The more sessions you complete, the smarter the system becomes at knowing when to remind you.