AGENTS.md
src/hooks/AGENTS.mdAGENTS.md
Quality
74/100
Scores the file, not the repository.Length
1,065 words
27 headings · 5 code blocksRepository
38k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1<!-- Parent: ../AGENTS.md -->2<!-- Generated: 2026-01-28 | Updated: 2026-01-31 -->34# hooks5631 event-driven hooks that power execution modes and behaviors.78## Purpose910Hooks intercept Claude Code events to enable:11- **Execution modes**: autopilot, ultrawork, ralph, ultrapilot, swarm, pipeline (mode-registry)12- **Validation**: thinking blocks, empty messages, comments13- **Recovery**: edit errors, session recovery, context window14- **Enhancement**: rules injection, directory READMEs, notepad15- **Detection**: keywords, think mode, slash commands1617## Key Files1819| File | Description |20|------|-------------|21| `index.ts` | Re-exports all hooks |22| `bridge.ts` | Shell script entry point - `processHook()` routes events to handlers |2324## Subdirectories2526### Execution Mode Hooks2728| Directory | Purpose | Trigger |29|-----------|---------|---------|30| `autopilot/` | Full autonomous execution | "autopilot", "build me" |31| `ultrawork/` | Maximum parallel execution | "ulw", "ultrawork" |32| `ralph/` | Persistence until verified | "ralph", "don't stop" |33| `ultrapilot/` | Parallel autopilot with file ownership | "ultrapilot" |34| `swarm/` | N coordinated agents with task claiming | "swarm N agents" |35| `ultraqa/` | QA cycling until goal met | test failures |36| `mode-registry/` | Tracks active execution mode | internal |37| `persistent-mode/` | Maintains mode state across sessions | internal |3839### Validation Hooks4041| Directory | Purpose |42|-----------|---------|43| `thinking-block-validator/` | Validates thinking blocks in responses |44| `empty-message-sanitizer/` | Handles empty/whitespace messages |45| `comment-checker/` | Checks code comment quality |46| `permission-handler/` | Handles permission requests and validation |4748### Recovery Hooks4950| Directory | Purpose |51|-----------|---------|52| `recovery/` | Edit error recovery, session recovery |53| `preemptive-compaction/` | Prevents context overflow |54| `pre-compact/` | Pre-compaction processing |5556### Enhancement Hooks5758| Directory | Purpose |59|-----------|---------|60| `rules-injector/` | Injects matching rule files |61| `directory-readme-injector/` | Injects directory READMEs |62| `notepad/` | Persists notes for compaction resilience |63| `learner/` | Skill extraction from conversations |64| `agent-usage-reminder/` | Reminds about agent delegation |6566### Detection Hooks6768| Directory | Purpose |69|-----------|---------|70| `keyword-detector/` | Magic keyword detection |71| `think-mode/` | Extended thinking detection |72| `auto-slash-command/` | Slash command expansion |73| `non-interactive-env/` | Non-interactive environment detection |74| `plugin-patterns/` | Plugin pattern detection |7576### Coordination Hooks7778| Directory | Purpose |79|-----------|---------|80| `todo-continuation/` | Enforces task completion |81| `omc-orchestrator/` | Orchestrator behavior |82| `subagent-tracker/` | Tracks spawned sub-agents |83| `session-end/` | Session termination handling |84| `background-notification/` | Background task notifications |8586### Setup Hooks8788| Directory | Purpose |89|-----------|---------|90| `setup/` | Initial setup and configuration |9192## For AI Agents9394### Working In This Directory9596#### Hook Structure9798Each hook follows a standard pattern:99```100hook-name/101├── index.ts # Main hook implementation102├── types.ts # TypeScript interfaces103├── constants.ts # Configuration constants104└── *.ts # Supporting modules105```106107#### When Adding a New Hook1081091. Create hook directory with `index.ts`, `types.ts`, `constants.ts`1102. Export from `index.ts` (hook re-exports)1113. Register handler in `bridge.ts` if needed1124. Update `docs/REFERENCE.md` (Hooks System section) with new hook entry1135. If execution mode hook, also create `skills/*/SKILL.md` and `commands/*.md`114115#### Hook Implementation116117```typescript118// index.ts119export interface HookConfig {120 enabled: boolean;121 // hook-specific config122}123124export function createHook(config: HookConfig) {125 return {126 name: 'hook-name',127 event: 'UserPromptSubmit', // or 'Stop', 'PreToolUse', 'PostToolUse'128 handler: async (context) => {129 // Hook logic130 return { modified: false };131 }132 };133}134```135136#### Key Hooks Explained137138**autopilot/** - Full autonomous execution:139- Validates goals and creates plans140- Manages execution state141- Handles cancellation142- Enforces completion143144**ralph/** - Persistence mechanism:145- Tracks progress via PRD146- Spawns architect for verification147- Loops until verified complete148- Supports structured PRD format149150**ultrapilot/** - Parallel autopilot:151- Decomposes tasks into subtasks152- Assigns file ownership to workers153- Coordinates parallel execution154- Integrates results155156**swarm/** - Coordinated multi-agent:157- SQLite-based task claiming158- 5-minute timeout per task159- Atomic claim/release160- Clean completion detection161162**learner/** - Skill extraction:163- Detects skill patterns in conversation164- Extracts to local skill files165- Auto-invokes matching skills166- Manages skill lifecycle167168### Common Patterns169170#### State Management171172```typescript173import { readState, writeState } from '../features/state-manager';174175const state = readState('autopilot-state');176state.phase = 'executing';177writeState('autopilot-state', state);178```179180#### Event Handling181182```typescript183// UserPromptSubmit - Before prompt is sent184// Stop - Before session ends185// PreToolUse - Before tool execution186// PostToolUse - After tool execution187```188189### Testing Requirements190191- Test specific hooks with `npm test -- --grep "hook-name"`192- Test execution modes end-to-end with skill invocation193- Verify state persistence in `.omc/state/`194- For security hooks, follow `templates/rules/security.md` checklist195196## Dependencies197198### Internal199- `features/state-manager/` for state persistence200- `features/verification/` for verification protocol201- `agents/` for spawning sub-agents202203### External204| Package | Purpose |205|---------|---------|206| `better-sqlite3` | Swarm task coordination |207| `fs`, `path` | State file operations |208209## Hook Events210211| Event | When Fired | Common Uses |212|-------|------------|-------------|213| `UserPromptSubmit` | Before prompt processing | Keyword detection, mode activation |214| `Stop` | Before session ends | Continuation enforcement |215| `PreToolUse` | Before tool execution | Permission validation |216| `PostToolUse` | After tool execution | Error recovery, rules injection |217218### Stop Hook Output Contract219220The persistent-mode stop hook uses **soft enforcement**:221222```typescript223// Stop hook ALWAYS returns continue: true224// Enforcement is via message injection, not blocking225return {226 continue: true,227 message: result.message || undefined // Injected into context228};229```230231**Why soft enforcement**: Hard blocking (`continue: false`) would prevent context compaction and could deadlock Claude Code.232233**Bypass conditions** (checked first, allow stopping):2341. `context-limit` - Context window exhausted, must allow compaction2352. `user-abort` - User explicitly requested stop236237**Mode priority** (checked after bypass, may inject continuation message):2381. Ralph (explicit persistence loop)2392. Autopilot (full orchestration)2403. Ultrapilot (parallel workers)2414. Swarm (coordinated agents)2425. Pipeline (sequential stages)2436. UltraQA (test cycling)2447. Ultrawork (parallel execution)245246**Session isolation**: Hooks only enforce for matching `session_id`. Stale states (>2 hours) are ignored.247248**Mode completion criteria**: Hook blocks while `state.active === true && state.session_id === currentSession && !isStaleState()`. Running `/cancel` sets `active: false` and removes state files.249250## State Files251252| Hook | State File |253|------|------------|254| autopilot | `.omc/state/autopilot-state.json` |255| ultrapilot | `.omc/state/ultrapilot-state.json` |256| ralph | `.omc/state/ralph-state.json` |257| swarm | `.omc/state/swarm-tasks.db` (SQLite) |258| learner | `~/.claude/local-skills/` |259260<!-- MANUAL: -->261
Also in Yeachan-Heo/oh-my-claudecode
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| Yeachan-Heo/oh-my-claudecode.github/CLAUDE.md · 38k | CLAUDE.md | setupbuildstylegit+2 | 79/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodeAGENTS.md · 38k | AGENTS.md | setuplint-formatstyletypes+4 | 45/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodeskills/AGENTS.md · 38k | AGENTS.md | teststylearchdependencies+1 | 66/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/AGENTS.md · 38k | AGENTS.md | buildteststylearch+2 | 77/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/agents/AGENTS.md · 38k | AGENTS.md | teststylearchdependencies+1 | 66/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/features/AGENTS.md · 38k | AGENTS.md | teststylearchdependencies | 74/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/tools/AGENTS.md · 38k | AGENTS.md | setupteststylearch+1 | 86/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/tools/diagnostics/AGENTS.md · 38k | AGENTS.md | teststylearchtypes+2 | 77/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodesrc/tools/lsp/AGENTS.md · 38k | AGENTS.md | setupteststylearch+2 | 74/100 | 3 days ago | |
| Yeachan-Heo/oh-my-claudecodeCLAUDE.md · 38k | CLAUDE.md | setupbuildstylegit+1 | 65/100 | 3 days ago |
Diff against .github/CLAUDE.md Diff against AGENTS.md Diff against skills/AGENTS.md Diff against src/AGENTS.md Diff against src/agents/AGENTS.md Diff against src/features/AGENTS.md Diff against src/tools/AGENTS.md Diff against src/tools/diagnostics/AGENTS.md Diff against src/tools/lsp/AGENTS.md Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago |
