Tool

Serialize parallel Claude Code agent merges with local queue

Local, zero-cost merge queue for parallel Claude Code agents: numbered worktree lanes, a FIFO landing queue, build lock and a pre-push guard.

Works with githubclaudegitnpm

91
Spark score
out of 100
Updated 2 months ago
Source checked Oct 14, 2026
Version 0.7.1
Models
claude

Add to Favorites

Why it matters

Prevent race conditions, redundant builds, and test flakiness when multiple Claude Code agents work in parallel by serializing their merge operations through a local, zero-cost FIFO queue that ensures only one agent lands changes at a time.

Outcomes

What it gets done

01

Queue and serialize git push operations across parallel agent worktrees to prevent merge conflicts

02

Run build commands with machine-wide locks so heavy builds never duplicate across lanes

03

Enforce pre-push checks and rebase validation before any code lands on integration branches

04

Manage numbered lane worktrees with automatic port assignment and preview capabilities

Source

Get it from source

Spark does not host a copy of it.

Open source

Reports

Agent outcome reports

No reports yet

Overview

Claude Code Merge Queue is a local, zero-cost merge queue for parallel Claude Code agents. Several agents land, build and test at the same time, and this serializes those steps so push races, redundant heavy builds and shared-resource test flakiness cannot happen. It runs on your own machine. Use it when you run several Claude Code agents in parallel on one machine. It is not a review process: checkCommand is the only gate, and it is not a security boundary.

What it does

Several agents land, build and test at the same time, and this serializes those steps so push races, redundant heavy builds and shared-resource test flakiness cannot happen. Each agent works in its own numbered lane. Claude Code handles worktree isolation itself (native --worktree or isolation: "worktree"), and a WorktreeCreate hook plugs the numbered lanes into that native worktree creation. Lane branches go by lane/1, lane/2 and so on, worktree directories sit next to your repo, at ../your-repo-lane-1, and lane n gets the dev-server port portBase + n, with a default of 3000.

The commands are:

  • hook worktree-create, the WorktreeCreate hook.
  • build-lock, given -- and your build command, which runs that build serialized across every lane, machine-wide.
  • land, which rebases and pushes your lane onto the integration branch through a FIFO queue, so two lanes are never mid-push at once. Agents run this themselves.
  • sync, which fast-forwards your main checkout so a dev server sees what just landed, and re-installs dependencies if the lockfile changed.
  • promote, which ships the integration branch to production. It is human-only: never in an agent's instructions, never automated.
  • preview, which instantly mirrors a lane's live working tree, uncommitted changes included, onto the main checkout without a build.
  • port, which prints a lane's dev-server port, derived from its own directory name.
  • prune, which removes already-landed lane worktrees on demand.

A pre-push hook makes land non-optional: a direct git push to the integration branch is rejected with the actual command to run instead, and the same hook runs checkCommand before allowing a landing through. With no checkCommand configured, every push fails by default.

When to use - and when NOT to

It is a local alternative to GitHub's merge queue, which needs Enterprise Cloud for private repos, costs GitHub Actions minutes on every queue attempt and requires a pull request. This works on any plan and any repo, costs $0 because it runs on your own machine, and needs no pull request: it does a direct rebase and push.

Know the limits:

  • No human reviews any of this before it lands. checkCommand passing is the only gate, and a real test suite and echo ok look identical to the tool.
  • Locks are crash-safe by PID liveness, not a timeout: after a kill -9 mid-claim, the next process notices the PID is dead and reclaims the lock.
  • It covers one machine, not a fleet. The FIFO queue lives in local temp storage, and two machines landing at once just get git's ordinary non-fast-forward rejection.
  • It is not a security boundary. Every guardrail stops mistakes and convention drift, not an adversarial agent; shell access always means git push --no-verify or editing the config on purpose.
  • A slow checkCommand is a real throughput ceiling. The FIFO lock holds for its entire duration; a 3-4 minute suite caps you well under 20 landings per hour.
  • Rebase conflicts abort and never guess: git rebase --abort runs on any conflict, the working tree is left clean, and CLAUDE.md tells the agent to resolve it and re-run land.

Inputs and outputs

Everything lives in one config file, claude-code-merge-queue.config.mjs at the repo root. A malformed config (empty branch names, a negative port, productionBranch equal to integrationBranch) fails loud with every problem listed, the moment any command loads it. The fields:

  • branchPrefix (lane/), worktreeSuffix (-lane-) and portBase (3000).
  • integrationBranch (main): where agents land, continuously and autonomously.
  • productionBranch (null): set it for a two-stage model where agents land on the integration branch and a human ships to production with promote. Null means the integration branch is production. When set, the pre-push hook protects it automatically.
  • protectedBranches (empty): extra branches the pre-push hook refuses a direct push to. Most repos need none.
  • regenerableFiles (empty): files a build tool rewrites that should never block a rebase or fast-forward. Next.js projects typically want next-env.d.ts here at minimum.
  • disposableUntracked (empty): untracked session litter, such as a scratchpad, that is safe to git clean when reclaiming an abandoned lane whose branch already landed. Nothing untracked is deleted until you name it; anything unlisted still blocks pruning and is surfaced as real uncommitted work. Without it, one stray untracked file pins an otherwise landed lane on disk forever, because git worktree remove refuses on any untracked file.
  • symlinks (.env, .env.local, node_modules): git-ignored paths symlinked into every new lane, so it needs no fresh install and no copy of your secrets.
  • buildOutputDirs (dist, build, .next): directories preview never copies onto your checkout. Preview is an rsync, not a build step, so add .output for Nuxt, .svelte-kit for SvelteKit and similar.
  • checkCommand (npm run check): the command that gates a landing. init detects it from package.json (check:push, check, ci or test, in that order). Null means nothing runs, which is only allowed if checksRequired is also false.
  • checksRequired (true): a null checkCommand fails every push rather than landing unverified code. Set it to false yourself to deliberately run with no checks, a visible, committed choice.

Every blocked push, whether to the integration branch, productionBranch or anything in protectedBranches, has a way through: one environment variable, no prompts, no second factor. It takes naming the specific branch, not a generic flag: CLAUDE_CODE_MERGE_QUEUE_EMERGENCY_PUSH=1 git push origin HEAD:main. This is a convention, not a hard guarantee: it stops mistakes and stray pushes, not an adversarial agent that sets the variable itself.

init writes the config with integrationBranch and checkCommand auto-detected; a CLAUDE.md (or appends to yours) telling Claude Code to land its own work once green, without being asked; .claude/settings.json with the WorktreeCreate hook wired in without touching anything else there; .husky/pre-push, created or appended to if you already have Husky (if you don't, init tells you rather than silently writing to the untracked .git/hooks/pre-push); package.json scripts land, sync, promote, preview and preview:restore, skipping any you have already defined; and claude-code-merge-queue-preflight.mjs, a self-contained safety net that runs before land and sync, so a stale branch fails with a real diagnosis instead of a bare command not found.

Integrations

Install it as a dev dependency with npm, pnpm, yarn or bun, then run init:

npm install --save-dev claude-code-merge-queue   # or: pnpm add -D / yarn add -D / bun add -d
npx claude-code-merge-queue init

It integrates with Claude Code through the worktree hook and CLAUDE.md, with Husky through the pre-push hook, and with your own lint, typecheck, test and build scripts through checkCommand. MIT licensed.

Source README
Claude Code Merge Queue — the local, zero-cost merge queue for parallel Claude Code agents

npm versionnpm downloadsCILicense: MITTypeScriptNodeRuntime deps

Claude Code Merge Queue 🚦

The local, zero-cost merge queue for parallel Claude Code agents. Several agents land, build, and test at the same time - this serializes it so push races, redundant heavy builds, and shared-resource test flakiness can't happen.

⚡ Quickstart

npm install --save-dev claude-code-merge-queue   # or: pnpm add -D / yarn add -D / bun add -d
npx claude-code-merge-queue init

Contents

Terminal demo: npm install --save-dev claude-code-merge-queue, then npx claude-code-merge-queue init — writes the config, CLAUDE.md, the WorktreeCreate hook, and land/sync/promote/preview scripts

⚙️ Configuration

Everything lives in one file - see examples/claude-code-merge-queue.config.mjs for every field with comments. The short version:

export default {
  branchPrefix: "lane/",               // lane/1, lane/2, ...
  worktreeSuffix: "-lane-",            // ../your-repo-lane-1
  portBase: 3000,                      // lane n gets portBase + n
  integrationBranch: "main",           // where agents land — see below
  productionBranch: null,              // set this for a two-stage model — see below
  protectedBranches: [],               // extra branches beyond the two above; most repos need none
  regenerableFiles: [],                // files a build tool rewrites — never block a rebase on these
  symlinks: [".env", ".env.local", "node_modules"],
  buildOutputDirs: ["dist", "build", ".next"], // preview never copies these onto your checkout
  checkCommand: "npm run check",       // what actually gates a landing — see below
  checksRequired: true,                // false = deliberately run with none; see below
};

A malformed config (empty branch names, a negative port, productionBranch equal to integrationBranch, ...) fails loud with every problem listed, the moment any command loads it - not a mysterious failure three steps later.

🆚 vs. GitHub's Merge Queue

GitHub Merge Queue Claude Code Merge Queue
Private repo Enterprise Cloud only Any plan, any repo
Cost per landing GitHub Actions minutes, every queue attempt $0 - runs on your own machine
Requires A pull request Nothing - direct rebase + push

Same idea - serialize landings, test before merge, keep history clean - run locally instead of in someone else's billed cloud.

🧰 What's in the box

Command What it does
claude-code-merge-queue hook worktree-create A Claude Code WorktreeCreate hook. Plugs Claude Code Merge Queue's numbered lanes into Claude's native worktree creation.
claude-code-merge-queue build-lock -- <cmd> Runs <cmd> - your build - serialized across every lane, machine-wide.
claude-code-merge-queue land Rebases and pushes your lane onto the integration branch through a FIFO queue, so two lanes are never mid-push at once. Agents run this themselves.
claude-code-merge-queue sync Fast-forwards your main checkout so a dev server actually sees what just landed - and re-installs dependencies if the lockfile changed.
claude-code-merge-queue promote Ships the integration branch to production. Human-only - never in an agent's instructions, never automated.
claude-code-merge-queue preview Instantly mirrors a lane's live working tree - uncommitted changes included - onto the main checkout, so you can look at it without a build.
claude-code-merge-queue port Prints a lane's dev-server port, derived from its own directory name.
claude-code-merge-queue prune Removes already-landed sibling lane worktrees on demand.

A pre-push hook makes land non-optional: a direct git push straight to the integration branch is rejected, with the actual command to run instead, and the same hook runs checkCommand before allowing a landing through - no checkCommand configured means every push fails by default. There's a way out for every block (see 🚨 The emergency hatch), but it takes naming the specific branch, not a generic flag.

📝 What init writes
  • claude-code-merge-queue.config.mjs - integrationBranch and checkCommand auto-detected.
  • CLAUDE.md (or appends to yours) - tells Claude Code to land its own work once green, without being asked.
  • .claude/settings.json - the WorktreeCreate hook wired in, without touching anything else already there.
  • .husky/pre-push - created or appended to, if you already have Husky. If you don't, init tells you rather than silently writing to the untracked .git/hooks/pre-push.
  • package.json scripts - land, sync, promote, preview, preview:restore, skipping any you've already defined yourself.
  • claude-code-merge-queue-preflight.mjs - a self-contained safety net that runs before land/sync, so a stale branch fails with a real diagnosis instead of a bare command not found.

🚨 The emergency hatch

Every blocked push - the integration branch, productionBranch, anything in protectedBranches - has a real way through it. One env var, no prompts, no second factor to remember:

CLAUDE_CODE_MERGE_QUEUE_EMERGENCY_PUSH=1 git push origin HEAD:main

This is a convention, not a hard guarantee: it stops mistakes and stray pushes, not an adversarial agent that sets the var itself.

🔍 Know the limits

  • No human reviews any of this before it lands. checkCommand passing is the only gate - a real test suite and echo ok look identical to this tool. Want a human on every change? This is missing that step on purpose.
  • Locks are crash-safe by PID liveness, not a timeout. kill -9 anything mid-claim and the next process notices the PID is dead and reclaims it - no stale locks, no timeout to tune.
  • One machine, not a fleet. The FIFO queue lives in local temp storage - two machines landing at once just get git's ordinary non-fast-forward rejection.
  • Not a security boundary. Every guardrail here stops mistakes and convention drift, not an adversarial agent - shell access always means git push --no-verify or editing the config on purpose.
  • A slow checkCommand is a real throughput ceiling. The FIFO lock holds for its entire duration - a 3-4 minute suite caps you well under 20 landings/hour.
  • Rebase conflicts abort, they never guess. git rebase --abort on any conflict, working tree left clean - CLAUDE.md tells the agent to resolve it and re-run land.

📄 License

MIT. Fork it, rename it, argue with the config shape - that's the point.

examples/claude-code-merge-queue.config.mjs

// claude-code-merge-queue.config.mjs — lives at your repo root. `claude-code-merge-queue init` writes a
// copy of this for you; edit the values below for your project.
//
// Worktree isolation is Claude Code's job (native `--worktree` /
// `isolation: "worktree"`) — this file is what the WorktreeCreate hook
// (see hooks/claude-settings.example.json) reads to name and shape the lane
// it creates, and what everything downstream (build queue, landing queue,
// preview) reads too.

/** @type {import("claude-code-merge-queue").ClaudeCodeMergeQueueConfig} */
export default {
  // Lane branches: lane/1, lane/2, ...
  branchPrefix: "lane/",

  // Sibling worktree dirs: ../<your-repo>-lane-1, -lane-2, ...
  worktreeSuffix: "-lane-",

  // Lane 1 gets this port, lane 2 gets portBase + 2, and so on — handy if
  // each lane also runs its own throwaway dev server.
  portBase: 3000,

  // The branch `claude-code-merge-queue land` rebases onto and pushes to. Agents land
  // here continuously and autonomously — see the CLAUDE.md workflow section
  // `claude-code-merge-queue init` writes.
  integrationBranch: "main",

  // Set this if you run a two-stage model: agents land on integrationBranch,
  // a human ships to productionBranch on their own schedule with
  // `claude-code-merge-queue promote`. null (the default) means integrationBranch IS
  // production — no separate promotion step. Example: integrationBranch
  // "dev", productionBranch "main". Automatically protected by the pre-push
  // hook when set — you don't need to also list it below.
  productionBranch: null,

  // Extra branches the pre-push hook refuses a *direct* push to, beyond
  // integrationBranch and productionBranch. Most repos need nothing here.
  protectedBranches: [],

  // Files your build tool rewrites on its own that should never block a
  // rebase or a fast-forward. Next.js projects typically want
  // ["next-env.d.ts"] here at minimum — add to this list the first time a
  // regenerated file blocks a landing, and never think about it again.
  regenerableFiles: [],

  // UNTRACKED session litter (a scratchpad of run logs, a temp dir) that's
  // safe to `git clean` when reclaiming a lane whose branch already landed and
  // that no live session is in. Without this, one stray untracked file pins an
  // otherwise fully-landed, abandoned lane on disk forever (git worktree remove
  // refuses on ANY untracked file). Empty by default — nothing untracked is
  // ever deleted until you name it here; anything unlisted still blocks pruning
  // and is surfaced as real uncommitted work. e.g. ["scratchpad/"].
  disposableUntracked: [],

  // Git-ignored paths symlinked into every new lane so it needs no fresh
  // install and no copy of your secrets.
  symlinks: [".env", ".env.local", "node_modules"],

  // Build-output dirs `claude-code-merge-queue preview` never copies onto your dev
  // checkout. preview is framework-agnostic (it's an rsync, not a build
  // step) — this is the one place your framework's name shows up. Add
  // ".output" for Nuxt, ".svelte-kit" for SvelteKit, etc.
  buildOutputDirs: ["dist", "build", ".next"],

  // The command that actually gates a landing — your lint/typecheck/test/
  // build. `claude-code-merge-queue init` tries to detect this from package.json
  // (check:push, check, ci, or test, in that order) and fills it in for
  // you. null means nothing runs, which is only allowed if checksRequired
  // is also false — see below.
  checkCommand: "npm run check",

  // true (the default): a null checkCommand FAILS every push rather than
  // landing unverified code. Set to false yourself to deliberately run
  // with no checks — a real state for a repo with nothing to test yet, but
  // one that should be a visible, committed choice, not a silent default.
  checksRequired: true,
};

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.