2025-12-24 17:11:18 +09:00
|
|
|
# HOOKS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
31 lifecycle hooks intercepting/modifying agent behavior. Events: PreToolUse, PostToolUse, UserPromptSubmit, Stop, onSummarize.
|
2025-12-24 17:11:18 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2025-12-24 17:11:18 +09:00
|
|
|
```
|
|
|
|
|
hooks/
|
2026-01-23 16:00:38 +09:00
|
|
|
├── atlas/ # Main orchestration (773 lines)
|
2026-01-23 02:14:08 +09:00
|
|
|
├── anthropic-context-window-limit-recovery/ # Auto-summarize
|
2026-01-25 13:12:40 +09:00
|
|
|
├── todo-continuation-enforcer.ts # Force TODO completion (489 lines)
|
2026-01-23 02:14:08 +09:00
|
|
|
├── ralph-loop/ # Self-referential dev loop
|
|
|
|
|
├── 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-01-17 22:01:56 +09:00
|
|
|
├── session-recovery/ # Auto-recovers from crashes
|
|
|
|
|
├── 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
|
|
|
|
|
├── auto-update-checker/ # Plugin update check
|
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
|
|
|
|
|
├── question-label-truncator/ # Auto-truncates question labels >30 chars
|
|
|
|
|
└── 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-23 02:14:08 +09:00
|
|
|
| PreToolUse | Before tool | Yes | Validate/modify inputs |
|
|
|
|
|
| PostToolUse | After tool | No | Append warnings, truncate |
|
|
|
|
|
| UserPromptSubmit | On prompt | Yes | Keyword detection |
|
|
|
|
|
| Stop | Session idle | No | Auto-continue |
|
|
|
|
|
| onSummarize | Compaction | No | Preserve state |
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
## EXECUTION ORDER
|
|
|
|
|
|
|
|
|
|
**chat.message**: keywordDetector → claudeCodeHooks → autoSlashCommand → startWork → ralphLoop
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
**tool.execute.before**: claudeCodeHooks → nonInteractiveEnv → commentChecker → directoryAgentsInjector → rulesInjector
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
**tool.execute.after**: editErrorRecovery → delegateTaskRetry → commentChecker → toolOutputTruncator → claudeCodeHooks
|
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`
|
|
|
|
|
3. Register in `src/index.ts`:
|
2026-01-17 22:01:56 +09:00
|
|
|
```typescript
|
|
|
|
|
const myHook = isHookEnabled("my-hook") ? createMyHook(ctx) : null
|
|
|
|
|
```
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## PATTERNS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
- **Session-scoped state**: `Map<sessionID, Set<string>>`
|
2026-01-17 22:01:56 +09:00
|
|
|
- **Conditional execution**: Check `input.tool` before processing
|
2026-01-23 02:14:08 +09:00
|
|
|
- **Output modification**: `output.output += "\n${REMINDER}"`
|
2025-12-24 17:11:18 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
- **Blocking non-critical**: Use PostToolUse warnings instead
|
|
|
|
|
- **Heavy computation**: Keep PreToolUse light
|
|
|
|
|
- **Redundant injection**: Track injected files
|