Hooks
Hooks are automated scripts that execute at specific lifecycle events in SpecWeave. They enable automatic documentation sync, external tool updates, and workflow automation without manual intervention.
How Hooks Work
Available Hooks
| Hook | Event | Purpose |
|---|---|---|
| post-increment-planning | After /specweave:increment | Auto-create GitHub issue, translate files |
| post-task-completion | After task marked complete | Sync living docs, update external tools |
| post-increment-done | After /specweave:done | Close external issues, final sync |
| pre-implementation | Before /specweave:do | Validate environment |
Hook Location
plugins/specweave/hooks/
├── hooks.json # Hook registration
├── post-increment-planning.sh
├── post-task-completion.sh
├── post-increment-done.sh
├── pre-implementation.sh
└── lib/
├── sync-living-docs.ts
└── translate-file.ts
Configuration
Hooks are configured in .specweave/config.json:
{
"hooks": {
"post_task_completion": {
"sync_living_docs": true,
"external_tracker_sync": true
},
"post_increment_planning": {
"auto_create_github_issue": true
},
"post_increment_done": {
"close_github_issue": true
}
}
}
Hook Events
Post-Task-Completion
Fires after every task is marked complete (via TodoWrite):
- Wait for inactivity (15s debounce)
- Sync living docs (increment → specs folder)
- Update external tracker (GitHub/JIRA/ADO)
- Update status line cache
- Play completion sound
Post-Increment-Planning
Fires after /specweave:increment completes:
- Translate files (if multilingual)
- Check autoCreateIssue config
- Create GitHub issue (if enabled)
- Update metadata.json with issue URL
Post-Increment-Done
Fires after /specweave:done completes:
- Final living docs sync
- Close external issue (if linked)
- Add completion comment
- Archive increment
Real-World Example
Scenario: You complete task T-005 (implementing JWT authentication)
What happens:
$ claude
> Complete task T-005: Implement JWT service
[Claude marks task complete in tasks.md]
┌─ Hook: post-task-completion ────────────────────────┐
│ │
│ ⏳ Debouncing... (15s wait for more completions) │
│ │
│ 📚 Syncing living docs... │
│ → Copying spec.md to specs/backend/fs-042/ │
│ → Updating cross-links │
│ ✅ Living docs synced │
│ │
│ 🔗 Syncing to GitHub Issue #42... │
│ → Updating checkbox: [x] T-005 │
│ → Updating progress: 3/5 tasks (60%) │
│ ✅ GitHub synced │
│ │
│ 📊 Updating status cache... │
│ ✅ Cache updated │
│ │
│ 🔔 Playing completion sound... │
│ │
└─────────────────────────────────────────────────────┘
✅ Task T-005 complete!
Troubleshooting
Hooks Not Firing
-
Check hook registration:
cat plugins/specweave/hooks/hooks.json -
Check config enabled:
{
"hooks": {
"post_task_completion": {
"sync_living_docs": true // Must be true
}
}
} -
Check for lock files:
ls -la .specweave/state/.hook-*
# Remove stale locks: rm -f .specweave/state/.hook-* -
Check logs:
cat .specweave/logs/hooks.log
Disabling Hooks
For emergency situations:
export SPECWEAVE_DISABLE_HOOKS=1
Or clear hook state:
rm -f .specweave/state/.hook-*