2025-12-24 17:11:18 +09:00
|
|
|
# HOOKS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-01-13 21:00:00 +09:00
|
|
|
22+ lifecycle hooks intercepting/modifying agent behavior via PreToolUse, PostToolUse, UserPromptSubmit, and more.
|
2025-12-24 17:11:18 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
```
|
|
|
|
|
hooks/
|
2026-01-15 15:53:51 +09:00
|
|
|
├── sisyphus-orchestrator/ # Main orchestration & agent delegation (684 lines)
|
|
|
|
|
├── anthropic-context-window-limit-recovery/ # Auto-summarize at token limit (554 lines)
|
|
|
|
|
├── todo-continuation-enforcer.ts # Force completion of [ ] items (445 lines)
|
2026-01-13 21:00:00 +09:00
|
|
|
├── ralph-loop/ # Self-referential dev loop (364 lines)
|
|
|
|
|
├── claude-code-hooks/ # settings.json hook compatibility layer
|
|
|
|
|
├── comment-checker/ # Prevents AI slop/excessive comments
|
|
|
|
|
├── auto-slash-command/ # Detects and executes /command patterns
|
2025-12-24 17:11:18 +09:00
|
|
|
├── rules-injector/ # Conditional rules from .claude/rules/
|
2026-01-13 21:00:00 +09:00
|
|
|
├── directory-agents-injector/ # Auto-injects local AGENTS.md files
|
|
|
|
|
├── directory-readme-injector/ # Auto-injects local README.md files
|
|
|
|
|
├── preemptive-compaction/ # Triggers summary at 85% usage
|
|
|
|
|
├── edit-error-recovery/ # Recovers from tool execution failures
|
|
|
|
|
├── thinking-block-validator/ # Ensures valid <thinking> format
|
|
|
|
|
├── context-window-monitor.ts # Reminds agents of remaining headroom
|
|
|
|
|
├── session-recovery/ # Auto-recovers from session crashes
|
|
|
|
|
├── start-work/ # Initializes work sessions (ulw/ulw)
|
|
|
|
|
├── think-mode/ # Dynamic thinking budget adjustment
|
|
|
|
|
├── background-notification/ # OS notification on task completion
|
|
|
|
|
└── tool-output-truncator.ts # Prevents context bloat from verbose tools
|
2025-12-24 17:11:18 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## HOOK EVENTS
|
2026-01-13 21:00:00 +09:00
|
|
|
| Event | Timing | Can Block | Description |
|
|
|
|
|
|-------|--------|-----------|-------------|
|
|
|
|
|
| PreToolUse | Before tool | Yes | Validate/modify inputs (e.g., directory-agents-injector) |
|
|
|
|
|
| PostToolUse | After tool | No | Append context/warnings (e.g., edit-error-recovery) |
|
|
|
|
|
| UserPromptSubmit | On prompt | Yes | Filter/modify user input (e.g., keyword-detector) |
|
|
|
|
|
| Stop | Session idle | No | Auto-continue tasks (e.g., todo-continuation-enforcer) |
|
|
|
|
|
| onSummarize | Compaction | No | State preservation (e.g., compaction-context-injector) |
|
2026-01-02 10:42:38 +09:00
|
|
|
|
|
|
|
|
## HOW TO ADD
|
2026-01-13 21:00:00 +09:00
|
|
|
1. Create `src/hooks/name/` with `index.ts` factory (e.g., `createMyHook`).
|
|
|
|
|
2. Implement `PreToolUse`, `PostToolUse`, `UserPromptSubmit`, `Stop`, or `onSummarize`.
|
|
|
|
|
3. Register in `src/hooks/index.ts`.
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## PATTERNS
|
2026-01-13 21:00:00 +09:00
|
|
|
- **Context Injection**: Use `PreToolUse` to prepend instructions to tool inputs.
|
|
|
|
|
- **Resilience**: Implement `edit-error-recovery` style logic to retry failed tools.
|
|
|
|
|
- **Telegraphic UI**: Use `PostToolUse` to add brief warnings without bloating transcript.
|
|
|
|
|
- **Statelessness**: Prefer local file storage for state that must persist across sessions.
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2026-01-13 21:00:00 +09:00
|
|
|
- **Blocking**: Avoid blocking tools unless critical (use warnings in `PostToolUse` instead).
|
|
|
|
|
- **Latency**: No heavy computation in `PreToolUse`; it slows every interaction.
|
|
|
|
|
- **Redundancy**: Don't inject the same file multiple times; track state in session storage.
|
|
|
|
|
- **Prose**: Never use verbose prose in hook outputs; keep it technical and brief.
|