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
- Timeline: The Conflict
- The Cost
10:00 AM - Alice (Cursor) starts editing 10:15 AM - Bob (Claude Code) also starts editing 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
auth.tsauth.ts (doesn’t know Alice is working on it)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 Alice successfully edits the file.
0 → Edit proceeds:6
Bob Tries to Edit Same File
15 minutes later, Bob (Claude Code) attempts to edit Pre-edit hook fires again…
auth.ts:7
Detect Conflict
Hook checks reservations:Response:File is already reserved!
8
Block Edit
Hook returns exit code Bob cannot edit the file. Conflict prevented.
2 → Edit blocked: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
- 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
- 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
- First edit of a file → Reservation created automatically
- Subsequent edits → Existing reservation reused (if still valid)
- Reservation expires → New reservation created on next edit
Manual Reservations
You can also reserve files manually before editing:- 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:Releasing Reservations
Reservations are automatically released when:- Session ends (session-end hook)
- Reservation expires (default 2 hours)
- File is committed (optional - configure via
releaseOnCommit)
Conflict Resolution Strategies
When pre-edit hook blocks your edit, you have options:Strategy 1: Coordinate via Messaging
Best for: Normal collaboration, non-urgent editsStrategy 2: Wait for Expiration
Best for: Non-urgent edits, when waiting is acceptableStrategy 3: Edit Different File
Best for: When you can make progress elsewhereStrategy 4: Request Override (Emergency)
Best for: Critical bugs, security issues, production emergenciesReal-World Scenarios
Scenario 1: Parallel Feature Development
Setup:- Alice working on OAuth integration
- Bob working on rate limiting
- Both features touch
auth.ts
- Both edit
auth.tssimultaneously - Merge conflict when Bob pulls Alice’s changes
- 15 minutes lost to conflict resolution
- Risk of broken merge
- 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.tsand I’ll call it fromauth.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/
- 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
- 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
- Both create migrations with same timestamp/number
- Migration system breaks (duplicate versions)
- Manual intervention required
- 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):- Latency Breakdown
- User Experience
- Optimization
Total: ~120ms
- Hook trigger: ~5ms (local)
- Check reservations API call: ~60ms (network)
- Decision logic: ~5ms (local)
- Create reservation (if needed): ~50ms (network)
- Return to IDE: ~0ms
Configuration
Customize Pre-Edit Behavior
~/.ulpi/config.json
Per-Project Overrides
Create.ulpi/config.json in project root:
.ulpi/config.json
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
Use shared mode by default
Use shared mode by default
Reserve files manually for major work
Reserve files manually for major work
Recommendation: Reserve all related files before starting major refactorExample:Benefit: Prevents others from starting conflicting work
Set appropriate expiration times
Set appropriate expiration times
Recommendation: Match expiration to expected work duration
- Quick fixes: 1 hour
- Feature work: 2-4 hours
- Major refactors: 8 hours (full workday)
Release reservations when done
Release reservations when done
Recommendation: Don’t wait for expiration if you finish earlyBenefit: Files available sooner for teammates
Communicate in messages
Communicate in messages
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?”
Troubleshooting
Pre-edit hook not blocking conflicts
Symptoms: You can edit files reserved by others Solutions:- Check
preEdit.blockConflictsistruein config - Verify Coordination subscription is active
- Ensure you’re connected:
ulpi coordination status - Check reservation exists:
ulpi coordination list-reservations - Enable debug logging:
ulpi config set debug=true
Edit blocked but file shows as available
Symptoms: Hook says file is reserved, butlist-reservations shows it as available
Solutions:
- Stale cache - Wait 10 seconds and try again
- Reservation expired between check and edit
- Other agent released reservation just now
- Refresh reservation list:
ulpi coordination list-reservations --refresh
Can’t override emergency situation
Symptoms: Override request denied even though it’s critical Solutions:- Check
allowOverridesistruein config - If admin approval required, contact admin
- Use CLI override with justification:
ulpi coordination override src/auth.ts --reason "Production down, SQL injection fix" - 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