Skip to content

codewithriza/AGNT-LOCK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” AGNT-LOCK

The Context Traffic Controller for Multi-Agent Repositories

Stop AI agents from destroying each other's work.

MIT License Build MCP Compatible Node.js TypeScript

Quick Start Β· How It Works Β· MCP Config Β· CLI Usage Β· Contributing


πŸ’₯ The Problem: Agentic Collision

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.

What goes wrong:

  • πŸ”„ 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

βœ… The Solution: AGNT-LOCK

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
Loading

How it works:

  1. Before editing, an agent calls acquire_lock(filepath, agent_name, intent)
  2. If the file is free β†’ lock is granted, intent is logged
  3. If the file is locked by another agent β†’ request is blocked with details about who holds it and why
  4. After editing, the agent calls release_lock(filepath) to free the file
  5. Any agent can call get_repo_state() to see the full coordination map

πŸš€ Quick Start

Install

# Clone the repository
git clone https://github.com/codewithriza/AGNT-LOCK.git
cd AGNT-LOCK

# Install dependencies
npm install

# Build
npm run build

Run as MCP Server

# Start the MCP server (stdio transport)
node dist/index.js

Install globally (CLI)

npm install -g .
agnt-lock status

βš™οΈ MCP Configuration

For Claude Desktop / Claude Code

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "agnt-lock": {
      "command": "node",
      "args": ["/absolute/path/to/AGNT-LOCK/dist/index.js"],
      "env": {}
    }
  }
}

For Cursor

Add to your .cursor/mcp.json:

{
  "mcpServers": {
    "agnt-lock": {
      "command": "node",
      "args": ["/absolute/path/to/AGNT-LOCK/dist/index.js"]
    }
  }
}

For Roo Code (VS Code)

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-LOCK with the actual path where you cloned the repo.


πŸ› οΈ MCP Tools

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.

acquire_lock

// 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": { ... }
}

get_repo_state

πŸ“Š 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"

πŸ’» CLI Usage

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 serve

πŸ“ Project Structure

AGNT-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

πŸ”’ How the Lock System Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    .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)  β”‚
β”‚                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Design Decisions:

  • 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

🀝 Contributing

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

Ideas for contributions:

  • 🌐 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

About

Stop AI agents from overwriting each other MCP based file locking for multi-agent repos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors