Skip to main content

Zero Merge Conflicts with Pre-Edit Hooks

The #1 pain point in multi-agent development: merge conflicts. Two agents edit the same file. Git detects conflicts. You spend 15 minutes manually resolving. Repeat 12-20 times per week. ULPI’s pre-edit hook solves this permanently. Before any file edit, the hook checks reservations and blocks conflicts before they happen. Result: Zero merge conflicts. Guaranteed.

The Problem: Uncoordinated File Access

Without Pre-Edit Hooks

10:00 AM - Alice (Cursor) starts editing auth.ts
10:15 AM - Bob (Claude Code) also starts editing auth.ts (doesn’t know Alice is working on it)
10:30 AM - Alice commits and pushes10:45 AM - Bob tries to push…
10:45 AM - 11:00 AM - Bob spends 15 minutes manually resolving conflictTotal time wasted: 15 minutes × 12 conflicts/week = 3 hours/week lost to merge conflicts

The Solution: Pre-Edit Hook + File Reservations

How It Works

1

Agent Attempts Edit

Alice (Cursor) wants to edit src/auth.ts:
2

Pre-Edit Hook Intercepts

BEFORE the edit executes, the pre-tool-use:edit hook fires:
3

Check Existing Reservations

Hook queries ULPI Coordination API:
Response:
4

Create Reservation

File is available, so hook creates reservation:
Response:
5

Allow Edit

Hook returns exit code 0 → Edit proceeds:
Alice successfully edits the file.
6

Bob Tries to Edit Same File

15 minutes later, Bob (Claude Code) attempts to edit auth.ts:
Pre-edit hook fires again…
7

Detect Conflict

Hook checks reservations:
Response:
File is already reserved!
8

Block Edit

Hook returns exit code 2Edit blocked:
Bob cannot edit the file. Conflict prevented.
9

Coordinate Instead of Conflict

Bob chooses option 1 (Message Alice):
Alice receives message and they coordinate:
Result: Coordination instead of conflict

Reservation Modes

Pre-edit hooks support two reservation modes:

Shared Mode (Default)

Use for: Config files, documentation, non-critical edits Behavior:
  • Multiple agents can reserve the same file in shared mode
  • Edits are allowed concurrently
  • Agents are notified of other shared reservations
  • Coordination encouraged but not enforced
Example:
When to use:
  • Documentation files
  • Configuration files (if small changes)
  • Comment-only edits
  • Files with clear sections (different agents edit different sections)

Exclusive Mode

Use for: Critical code files, database migrations, breaking changes Behavior:
  • Only one agent can hold exclusive reservation
  • All other agents blocked from editing
  • Strictest conflict prevention
Example:
When to use:
  • Database migration files
  • Configuration files with complex interdependencies
  • Critical business logic files
  • Files undergoing major refactors

Reservation Management

Auto-Reservation on First Edit

By default, pre-edit hooks automatically create reservations:
~/.ulpi/config.json
Behavior:
  1. First edit of a file → Reservation created automatically
  2. Subsequent edits → Existing reservation reused (if still valid)
  3. Reservation expires → New reservation created on next edit

Manual Reservations

You can also reserve files manually before editing:
When to use manual reservations:
  • You know you’ll be working on multiple related files
  • Major refactor affecting many files
  • Want to claim files before starting work
  • Prevent others from editing during planning phase

Viewing Reservations

See all active file reservations:
Example output:

Releasing Reservations

Reservations are automatically released when:
  • Session ends (session-end hook)
  • Reservation expires (default 2 hours)
  • File is committed (optional - configure via releaseOnCommit)
Manual release:

Conflict Resolution Strategies

When pre-edit hook blocks your edit, you have options:

Strategy 1: Coordinate via Messaging

Best for: Normal collaboration, non-urgent edits
Outcome: Coordinate and avoid conflict

Strategy 2: Wait for Expiration

Best for: Non-urgent edits, when waiting is acceptable
Outcome: Wait, then edit when file becomes available

Strategy 3: Edit Different File

Best for: When you can make progress elsewhere
Outcome: Make progress on related work

Strategy 4: Request Override (Emergency)

Best for: Critical bugs, security issues, production emergencies
Outcome: Admin approves → You get access (Alice’s reservation released)
Emergency overrides should be rare. They bypass the conflict prevention system. Use only for true emergencies (security issues, production outages, etc.).

Real-World Scenarios

Scenario 1: Parallel Feature Development

Setup:
  • Alice working on OAuth integration
  • Bob working on rate limiting
  • Both features touch auth.ts
Without Hooks:
  • Both edit auth.ts simultaneously
  • Merge conflict when Bob pulls Alice’s changes
  • 15 minutes lost to conflict resolution
  • Risk of broken merge
With Pre-Edit Hooks:
  • Alice edits auth.ts → Auto-reserved (shared mode)
  • Bob tries to edit → Blocked with Alice’s reservation shown
  • Bob messages Alice: “I need to add rate limiting”
  • Alice: “I’m adding OAuth. How about you create middleware/rateLimiter.ts and I’ll call it from auth.ts?”
  • Bob creates separate middleware file
  • Alice finishes OAuth, calls Bob’s middleware
  • Zero conflicts, better architecture

Scenario 2: Major Refactor

Setup:
  • Charlie refactoring entire authentication module
  • Touches 15 files across src/auth/
Without Hooks:
  • Charlie edits files one by one
  • Alice and Bob don’t know about refactor
  • They make changes to auth files
  • Massive merge conflicts when Charlie is done
With Pre-Edit Hooks:
  • Charlie reserves entire src/auth/ directory (exclusive mode)
  • All 15 files locked to Charlie
  • Alice tries to edit auth/login.ts → Blocked
  • Message shown: “Charlie is refactoring the auth module (estimated 3 hours)”
  • Alice and Bob work on other areas
  • Charlie completes refactor, releases reservations
  • Zero conflicts, team aware of major work

Scenario 3: Database Migration

Setup:
  • Alice creating new database migration
  • Bob trying to create another migration simultaneously
Without Hooks:
  • Both create migrations with same timestamp/number
  • Migration system breaks (duplicate versions)
  • Manual intervention required
With Pre-Edit Hooks:
  • Migrations directory configured with exclusive mode
  • Alice creates migration → Directory reserved (exclusive)
  • Bob tries to create migration → Blocked
  • Bob sees: “Alice is creating a migration (estimated 10 minutes)”
  • Bob waits, creates his migration after Alice
  • Migrations created in correct order, no conflicts

Performance & Latency

Hook Execution Time

Pre-edit hook is the fastest hook (~120ms average):
Total: ~120ms
  1. Hook trigger: ~5ms (local)
  2. Check reservations API call: ~60ms (network)
  3. Decision logic: ~5ms (local)
  4. Create reservation (if needed): ~50ms (network)
  5. Return to IDE: ~0ms
Network calls: 1-2 (check reservations, optionally create)

Configuration

Customize Pre-Edit Behavior

~/.ulpi/config.json

Per-Project Overrides

Create .ulpi/config.json in project root:
.ulpi/config.json
Project config overrides global config.

Success Metrics

Teams using pre-edit hooks report:

Zero Merge Conflicts

Down from 12-20 per week to 0 conflicts100% reduction in merge conflict time wasted

3 Hours Saved Weekly

Per developer, per week$15,000 annual savings per developer

Better Architecture

Forced coordination leads to better design decisionsFewer rushed merges, more thoughtful collaboration

Team Awareness

Everyone knows what others are working onReduced duplicate work and conflicts

Best Practices

Recommendation: Start with shared mode for most filesRationale:
  • Allows multiple agents to work on same file (if coordinating)
  • Less restrictive than exclusive
  • Teams coordinate naturally when they see shared reservations
Switch to exclusive only when:
  • Database migrations
  • Complex refactors
  • Critical business logic
Recommendation: Reserve all related files before starting major refactorExample:
Benefit: Prevents others from starting conflicting work
Recommendation: Match expiration to expected work duration
  • Quick fixes: 1 hour
  • Feature work: 2-4 hours
  • Major refactors: 8 hours (full workday)
Avoid: 24+ hour reservations (locks files overnight)
Recommendation: Don’t wait for expiration if you finish early
Benefit: Files available sooner for teammates
Recommendation: When blocked, message the agent with reservationGood message examples:
  • “When will you be done with auth.ts? I have urgent fix.”
  • “Can we split the work? You handle OAuth, I’ll do rate limiting?”
  • “I see you’re refactoring. Need any help?”
Avoid: Radio silence or force overrides

Troubleshooting

Pre-edit hook not blocking conflicts

Symptoms: You can edit files reserved by others Solutions:
  1. Check preEdit.blockConflicts is true in config
  2. Verify Coordination subscription is active
  3. Ensure you’re connected: ulpi coordination status
  4. Check reservation exists: ulpi coordination list-reservations
  5. Enable debug logging: ulpi config set debug=true

Edit blocked but file shows as available

Symptoms: Hook says file is reserved, but list-reservations shows it as available Solutions:
  1. Stale cache - Wait 10 seconds and try again
  2. Reservation expired between check and edit
  3. Other agent released reservation just now
  4. Refresh reservation list: ulpi coordination list-reservations --refresh

Can’t override emergency situation

Symptoms: Override request denied even though it’s critical Solutions:
  1. Check allowOverrides is true in config
  2. If admin approval required, contact admin
  3. Use CLI override with justification: ulpi coordination override src/auth.ts --reason "Production down, SQL injection fix"
  4. As last resort, disable hook temporarily (NOT RECOMMENDED)

Next Steps

Memory Integration

Learn how pre-compact hooks preserve context across sessions

Use Cases

Real-world scenarios where hooks save hours of coordination time

Coordination Product

Explore the full Coordination product powering file reservations

Performance Metrics

Detailed latency analysis and optimization tips