2025-12-24 17:11:18 +09:00
|
|
|
# HOOKS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-02-01 19:26:57 +09:00
|
|
|
|
2026-02-06 18:59:58 +09:00
|
|
|
40+ 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-06 18:59:58 +09:00
|
|
|
├── atlas/ # Main orchestration (770 lines)
|
2026-01-26 11:48:30 +09:00
|
|
|
├── anthropic-context-window-limit-recovery/ # Auto-summarize
|
2026-02-06 18:59:58 +09:00
|
|
|
├── todo-continuation-enforcer.ts # Force TODO completion (517 lines)
|
|
|
|
|
├── ralph-loop/ # Self-referential dev loop (428 lines)
|
2026-01-23 02:14:08 +09:00
|
|
|
├── claude-code-hooks/ # settings.json compat layer - see AGENTS.md
|
|
|
|
|
├── comment-checker/ # Prevents AI slop
|
2026-01-17 22:01:56 +09:00
|
|
|
├── auto-slash-command/ # Detects /command patterns
|
2026-01-23 02:14:08 +09:00
|
|
|
├── rules-injector/ # Conditional rules
|
|
|
|
|
├── directory-agents-injector/ # Auto-injects AGENTS.md
|
|
|
|
|
├── directory-readme-injector/ # Auto-injects README.md
|
|
|
|
|
├── edit-error-recovery/ # Recovers from failures
|
|
|
|
|
├── thinking-block-validator/ # Ensures valid <thinking>
|
|
|
|
|
├── context-window-monitor.ts # Reminds of headroom
|
2026-02-06 18:59:58 +09:00
|
|
|
├── session-recovery/ # Auto-recovers from crashes (436 lines)
|
|
|
|
|
├── session-notification.ts # Session event notifications (337 lines)
|
2026-01-17 22:01:56 +09:00
|
|
|
├── think-mode/ # Dynamic thinking budget
|
|
|
|
|
├── keyword-detector/ # ultrawork/search/analyze modes
|
2026-01-23 02:14:08 +09:00
|
|
|
├── background-notification/ # OS notification
|
|
|
|
|
├── prometheus-md-only/ # Planner read-only mode
|
|
|
|
|
├── agent-usage-reminder/ # Specialized agent hints
|
2026-02-06 18:59:58 +09:00
|
|
|
├── auto-update-checker/ # Plugin update check (304 lines)
|
2026-01-25 13:12:40 +09:00
|
|
|
├── tool-output-truncator.ts # Prevents context bloat
|
|
|
|
|
├── compaction-context-injector/ # Injects context on compaction
|
|
|
|
|
├── delegate-task-retry/ # Retries failed delegations
|
|
|
|
|
├── interactive-bash-session/ # Tmux session management
|
|
|
|
|
├── non-interactive-env/ # Non-TTY environment handling
|
|
|
|
|
├── start-work/ # Sisyphus work session starter
|
|
|
|
|
├── task-resume-info/ # Resume info for cancelled tasks
|
2026-01-26 11:48:30 +09:00
|
|
|
├── question-label-truncator/ # Auto-truncates question labels
|
|
|
|
|
├── category-skill-reminder/ # Reminds of category skills
|
|
|
|
|
├── empty-task-response-detector.ts # Detects empty responses
|
|
|
|
|
├── sisyphus-junior-notepad/ # Sisyphus Junior notepad
|
2026-02-01 19:26:57 +09:00
|
|
|
├── stop-continuation-guard/ # Guards stop continuation
|
|
|
|
|
├── subagent-question-blocker/ # Blocks subagent questions
|
2026-02-06 18:59:58 +09:00
|
|
|
├── task-reminder/ # Task progress reminders
|
|
|
|
|
├── tasks-todowrite-disabler/ # Disables TodoWrite when task system active
|
|
|
|
|
├── unstable-agent-babysitter/ # Monitors unstable agent behavior
|
|
|
|
|
├── write-existing-file-guard/ # Guards against overwriting existing files
|
|
|
|
|
├── preemptive-compaction.ts # Preemptive context compaction
|
2026-01-25 13:12:40 +09:00
|
|
|
└── index.ts # Hook aggregation + registration
|
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
|