Skip to main content

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 exist

What It Enables

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
MCP Tool Used: register-agentWhy it matters: Other agents can discover and message you
Shows critical coordination info at session start:
MCP Tools Used: fetch-inbox, list-file-reservationsWhy it matters: You see coordination status before starting work
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
MCP Tool Used: search-memoriesWhy it matters: AI has context from previous sessions without manual explanation
Warns if critical acknowledgments are pending:
MCP Tool Used: get-action-itemsWhy it matters: You don’t forget critical obligations

Exit Codes

Example blocking scenario:

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 every Write or Edit tool execution Blocking: βœ… Can block edits to prevent conflicts

What It Enables

Checks if file is reserved by another agent before allowing edit:Flow:
  1. Hook fires before edit
  2. Queries Coordination API: β€œIs this file reserved?”
  3. If reserved by another agent β†’ Block edit (exit code 2)
  4. If not reserved β†’ Create reservation β†’ Allow edit (exit code 0)
MCP Tools Used: list-file-reservations, reserve-file-pathsResult: Zero merge conflicts, guaranteed
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)
Default behavior: Shared mode with 2-hour expirationMCP Tool Used: reserve-file-pathsWhy it matters: You don’t manually manage file locks
When edits are blocked, suggests coordination actions:
MCP Tool Used: send-message (if user chooses to message)Why it matters: Clear path to resolving conflicts

Exit Codes


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 every Write or Edit tool execution Blocking: ❌ Non-blocking (always returns exit code 0)

What It Enables

Shows tasks/obligations related to the edited file:
MCP Tool Used: get-action-itemsWhy it matters: You don’t forget required follow-ups
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 updates
Records edit for coordination audit trail:
  • Timestamp
  • File path
  • Agent identity
  • Reservation status
  • Lines changed
MCP Tool Used: log-eventWhy it matters: Complete transparency for team oversight

Exit Codes


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

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
Salience filtering: Only saves memories with importance β‰₯ configured threshold (default 0.5)MCP Tool Used: store-memoryResult: Critical context preserved even after compaction
Intelligently extracts what matters:
MCP Tool Used: store-memory (with bulk insert)Why it matters: AI has long-term memory across sessions

Exit Codes


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 alerts

What It Enables

Displays high-priority coordination messages before AI responds:
MCP Tool Used: fetch-inbox (filter: priority=urgent, unread=true)Why it matters: Critical info never missed
Reminds about pending acks that need attention:
MCP Tool Used: get-action-itemsWhy it matters: Obligations don’t get forgotten

Exit Codes


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 interruption

What It Enables

Blocks stop if critical operations are incomplete:
MCP Tool Used: get-action-items (filter: blocking=true)Why it matters: Prevents data corruption and orphaned locks
Warns about unacknowledged critical messages:
MCP Tool Used: get-action-itemsWhy it matters: Important coordination doesn’t fall through cracks

Exit Codes


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

Releases all file reservations automatically:
MCP Tool Used: release-file-reservationsResult: Zero orphaned file locks
Marks agent as offline in Coordination:
  • Sets status to β€œoffline”
  • Records last seen timestamp
  • Updates session duration
MCP Tool Used: update-agent-statusWhy it matters: Other agents know you’re no longer active
Optionally creates final memory snapshot:
  • Saves unresolved tasks
  • Records session learnings
  • Stores pending obligations
MCP Tool Used: store-memoryWhy it matters: Next session continues seamlessly

Exit Codes


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

Stores subagent learnings to shared memory:
MCP Tool Used: store-memoryWhy it matters: Subagent learnings benefit entire team
Releases files reserved by subagent:
  • Subagent file reservations are auto-released
  • Parent agent can access those files again
  • Other agents can now reserve them
MCP Tool Used: release-file-reservationsWhy it matters: No orphaned locks from subagents
Reports subagent results to parent:
MCP Tool Used: update-taskWhy it matters: Parent agent knows when delegated work is done

Exit Codes


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

Total overhead across all hooks: ~140ms average per hook execution Network efficiency: 14 total MCP calls distributed across 8 hooks Perceived performance impact: Minimal - blocking hooks only fire when necessary

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