Hooks Automation
Behavioral Classification
Type: Autonomous Execution
This skill provides hooks that execute automatically in response to Claude Code operations. No interactive decisions required.
Trigger Points:
- Pre-operation: Validates and prepares before edits, commands, tasks
- Post-operation: Formats, analyzes, and trains after operations
- Session: Manages state across sessions
- MCP: Coordinates with swarm agents
Overview
Intelligent automation system that coordinates, validates, and learns from Claude Code operations through hooks integrated with MCP tools and neural pattern training.
Key Capabilities:
- Pre-Operation Hooks: Validate, prepare, and auto-assign agents
- Post-Operation Hooks: Format, analyze, and train patterns
- Session Management: Persist state, restore context
- Memory Coordination: Synchronize knowledge across swarm agents
- Git Integration: Automated commit hooks with quality verification
- Neural Training: Continuous learning from successful patterns
Quick Start
Initialize Hooks System
# Initialize with default hooks configuration
npx claude-flow init --hooks
This creates:
.claude/settings.json with pre-configured hooks
- Hook command documentation in
.claude/commands/hooks/
- Default hook handlers for common operations
Basic Hook Usage
# Pre-task hook (auto-spawns agents)
npx claude-flow hook pre-task --description "Implement authentication"
# Post-edit hook (auto-formats and stores in memory)
npx claude-flow hook post-edit --file "src/auth.js" --memory-key "auth/login"
# Session end hook (saves state and metrics)
npx claude-flow hook session-end --session-id "dev-session" --export-metrics
Sub-Documentation
For detailed information, see the following files:
| Document |
Contents |
| Pre-Hooks |
pre-edit, pre-bash, pre-task, pre-search |
| Post-Hooks |
post-edit, post-bash, post-task, post-search |
| MCP Integration |
MCP hooks, memory coordination, agent workflows |
| Session Management |
session-start, session-restore, session-end |
| Configuration |
Settings, git hooks, custom hooks |
Available Hooks
Pre-Operation Hooks
| Hook |
Description |
pre-edit |
Validate and assign agents before file modifications |
pre-bash |
Check command safety and resource requirements |
pre-task |
Auto-spawn agents and prepare for complex tasks |
pre-search |
Prepare and optimize search operations |
Post-Operation Hooks
| Hook |
Description |
post-edit |
Auto-format, validate, and update memory |
post-bash |
Log execution and update metrics |
post-task |
Performance analysis and decision storage |
post-search |
Cache results and improve patterns |
Session Hooks
| Hook |
Description |
session-start |
Initialize new session |
session-restore |
Load previous session state |
session-end |
Cleanup and persist session state |
notify |
Custom notifications with swarm status |
MCP Integration Hooks
| Hook |
Description |
mcp-initialized |
Persist swarm configuration |
agent-spawned |
Update agent roster and memory |
task-orchestrated |
Monitor task progress |
neural-trained |
Save pattern improvements |
Quick Reference
Most Common Commands
# Pre-task preparation
npx claude-flow hook pre-task --description "Task description"
# Post-edit with memory storage
npx claude-flow hook post-edit --file "path/to/file" --memory-key "key"
# Session management
npx claude-flow hook session-start --session-id "my-session"
npx claude-flow hook session-end --session-id "my-session" --export-metrics
# Notifications
npx claude-flow hook notify --message "Task completed" --broadcast
Hook Response Format
{
"continue": true,
"reason": "All validations passed",
"metadata": {
"agent_assigned": "backend-dev",
"syntax_valid": true
}
}
Benefits
- Automatic Agent Assignment: Right agent for every file type
- Consistent Code Formatting: Language-specific formatters
- Continuous Learning: Neural patterns improve over time
- Cross-Session Memory: Context persists between sessions
- Performance Tracking: Comprehensive metrics and analytics
- Quality Gates: Pre-commit validation and verification
Performance Tips
- Keep Hooks Lightweight - Target < 100ms execution time
- Use Async for Heavy Operations - Don't block the main flow
- Cache Aggressively - Store frequently accessed data
- Batch Related Operations - Combine multiple actions
- Use Memory Wisely - Set appropriate TTLs
Related Skills
sparc-methodology - Hooks enhance SPARC workflows
pair-programming - Automated quality in pairing sessions
verification-quality - Truth-score validation in hooks
swarm-advanced - Multi-agent coordination via hooks
Version: 2.0.0
Last Updated: 2025-01-24
1---2name: hooks-automation3description: Automated coordination, formatting, and learning from Claude Code operations using intelligent hooks with MCP integration4---5
6# Hooks Automation
7
8## Behavioral Classification
9
10**Type**: Autonomous Execution
11
12This skill provides hooks that execute automatically in response to Claude Code operations. No interactive decisions required.
13
14**Trigger Points**:
15- Pre-operation: Validates and prepares before edits, commands, tasks
16- Post-operation: Formats, analyzes, and trains after operations
17- Session: Manages state across sessions
18- MCP: Coordinates with swarm agents
19
20---
21
22## Overview
23
24Intelligent automation system that coordinates, validates, and learns from Claude Code operations through hooks integrated with MCP tools and neural pattern training.
25
26**Key Capabilities:**
27- **Pre-Operation Hooks**: Validate, prepare, and auto-assign agents
28- **Post-Operation Hooks**: Format, analyze, and train patterns
29- **Session Management**: Persist state, restore context
30- **Memory Coordination**: Synchronize knowledge across swarm agents
31- **Git Integration**: Automated commit hooks with quality verification
32- **Neural Training**: Continuous learning from successful patterns
33
34---
35
36## Quick Start
37
38### Initialize Hooks System
39
40```bash
41# Initialize with default hooks configuration
42npx claude-flow init --hooks
43```
44
45This creates:
46- `.claude/settings.json` with pre-configured hooks
47- Hook command documentation in `.claude/commands/hooks/`
48- Default hook handlers for common operations
49
50### Basic Hook Usage
51
52```bash
53# Pre-task hook (auto-spawns agents)
54npx claude-flow hook pre-task --description "Implement authentication"
55
56# Post-edit hook (auto-formats and stores in memory)
57npx claude-flow hook post-edit --file "src/auth.js" --memory-key "auth/login"
58
59# Session end hook (saves state and metrics)
60npx claude-flow hook session-end --session-id "dev-session" --export-metrics
61```
62
63---
64
65## Sub-Documentation
66
67For detailed information, see the following files:
68
69| Document | Contents |
70|----------|----------|
71| [Pre-Hooks](./pre-hooks.md) | pre-edit, pre-bash, pre-task, pre-search |
72| [Post-Hooks](./post-hooks.md) | post-edit, post-bash, post-task, post-search |
73| [MCP Integration](./mcp-integration.md) | MCP hooks, memory coordination, agent workflows |
74| [Session Management](./session.md) | session-start, session-restore, session-end |
75| [Configuration](./configuration.md) | Settings, git hooks, custom hooks |
76
77---
78
79## Available Hooks
80
81### Pre-Operation Hooks
82| Hook | Description |
83|------|-------------|
84| `pre-edit` | Validate and assign agents before file modifications |
85| `pre-bash` | Check command safety and resource requirements |
86| `pre-task` | Auto-spawn agents and prepare for complex tasks |
87| `pre-search` | Prepare and optimize search operations |
88
89### Post-Operation Hooks
90| Hook | Description |
91|------|-------------|
92| `post-edit` | Auto-format, validate, and update memory |
93| `post-bash` | Log execution and update metrics |
94| `post-task` | Performance analysis and decision storage |
95| `post-search` | Cache results and improve patterns |
96
97### Session Hooks
98| Hook | Description |
99|------|-------------|
100| `session-start` | Initialize new session |
101| `session-restore` | Load previous session state |
102| `session-end` | Cleanup and persist session state |
103| `notify` | Custom notifications with swarm status |
104
105### MCP Integration Hooks
106| Hook | Description |
107|------|-------------|
108| `mcp-initialized` | Persist swarm configuration |
109| `agent-spawned` | Update agent roster and memory |
110| `task-orchestrated` | Monitor task progress |
111| `neural-trained` | Save pattern improvements |
112
113---
114
115## Quick Reference
116
117### Most Common Commands
118
119```bash
120# Pre-task preparation
121npx claude-flow hook pre-task --description "Task description"
122
123# Post-edit with memory storage
124npx claude-flow hook post-edit --file "path/to/file" --memory-key "key"
125
126# Session management
127npx claude-flow hook session-start --session-id "my-session"
128npx claude-flow hook session-end --session-id "my-session" --export-metrics
129
130# Notifications
131npx claude-flow hook notify --message "Task completed" --broadcast
132```
133
134### Hook Response Format
135
136```json
137{
138 "continue": true,
139 "reason": "All validations passed",
140 "metadata": {
141 "agent_assigned": "backend-dev",
142 "syntax_valid": true
143 }
144}
145```
146
147---
148
149## Benefits
150
151- **Automatic Agent Assignment**: Right agent for every file type
152- **Consistent Code Formatting**: Language-specific formatters
153- **Continuous Learning**: Neural patterns improve over time
154- **Cross-Session Memory**: Context persists between sessions
155- **Performance Tracking**: Comprehensive metrics and analytics
156- **Quality Gates**: Pre-commit validation and verification
157
158---
159
160## Performance Tips
161
1621. **Keep Hooks Lightweight** - Target < 100ms execution time
1632. **Use Async for Heavy Operations** - Don't block the main flow
1643. **Cache Aggressively** - Store frequently accessed data
1654. **Batch Related Operations** - Combine multiple actions
1665. **Use Memory Wisely** - Set appropriate TTLs
167
168---
169
170## Related Skills
171
172- `sparc-methodology` - Hooks enhance SPARC workflows
173- `pair-programming` - Automated quality in pairing sessions
174- `verification-quality` - Truth-score validation in hooks
175- `swarm-advanced` - Multi-agent coordination via hooks
176
177---
178
179**Version**: 2.0.0
180**Last Updated**: 2025-01-24