2025-12-24 17:11:18 +09:00
|
|
|
# HOOKS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-02-01 19:26:57 +09:00
|
|
|
|
2026-02-08 17:51:30 +09:00
|
|
|
163 lifecycle hooks intercepting/modifying agent behavior across 5 events.
|
2026-02-01 19:26:57 +09:00
|
|
|
|
|
|
|
|
**Event Types**:
|
|
|
|
|
- `UserPromptSubmit` (`chat.message`) - Can block
|
|
|
|
|
- `PreToolUse` (`tool.execute.before`) - Can block
|
|
|
|
|
- `PostToolUse` (`tool.execute.after`) - Cannot block
|
|
|
|
|
- `Stop` (`event: session.stop`) - Cannot block
|
|
|
|
|
- `onSummarize` (Compaction) - Cannot block
|
2025-12-24 17:11:18 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
```
|
|
|
|
|
hooks/
|
2026-02-09 14:29:53 +09:00
|
|
|
├── agent-usage-reminder/ # Specialized agent hints (212 lines)
|
|
|
|
|
├── anthropic-context-window-limit-recovery/ # Auto-summarize on limit (2232 lines)
|
|
|
|
|
├── anthropic-effort/ # Anthropic effort level management (272 lines)
|
|
|
|
|
├── atlas/ # Main orchestration hook (1976 lines)
|
|
|
|
|
├── auto-slash-command/ # Detects /command patterns (1134 lines)
|
|
|
|
|
├── auto-update-checker/ # Plugin update check (1140 lines)
|
|
|
|
|
├── background-notification/ # OS notifications (33 lines)
|
|
|
|
|
├── category-skill-reminder/ # Reminds of category skills (597 lines)
|
|
|
|
|
├── claude-code-hooks/ # settings.json compat - see AGENTS.md (2110 lines)
|
|
|
|
|
├── comment-checker/ # Prevents AI slop comments (710 lines)
|
|
|
|
|
├── compaction-context-injector/ # Injects context on compaction (128 lines)
|
|
|
|
|
├── compaction-todo-preserver/ # Preserves todos during compaction (203 lines)
|
|
|
|
|
├── context-window-monitor.ts # Reminds of headroom (99 lines)
|
|
|
|
|
├── delegate-task-retry/ # Retries failed delegations (266 lines)
|
|
|
|
|
├── directory-agents-injector/ # Auto-injects AGENTS.md (195 lines)
|
|
|
|
|
├── directory-readme-injector/ # Auto-injects README.md (190 lines)
|
|
|
|
|
├── edit-error-recovery/ # Recovers from edit failures (188 lines)
|
|
|
|
|
├── empty-task-response-detector.ts # Detects empty responses (27 lines)
|
|
|
|
|
├── index.ts # Hook aggregation + registration (46 lines)
|
|
|
|
|
├── interactive-bash-session/ # Tmux session management (695 lines)
|
|
|
|
|
├── keyword-detector/ # ultrawork/search/analyze modes (1665 lines)
|
|
|
|
|
├── non-interactive-env/ # Non-TTY environment handling (483 lines)
|
|
|
|
|
├── preemptive-compaction.ts # Preemptive context compaction (108 lines)
|
|
|
|
|
├── prometheus-md-only/ # Planner read-only mode (955 lines)
|
|
|
|
|
├── question-label-truncator/ # Auto-truncates question labels (199 lines)
|
|
|
|
|
├── ralph-loop/ # Self-referential dev loop (1687 lines)
|
|
|
|
|
├── rules-injector/ # Conditional rules injection (1604 lines)
|
|
|
|
|
├── session-notification.ts # Session event notifications (108 lines)
|
|
|
|
|
├── session-recovery/ # Auto-recovers from crashes (1279 lines)
|
|
|
|
|
├── sisyphus-junior-notepad/ # Sisyphus Junior notepad (76 lines)
|
|
|
|
|
├── start-work/ # Sisyphus work session starter (648 lines)
|
|
|
|
|
├── stop-continuation-guard/ # Guards stop continuation (214 lines)
|
|
|
|
|
├── subagent-question-blocker/ # Blocks subagent questions (112 lines)
|
|
|
|
|
├── task-reminder/ # Task progress reminders (210 lines)
|
|
|
|
|
├── task-resume-info/ # Resume info for cancelled tasks (39 lines)
|
|
|
|
|
├── tasks-todowrite-disabler/ # Disables TodoWrite when tasks active (202 lines)
|
|
|
|
|
├── think-mode/ # Dynamic thinking budget (1365 lines)
|
|
|
|
|
├── thinking-block-validator/ # Ensures valid <thinking> blocks (169 lines)
|
|
|
|
|
├── todo-continuation-enforcer/ # Force TODO completion (2061 lines)
|
|
|
|
|
├── tool-output-truncator.ts # Prevents context bloat (62 lines)
|
|
|
|
|
├── unstable-agent-babysitter/ # Monitors unstable agent behavior (451 lines)
|
|
|
|
|
└── write-existing-file-guard/ # Guards against overwriting files (356 lines)
|
2025-12-24 17:11:18 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## HOOK EVENTS
|
2026-01-17 22:01:56 +09:00
|
|
|
| Event | Timing | Can Block | Use Case |
|
|
|
|
|
|-------|--------|-----------|----------|
|
2026-01-26 11:48:30 +09:00
|
|
|
| UserPromptSubmit | `chat.message` | Yes | Keyword detection, slash commands |
|
|
|
|
|
| PreToolUse | `tool.execute.before` | Yes | Validate/modify inputs, inject context |
|
|
|
|
|
| PostToolUse | `tool.execute.after` | No | Truncate output, error recovery |
|
|
|
|
|
| Stop | `event` (session.stop) | No | Auto-continue, notifications |
|
|
|
|
|
| onSummarize | Compaction | No | Preserve state, inject summary context |
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
## EXECUTION ORDER
|
2026-01-26 11:48:30 +09:00
|
|
|
- **UserPromptSubmit**: keywordDetector → claudeCodeHooks → autoSlashCommand → startWork
|
2026-02-06 18:59:58 +09:00
|
|
|
- **PreToolUse**: subagentQuestionBlocker → questionLabelTruncator → claudeCodeHooks → nonInteractiveEnv → commentChecker → directoryAgentsInjector → directoryReadmeInjector → rulesInjector → prometheusMdOnly → sisyphusJuniorNotepad → writeExistingFileGuard → atlasHook
|
|
|
|
|
- **PostToolUse**: claudeCodeHooks → toolOutputTruncator → contextWindowMonitor → commentChecker → directoryAgentsInjector → directoryReadmeInjector → rulesInjector → emptyTaskResponseDetector → agentUsageReminder → interactiveBashSession → editErrorRecovery → delegateTaskRetry → atlasHook → taskResumeInfo → taskReminder
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## HOW TO ADD
|
2026-01-17 22:01:56 +09:00
|
|
|
1. Create `src/hooks/name/` with `index.ts` exporting `createMyHook(ctx)`
|
2026-01-23 02:14:08 +09:00
|
|
|
2. Add hook name to `HookNameSchema` in `src/config/schema.ts`
|
2026-01-26 11:48:30 +09:00
|
|
|
3. Register in `src/index.ts` and add to relevant lifecycle methods
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-26 11:48:30 +09:00
|
|
|
## HOOK PATTERNS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-26 11:48:30 +09:00
|
|
|
**Simple Single-Event**:
|
|
|
|
|
```typescript
|
|
|
|
|
export function createToolOutputTruncatorHook(ctx) {
|
|
|
|
|
return { "tool.execute.after": async (input, output) => { ... } }
|
|
|
|
|
}
|
|
|
|
|
```
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-26 11:48:30 +09:00
|
|
|
**Multi-Event with State**:
|
|
|
|
|
```typescript
|
|
|
|
|
export function createThinkModeHook() {
|
|
|
|
|
const state = new Map<string, ThinkModeState>()
|
|
|
|
|
return {
|
|
|
|
|
"chat.params": async (output, sessionID) => { ... },
|
|
|
|
|
"event": async ({ event }) => { /* cleanup */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-26 11:48:30 +09:00
|
|
|
## ANTI-PATTERNS
|
2026-01-23 02:14:08 +09:00
|
|
|
- **Blocking non-critical**: Use PostToolUse warnings instead
|
2026-01-26 11:48:30 +09:00
|
|
|
- **Heavy computation**: Keep PreToolUse light to avoid latency
|
|
|
|
|
- **Redundant injection**: Track injected files to avoid context bloat
|
|
|
|
|
- **Direct state mutation**: Use `output.output +=` instead of replacing
|