Understanding ULPI Lifecycle Hooks
Every AI coding assistant goes through a predictable lifecycle: start session → receive prompts → execute tools → compact context → end session. ULPI Hooks intercept 8 critical moments in this lifecycle to enable coordination, memory preservation, and conflict prevention. This guide explains each hook in detail: when it fires, what it enables, exit codes, performance characteristics, and integration with other ULPI products.Hook Execution Flow
Understanding when hooks fire in relation to your AI assistant’s operations:Hook 1: session-start
When It Fires
Trigger: Your AI coding assistant starts a new chat session Frequency: Once per session (typically when you open the IDE or create a new chat) Blocking: ✅ Can block session start if critical issues existWhat It Enables
Agent Registration
Agent Registration
Automatically registers your AI assistant with ULPI Coordination:
- Creates unique agent identity (e.g., “Claude-Code-YourName”)
- Sets online status
- Associates with project/repository
- Establishes contact policies
register-agentWhy it matters: Other agents can discover and message youCoordination Dashboard Display
Coordination Dashboard Display
Shows critical coordination info at session start:MCP Tools Used:
fetch-inbox, list-file-reservationsWhy it matters: You see coordination status before starting workMemory Context Loading
Memory Context Loading
Retrieves relevant memories from previous sessions:
- Searches for memories related to current project
- Loads high-salience memories (importance > 0.7)
- Injects context into session automatically
search-memoriesWhy it matters: AI has context from previous sessions without manual explanationPending Acknowledgments Alert
Pending Acknowledgments Alert
Warns if critical acknowledgments are pending:MCP Tool Used:
get-action-itemsWhy it matters: You don’t forget critical obligationsExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Allow session start | Default - no blocking issues |
2 | Block session start | Critical pending acks that must be addressed first |
Performance
- Average latency: 150ms
- MCP calls: 3-5 (register-agent, fetch-inbox, list-file-reservations, search-memories, get-action-items)
- Network requests: 3-5 (one per MCP call)
- User impact: Minimal - dashboard appears within 200ms of session start
Configuration
~/.ulpi/config.json
Hook 2: pre-tool-use:edit
When It Fires
Trigger: AI assistant attempts to edit any file Frequency: Before everyWrite or Edit tool execution
Blocking: ✅ Can block edits to prevent conflicts
What It Enables
File Conflict Prevention
File Conflict Prevention
Checks if file is reserved by another agent before allowing edit:Flow:
- Hook fires before edit
- Queries Coordination API: “Is this file reserved?”
- If reserved by another agent → Block edit (exit code 2)
- If not reserved → Create reservation → Allow edit (exit code 0)
list-file-reservations, reserve-file-pathsResult: Zero merge conflicts, guaranteedAutomatic File Reservation
Automatic File Reservation
Auto-reserves files on first edit:Reservation modes:
- Shared: Multiple agents can read/edit (used for config files, docs)
- Exclusive: Only one agent can edit (used for critical code files)
reserve-file-pathsWhy it matters: You don’t manually manage file locksConflict Resolution Guidance
Conflict Resolution Guidance
When edits are blocked, suggests coordination actions:MCP Tool Used:
send-message (if user chooses to message)Why it matters: Clear path to resolving conflictsExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Allow edit | File available OR already reserved by this agent |
2 | Block edit | File reserved by another agent in exclusive or conflicting mode |
Performance
- Average latency: 120ms (fastest hook)
- MCP calls: 1-2 (list-file-reservations, optionally reserve-file-paths)
- Network requests: 1-2
- User impact: Imperceptible - edits proceed normally unless conflict detected
Configuration
~/.ulpi/config.json
Hook 3: post-tool-use:edit
When It Fires
Trigger: AI assistant completes a file edit successfully Frequency: After everyWrite or Edit tool execution
Blocking: ❌ Non-blocking (always returns exit code 0)
What It Enables
Obligation Tracking
Obligation Tracking
Shows tasks/obligations related to the edited file:MCP Tool Used:
get-action-itemsWhy it matters: You don’t forget required follow-upsTask Status Updates
Task Status Updates
If edit is part of a tracked task, updates task progress:MCP Tool Used:
update-task (via ULPI Tasks integration)Why it matters: Automatic task tracking without manual updatesAudit Logging
Audit Logging
Records edit for coordination audit trail:
- Timestamp
- File path
- Agent identity
- Reservation status
- Lines changed
log-eventWhy it matters: Complete transparency for team oversightExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Continue | Always (non-blocking hook) |
Performance
- Average latency: 80ms (runs asynchronously)
- MCP calls: 1 (get-action-items)
- Network requests: 1
- User impact: None - runs in background
Configuration
~/.ulpi/config.json
Hook 4: pre-compact
When It Fires
Trigger: Claude approaches token limit and prepares to compact conversation Frequency: Varies - typically every 2-3 hours in long sessions Blocking: ✅ Can block compaction (rarely used)What It Enables
Automatic Memory Snapshots
Automatic Memory Snapshots
Creates memory snapshot of important context before compaction:What gets saved:
- Architecture decisions and rationale
- Important code patterns and conventions
- Project-specific context and constraints
- Active tasks and their status
- Pending obligations
store-memoryResult: Critical context preserved even after compactionContext Extraction
Context Extraction
Intelligently extracts what matters:MCP Tool Used:
store-memory (with bulk insert)Why it matters: AI has long-term memory across sessionsExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Allow compaction | Default - snapshot created successfully |
2 | Block compaction | Critical context extraction failed (rare) |
Performance
- Average latency: 200ms (slowest hook due to context extraction)
- MCP calls: 2-3 (analyze conversation, store-memory bulk)
- Network requests: 2-3
- User impact: Minimal - compaction delayed by ~200ms
Configuration
~/.ulpi/config.json
Hook 5: user-prompt-submit
When It Fires
Trigger: User submits a prompt to the AI assistant Frequency: Before every AI response Blocking: ✅ Can block response to show urgent alertsWhat It Enables
Urgent Message Alerts
Urgent Message Alerts
Displays high-priority coordination messages before AI responds:MCP Tool Used:
fetch-inbox (filter: priority=urgent, unread=true)Why it matters: Critical info never missedPending Acknowledgment Reminders
Pending Acknowledgment Reminders
Reminds about pending acks that need attention:MCP Tool Used:
get-action-itemsWhy it matters: Obligations don’t get forgottenExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Allow response | No urgent messages or user dismissed alerts |
2 | Block response | Urgent message requires acknowledgment before proceeding |
Performance
- Average latency: 100ms
- MCP calls: 1-2 (fetch-inbox, get-action-items)
- Network requests: 1-2
- User impact: Slight delay before AI responds (only if urgent messages exist)
Configuration
~/.ulpi/config.json
Hook 6: stop
When It Fires
Trigger: User clicks stop/cancel button during AI execution Frequency: Only when user manually stops execution Blocking: ✅ Can block stop to prevent unsafe interruptionWhat It Enables
Prevent Unsafe Shutdowns
Prevent Unsafe Shutdowns
Blocks stop if critical operations are incomplete:MCP Tool Used:
get-action-items (filter: blocking=true)Why it matters: Prevents data corruption and orphaned locksPending Acknowledgment Warnings
Pending Acknowledgment Warnings
Warns about unacknowledged critical messages:MCP Tool Used:
get-action-itemsWhy it matters: Important coordination doesn’t fall through cracksExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Allow stop | Safe to stop - no critical pending operations |
2 | Block stop | Critical operations incomplete or urgent acks pending |
Performance
- Average latency: 90ms
- MCP calls: 1 (get-action-items)
- Network requests: 1
- User impact: Stop button delayed by ~100ms (only if blocking issues exist)
Configuration
~/.ulpi/config.json
Hook 7: session-end
When It Fires
Trigger: AI assistant session ends (user closes chat, IDE closes, etc.) Frequency: Once per session Blocking: ❌ Non-blocking (cleanup hook)What It Enables
Automatic File Reservation Release
Automatic File Reservation Release
Releases all file reservations automatically:MCP Tool Used:
release-file-reservationsResult: Zero orphaned file locksAgent Status Update
Agent Status Update
Marks agent as offline in Coordination:
- Sets status to “offline”
- Records last seen timestamp
- Updates session duration
update-agent-statusWhy it matters: Other agents know you’re no longer activeFinal Memory Snapshot
Final Memory Snapshot
Optionally creates final memory snapshot:
- Saves unresolved tasks
- Records session learnings
- Stores pending obligations
store-memoryWhy it matters: Next session continues seamlesslyExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Complete cleanup | Always (non-blocking hook) |
Performance
- Average latency: 110ms (runs async, doesn’t delay session close)
- MCP calls: 2-3 (release-file-reservations, update-agent-status, store-memory)
- Network requests: 2-3
- User impact: None - runs in background as session closes
Configuration
~/.ulpi/config.json
Hook 8: subagent-stop
When It Fires
Trigger: A spawned subagent completes its task Frequency: When using Task agent or spawning subagents Blocking: ❌ Non-blocking (cleanup hook)What It Enables
Learning Consolidation
Learning Consolidation
Stores subagent learnings to shared memory:MCP Tool Used:
store-memoryWhy it matters: Subagent learnings benefit entire teamSubagent Reservation Release
Subagent Reservation Release
Releases files reserved by subagent:
- Subagent file reservations are auto-released
- Parent agent can access those files again
- Other agents can now reserve them
release-file-reservationsWhy it matters: No orphaned locks from subagentsTask Result Reporting
Task Result Reporting
Reports subagent results to parent:MCP Tool Used:
update-taskWhy it matters: Parent agent knows when delegated work is doneExit Codes
| Code | Meaning | When Used |
|---|---|---|
0 | Complete cleanup | Always (non-blocking hook) |
Performance
- Average latency: 95ms (async)
- MCP calls: 1-2 (store-memory, release-file-reservations, update-task)
- Network requests: 1-2
- User impact: None - subagent cleanup is background operation
Configuration
~/.ulpi/config.json
Hook Performance Summary
| Hook | Avg Latency | MCP Calls | Blocking | User Impact |
|---|---|---|---|---|
| session-start | 150ms | 3-5 | ✅ | Dashboard shown |
| pre-tool-use:edit | 120ms | 1-2 | ✅ | Imperceptible |
| post-tool-use:edit | 80ms | 1 | ❌ | None (async) |
| pre-compact | 200ms | 2-3 | ✅ | ~200ms compaction delay |
| user-prompt-submit | 100ms | 1-2 | ✅ | Slight response delay |
| stop | 90ms | 1 | ✅ | ~100ms stop delay |
| session-end | 110ms | 2-3 | ❌ | None (async) |
| subagent-stop | 95ms | 1-2 | ❌ | None (async) |
Next Steps
File Conflict Prevention Deep Dive
Master the pre-edit hook and achieve zero merge conflicts
Memory Integration
Learn how pre-compact hooks preserve context automatically
Use Cases
See real-world scenarios where hooks save hours daily
Assistant Compatibility
Setup guides for Claude Code, Cursor, Windsurf, and more