2025-12-24 17:11:18 +09:00
|
|
|
# HOOKS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
|
|
|
|
|
2026-01-09 15:44:06 +09:00
|
|
|
22+ lifecycle hooks intercepting/modifying agent behavior. Context injection, error recovery, output control, notifications.
|
2025-12-24 17:11:18 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
hooks/
|
2026-01-09 15:44:06 +09:00
|
|
|
├── anthropic-context-window-limit-recovery/ # Auto-compact at token limit (556 lines)
|
2026-01-02 10:42:38 +09:00
|
|
|
├── auto-slash-command/ # Detect and execute /command patterns
|
|
|
|
|
├── auto-update-checker/ # Version notifications, startup toast
|
|
|
|
|
├── background-notification/ # OS notify on task complete
|
2026-01-09 15:44:06 +09:00
|
|
|
├── claude-code-hooks/ # settings.json PreToolUse/PostToolUse/etc (408 lines)
|
2025-12-24 17:11:18 +09:00
|
|
|
├── comment-checker/ # Prevent excessive AI comments
|
2026-01-09 15:44:06 +09:00
|
|
|
│ ├── filters/ # docstring, directive, bdd, shebang
|
|
|
|
|
│ └── output/ # XML builder, formatter
|
2026-01-02 10:42:38 +09:00
|
|
|
├── compaction-context-injector/ # Preserve context during compaction
|
|
|
|
|
├── directory-agents-injector/ # Auto-inject AGENTS.md
|
|
|
|
|
├── directory-readme-injector/ # Auto-inject README.md
|
2026-01-09 15:44:06 +09:00
|
|
|
├── edit-error-recovery/ # Recover from edit failures
|
2025-12-24 17:11:18 +09:00
|
|
|
├── empty-message-sanitizer/ # Sanitize empty messages
|
|
|
|
|
├── interactive-bash-session/ # Tmux session management
|
2026-01-02 10:42:38 +09:00
|
|
|
├── keyword-detector/ # ultrawork/search keyword activation
|
|
|
|
|
├── non-interactive-env/ # CI/headless handling
|
|
|
|
|
├── preemptive-compaction/ # Pre-emptive at 85% usage
|
2026-01-09 15:44:06 +09:00
|
|
|
├── prometheus-md-only/ # Restrict prometheus to read-only
|
2026-01-02 10:42:38 +09:00
|
|
|
├── ralph-loop/ # Self-referential dev loop
|
2025-12-24 17:11:18 +09:00
|
|
|
├── rules-injector/ # Conditional rules from .claude/rules/
|
2026-01-09 15:44:06 +09:00
|
|
|
├── session-recovery/ # Recover from errors (432 lines)
|
|
|
|
|
├── sisyphus-orchestrator/ # Main orchestration hook (660 lines)
|
|
|
|
|
├── start-work/ # Initialize Sisyphus work session
|
|
|
|
|
├── task-resume-info/ # Track task resume state
|
2025-12-24 17:11:18 +09:00
|
|
|
├── think-mode/ # Auto-detect thinking triggers
|
2026-01-09 15:44:06 +09:00
|
|
|
├── thinking-block-validator/ # Validate thinking block format
|
2026-01-02 10:42:38 +09:00
|
|
|
├── agent-usage-reminder/ # Remind to use specialists
|
|
|
|
|
├── context-window-monitor.ts # Monitor usage (standalone)
|
|
|
|
|
├── session-notification.ts # OS notify on idle
|
2026-01-09 15:44:06 +09:00
|
|
|
├── todo-continuation-enforcer.ts # Force TODO completion (413 lines)
|
2026-01-02 10:42:38 +09:00
|
|
|
└── tool-output-truncator.ts # Truncate verbose outputs
|
2025-12-24 17:11:18 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## HOOK EVENTS
|
|
|
|
|
|
|
|
|
|
| Event | Timing | Can Block | Use Case |
|
|
|
|
|
|-------|--------|-----------|----------|
|
2026-01-02 10:42:38 +09:00
|
|
|
| PreToolUse | Before tool | Yes | Validate, modify input |
|
|
|
|
|
| PostToolUse | After tool | No | Add context, warnings |
|
|
|
|
|
| UserPromptSubmit | On prompt | Yes | Inject messages, block |
|
2025-12-24 17:11:18 +09:00
|
|
|
| Stop | Session idle | No | Inject follow-ups |
|
2026-01-02 10:42:38 +09:00
|
|
|
| onSummarize | Compaction | No | Preserve context |
|
|
|
|
|
|
|
|
|
|
## HOW TO ADD
|
|
|
|
|
|
|
|
|
|
1. Create `src/hooks/my-hook/`
|
|
|
|
|
2. Files: `index.ts` (createMyHook), `constants.ts`, `types.ts` (optional)
|
|
|
|
|
3. Return: `{ PreToolUse?, PostToolUse?, UserPromptSubmit?, Stop?, onSummarize? }`
|
|
|
|
|
4. Export from `src/hooks/index.ts`
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## PATTERNS
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
- **Storage**: JSON file for persistent state across sessions
|
|
|
|
|
- **Once-per-session**: Track injected paths in Set
|
|
|
|
|
- **Message injection**: Return `{ messages: [...] }`
|
|
|
|
|
- **Blocking**: Return `{ blocked: true, message: "..." }` from PreToolUse
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
- Heavy computation in PreToolUse (slows every tool call)
|
|
|
|
|
- Blocking without actionable message
|
|
|
|
|
- Duplicate injection (track what's injected)
|
|
|
|
|
- Missing try/catch (don't crash session)
|