Stop AI agents from destroying each other's work.
Quick Start Β· How It Works Β· MCP Config Β· CLI Usage Β· Contributing
You're running multiple AI agents on the same codebase. Maybe Claude Code is refactoring your auth module while Aider is updating your API routes. Everything seems fine until:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β π€ Agent A (Claude Code) π€ Agent B (Aider) β
β βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β Reading auth.ts... β β Reading auth.ts... β β
β β Planning refactor β β Planning new routes β β
β ββββββββββ¬βββββββββββββ ββββββββββ¬βββββββββββββ β
β β β β
β βΌ βΌ β
β βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β Writing auth.ts... β β Writing auth.ts... β β
β β β
Refactor done! β β β
Routes added! β β
β ββββββββββ¬βββββββββββββ ββββββββββ¬βββββββββββββ β
β β β β
β βββββββββββββ βββββββββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββ β
β β π auth.ts β β
β β CORRUPTED β β
β β Build: FAIL β β
β ββββββββββββββββ β
β β
β Agent A's refactor is GONE. Agent B overwrote it. β
β Neither agent knows the other existed. β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
This is "Agentic Collision" β and it's the #1 reason multi-agent workflows fail silently.
- π Silent overwrites β Agent B nukes Agent A's changes with zero warning
- π§ Context loss β Each agent hallucinates that it's the only one working
- π Infinite loops β Agents "fix" each other's changes back and forth forever
- π Broken builds β The repo ends up in a state no single agent intended
AGNT-LOCK is a lightweight coordination layer that sits between your AI agents and your repository. It uses the Model Context Protocol (MCP) to give every agent awareness of what other agents are doing.
graph TB
subgraph Agents
A[π€ Claude Code]
B[π€ Roo Code]
C[π€ Aider]
D[π€ Cursor]
end
subgraph AGNT-LOCK
MCP[π MCP Server]
SM[π State Manager]
IL[π Intent Log]
end
subgraph Repository
F1[π auth.ts]
F2[π routes.ts]
F3[π config.ts]
end
A -->|acquire_lock| MCP
B -->|acquire_lock| MCP
C -->|get_repo_state| MCP
D -->|release_lock| MCP
MCP --> SM
SM --> IL
SM -->|β
Grant / π Block| Agents
SM -.->|tracks| Repository
- Before editing, an agent calls
acquire_lock(filepath, agent_name, intent) - If the file is free β lock is granted, intent is logged
- If the file is locked by another agent β request is blocked with details about who holds it and why
- After editing, the agent calls
release_lock(filepath)to free the file - Any agent can call
get_repo_state()to see the full coordination map
# Clone the repository
git clone https://github.com/codewithriza/AGNT-LOCK.git
cd AGNT-LOCK
# Install dependencies
npm install
# Build
npm run build# Start the MCP server (stdio transport)
node dist/index.jsnpm install -g .
agnt-lock statusAdd to your claude_desktop_config.json:
{
"mcpServers": {
"agnt-lock": {
"command": "node",
"args": ["/absolute/path/to/AGNT-LOCK/dist/index.js"],
"env": {}
}
}
}Add to your .cursor/mcp.json:
{
"mcpServers": {
"agnt-lock": {
"command": "node",
"args": ["/absolute/path/to/AGNT-LOCK/dist/index.js"]
}
}
}Add to your MCP settings in Roo Code:
{
"mcpServers": {
"agnt-lock": {
"command": "node",
"args": ["/absolute/path/to/AGNT-LOCK/dist/index.js"],
"disabled": false,
"alwaysAllow": ["acquire_lock", "release_lock", "get_repo_state"]
}
}
}π‘ Tip: Replace
/absolute/path/to/AGNT-LOCKwith the actual path where you cloned the repo.
AGNT-LOCK exposes 4 tools via the Model Context Protocol:
| Tool | Description |
|---|---|
acquire_lock |
Lock a file before editing. Blocks if already locked by another agent. |
release_lock |
Release a file lock after editing. Commits intent to session history. |
get_repo_state |
Get the full coordination map: active locks, agents, recent activity. |
force_release_all |
Emergency reset: force-release all locks in the repository. |
// Parameters
{
filepath: "src/auth.ts", // File to lock
agent_name: "claude-code", // Who's locking it
intent: "Refactoring auth middleware to use JWT" // Why
}
// Response (success)
{
"success": true,
"message": "β
Lock acquired on \"src/auth.ts\" by \"claude-code\".",
"lock": {
"filepath": "src/auth.ts",
"agent_name": "claude-code",
"intent": "Refactoring auth middleware to use JWT",
"acquired_at": "2026-03-15T10:30:00.000Z",
"expires_at": "2026-03-15T10:45:00.000Z"
}
}
// Response (blocked)
{
"success": false,
"message": "π BLOCKED: File \"src/auth.ts\" is locked by agent \"aider\"...",
"blocked_by": { ... }
}π AGNT-LOCK Repository State
ββββββββββββββββββββββββββββββ
Session: session_20260315_a3f8k2
Active Locks: 2
Active Agents: claude-code, aider
π Locked Files:
β’ src/auth.ts β claude-code (intent: "Refactoring auth middleware")
β’ src/routes.ts β aider (intent: "Adding new API endpoints")
π Recent Activity:
π claude-code β acquire "src/auth.ts"
π aider β acquire "src/routes.ts"
π roo-code β release "src/config.ts"
AGNT-LOCK also includes a CLI for manual coordination and debugging:
# Check repository coordination state
agnt-lock status
# Manually lock a file
agnt-lock lock src/index.ts my-agent "Updating the main entry point"
# Release a lock
agnt-lock unlock src/index.ts my-agent
# Emergency: release all locks
agnt-lock reset
# Start MCP server from CLI
agnt-lock serveAGNT-LOCK/
βββ src/
β βββ index.ts # MCP server entry point (stdio transport)
β βββ server.ts # MCP tool definitions (acquire, release, state)
β βββ state-manager.ts # Core .agentlock state engine
β βββ cli.ts # Color-coded CLI dashboard
βββ tests/
β βββ state-manager.test.ts # Vitest unit tests (9 tests)
βββ website/ # Next.js + Tailwind landing page
β βββ app/
β β βββ page.tsx # Dark-mode landing page
β β βββ layout.tsx # Root layout with metadata
β β βββ globals.css # Tailwind + custom styles
β βββ package.json
βββ dist/ # Compiled JavaScript (after build)
βββ .agentlock/ # Runtime state directory (auto-created, gitignored)
β βββ state.json # Current locks & intent log
βββ vitest.config.ts # Test configuration
βββ package.json
βββ tsconfig.json
βββ LICENSE # MIT
βββ README.md
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β .agentlock/state.json β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β active_locks: { β
β "src/auth.ts": { β
β agent_name: "claude-code", β
β intent: "Refactoring auth middleware", β
β acquired_at: "2026-03-15T10:30:00Z", β
β expires_at: "2026-03-15T10:45:00Z" β Auto-expiry β
β } β
β } β
β β
β intent_log: [ β
β { agent: "roo-code", action: "acquire", file: "..." }, β
β { agent: "roo-code", action: "release", file: "..." }, β
β { agent: "claude-code", action: "acquire", file: "..." } β
β ] β Rolling log (max 500 entries) β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- File-level locking β Granular enough to allow parallel work, broad enough to prevent conflicts
- 15-minute TTL β Locks auto-expire to prevent deadlocks from crashed agents
- Intent logging β Every lock/unlock is logged with why the agent needed the file
- Zero external dependencies β State is a single JSON file, no database required
- Ownership verification β Only the locking agent (or force-release) can unlock a file
Contributions are welcome! Here's how to get started:
# Fork and clone
git clone https://github.com/YOUR_USERNAME/AGNT-LOCK.git
cd AGNT-LOCK
# Install dependencies
npm install
# Build
npm run build
# Test the CLI
node dist/cli.js status- π HTTP/SSE transport (for remote agent coordination)
- π Web dashboard for visualizing lock state
- π Webhook notifications when locks are contested
- π§ͺ Test suite
- π¦ npm package publishing
- π³ Docker container