A queue for parallel coding agents

Heavy commands take turns. The machine stays calm.

calmrun is a machine-wide queue for tests, type checks, builds and docker. Put calmrun -- in front of a heavy command and it waits until the machine has room, then runs it at low CPU priority and passes its exit code back. Several coding agents and terminals can share one computer without freezing it.

  • One binary, no daemon
  • Windows, macOS, Linux
  • MIT
calmrun
# macOS / Linux
$ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/vannt-dev/calmrun/releases/latest/download/calmrun-installer.sh | sh
# Windows (PowerShell)
> powershell -ExecutionPolicy Bypass -c "irm https://github.com/vannt-dev/calmrun/releases/latest/download/calmrun-installer.ps1 | iex"

$ calmrun -- npx vitest run
calmrun: waiting — 4 of 6 points in use, 2nd in line (needs 2); running: npx vitest in web (3m10s), cargo build in api (1m02s)

The problem

One test run is fine. Four agents that each start vitest with a worker per core, plus a tsc and a build, are not: they all start in the same minute, and nobody is in charge of the machine.

Everything starts at once

Each agent decides on its own to run the tests, the type check and the build. None of them knows the others are doing the same.

The machine stalls

RAM runs out and the system swaps. The editor, the terminal and the agents themselves stop responding.

Tests time out

Starved runs fail on timeouts that have nothing to do with the code. Agents retry, which adds even more load.

How it works

Every calmrun process adds its job to a small state file guarded by an OS file lock, and every waiter applies the same rules to it. There is no daemon to start or keep alive.

Jobs from agents and terminals wait in one queue; a job starts when its gates are open and runs at low priority. Claude Code Codex · Cursor · Gemini your terminal hook, MCP or calmrun -- The queue --prio high first, then first come vitest run 2 points tsc --noEmit 2 points eslint . 1 point one state file, no daemon Starts when its points are free enough RAM is free the disk has room its folder is not busy a resource slot is free Running at low CPU priority 4 of 6 points in use vitest cargo build memory ceiling watched
The default budget is logical cores − 2, capped at one point per 4 GB of RAM, at least 2. calmrun doctor shows the numbers for your machine.

Points by kind

calmrun reads the command and picks a kind: vitest, jest, type checks and builds cost 2 points, monorepo runners 3, linters, plain test runs and a single compiler call 1. --cost and --kind override it, and your own kinds go in the config.

RAM and disk gates

A job also waits while free RAM is below min_free_gb or its drive has less than min_free_disk_gb free. On an idle machine it starts anyway, so nothing waits forever.

One run per folder

vitest, jest and JavaScript builds take their nearest node_modules, Cargo its target folder, and Gradle, Maven, .NET, CMake, Swift or Flutter builds their project folder. Two jobs on the same folder never run together, so caches and build output don't fight.

Low priority, bounded memory

Commands run below normal priority (nice +10 on Unix), so your editor stays responsive. A job whose process tree goes above ceiling_gb is stopped with exit 137.

No endless commands

Watch modes (vitest watch, tsc -w, gradle -t, dotnet watch, …) and attached docker compose up would hold points forever, so calmrun refuses them and prints the one-shot command to run instead. Dev servers and app runs start at once, outside the queue.

Tickets, resources, queues

--wait-timeout gives up after a while (exit 75) and keeps the place in line for 10 minutes as a ticket. --needs db takes a named resource; --id uses a separate queue.

An order you can steer

calmrun bump puts a waiting job next: while it waits for room, later jobs may not pass it. Pick it by label, --pos, --ticket or --dir; --prio low and bump --back send long jobs to the end of the line.

See and stop a stuck job

calmrun status and the waiting lines show a running job's CPU, idle 5m, its usual time and its last output. Test-like jobs stop after 60 minutes (exit 124, --timeout, max_run_min); calmrun stop <id> ends one now, calmrun logs <id> --follow shows what it prints.

Pause when you need the machine

calmrun pause 30m --reason "video call" stops waiting jobs from starting in every queue; running jobs go on, and the line starts again by itself when the time is up or on calmrun resume. A pause always has an end.

Kinds and default costs

KindPointsDetected from
vitest2vitest
jest2jest
tsc2tsc, vue-tsc, tsgo, npm run typecheck
typecheck2mypy, pyright, deno check, phpstan, psalm
build2vite/next/ng build, webpack, npm run build and the build tools of every ecosystem below; 1 point for one compiler call (gcc, clang, cl)
monorepo3turbo run, nx run-many/affected, pnpm -r, lerna run, rush build, moon run
capture2playwright, puppeteer, cypress
docker2docker compose up/build/run/create, docker build/run/buildx, podman, buildah build, packer build
eslint1eslint, oxlint, biome, npm run lint
lint1ruff, pylint, flake8, go vet, golangci-lint run, rubocop
pytest1pytest, python -m pytest
test1npm test, tox, mocha and the test runners of every ecosystem below
other1anything else

By ecosystem

Key: the folder two jobs never share (the nearest one holding that file). Worker hint: what calmrun passes so a tool that uses every core takes only its share. A flag or variable you set yourself wins, and tools that run one job at a time unless asked (make, ctest, plain Maven) are left alone. A dash means none.

EcosystemToolsKeyWorker hint
JavaScript · TypeScriptvitest, jest, tsc, eslint, vite build, webpack, npm test, deno testnode_modules (vitest, jest, builds)--maxWorkers (vitest), DENO_JOBS
Pythonpytest, mypy, pyright, ruff, tox, noxtox.ini (tox)pytest -n auto, tox -p auto → N
Rustcargo build/check/clippy/test, nextest, maturintargetCARGO_BUILD_JOBS, NEXTEST_TEST_THREADS
Gogo build/test/vet, golangci-lint–-p N, --concurrency N
C · C++make, cmake --build, ctest, ninja, meson, bazel, buck2, scons, xmake, gcc, clang, clMakefile, CMakeCache.txt, build.ninja, MODULE.bazel, …--parallel N, -jN, --jobs=N
JVMgradle, mvn, mvnd, sbt, antsettings.gradle, pom.xml, build.sbt--max-workers=N, -T N (mvnd)
.NETdotnet build/test/publish, msbuild*.sln, *.csproj, …-m:N (dotnet)
Swift · Xcodeswift build/test, xcodebuildPackage.swift, *.xcodeproj-j N, -jobs N
Flutter · Dartflutter build/test, dart test, build_runnerpubspec.yaml--concurrency=N (tests)
Rubyrspec, cucumber, rake test, rails test, parallel_rspec, rubocop–PARALLEL_WORKERS, PARALLEL_TEST_PROCESSORS
PHPphpunit, pest, paratest, composer test, artisan test, phpstan–--processes=N (paratest)
Elixir · Erlangmix test/compile, rebar3mix.exs, rebar.config--max-cases N (mix test)
Haskell · OCaml · Zigstack, cabal, dune, zig buildstack.yaml, cabal.project, dune-project, build.zig-j N
Monorepo runnersturbo, nx, lerna, pnpm -r, rush, moonnode_modulestheir concurrency flag or variable; turbo, nx and pnpm never above their own default
Containersdocker / podman compose, build; buildah, packer––

Agent integration

Agents don't need to remember anything: hooks for Claude Code, Codex, OpenCode and the Pi coding agent (Antigravity: experimental) catch heavy shell commands, the MCP server gives any MCP client a queued run_task tool, and setup writes the instructions and hooks into each agent's global files.

Agent hooks

calmrun hook claude|codex|opencode|pi|antigravity is a PreToolUse hook for the agent's shell tool. When a command runs a heavy tool without calmrun (also through rtk), the hook denies it and tells the agent the exact command with each heavy part wrapped, with a --wait-timeout below the tool's time limit. Light commands pass. calmrun setup --write --hook all installs them; for Claude Code by hand, in ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|PowerShell",
        "hooks": [{ "type": "command", "command": "calmrun hook claude" }]
      }
    ]
  }
}

cd web && npx vitest run becomes cd web && calmrun -- npx vitest run. With CALMRUN_HOOK_MODE=rewrite the hook rewrites the command itself instead of denying it.

MCP server

calmrun mcp serves tools over stdio: run_task (waits in the same queue and runs the command; a job still busy after wait_seconds goes on in the background and returns a task_id), task_status, cancel_task, queue_status and bump. For a device or an emulator without a command: calmrun hold emulator prints a lease, calmrun release <lease> gives it back.

# Claude Code
claude mcp add calmrun -- calmrun mcp

# Codex: ~/.codex/config.toml
[mcp_servers.calmrun]
command = "calmrun"
args = ["mcp"]
tool_timeout_sec = 3600

// Cursor: ~/.cursor/mcp.json
{ "mcpServers": { "calmrun": { "type": "stdio", "command": "calmrun", "args": ["mcp"] } } }

// Gemini CLI: ~/.gemini/settings.json (timeout in ms)
{ "mcpServers": { "calmrun": { "command": "calmrun", "args": ["mcp"], "timeout": 3600000 } } }

calmrun setup

Adds a short calmrun section to the global instruction file of Claude Code, Codex, Gemini CLI, OpenCode and Pi. It is a dry run until you add --write; every file it changes is backed up first.

$ calmrun setup                          # show what would change
$ calmrun setup --write                  # apply
$ calmrun setup --write --agents codex   # only some agents
$ calmrun setup --write --hook           # also the Claude Code hook (--hook all: every agent)
$ calmrun setup --write --remove --hook  # take both out again

calmrun guide

Prints short instructions to paste into an agent's context. Or add this to CLAUDE.md or AGENTS.md by hand:

## Heavy commands

This machine is shared by several agents. Run heavy commands
through the calmrun queue: `calmrun -- <command>` (tests, type
checks, linters, builds, Playwright, docker compose, pytest,
cargo/gradle/make/dotnet/go builds).
Example: `calmrun -- npx vitest run`.
Run anything that may take more than a minute or two in the
background and check on it later.
Use `calmrun status` to see what is running or waiting.
Do not wrap light commands (git, ls, cat, package installs).

Commands

calmrun [flags] -- <cmd> Queue the command, then run it at low priority. Flags: --kind, --cost N, --prio high|low, --label L, --needs db,gpu, --id QUEUE, --wait-timeout SECS, --ticket ID, --timeout SECS, --log. One quoted string runs through the shell.
calmrun statusWhat runs, what waits and why, the budget and free RAM; for a running job its CPU, how long it has been idle, its usual time and its last output. --json for tools.
calmrun statsRuns, failures, wait and run times per label over --days N (default 7).
calmrun bump <label>Move waiting jobs to the front, where later jobs may not pass them while they wait for room; pick them by label, --pos N, --ticket ID or --dir PATH. --back moves them to the end.
calmrun stop <id>Stop a running or waiting job (the id column of status, or --label); a calmrun that does not react is killed.
calmrun logs <id>The output of a job that keeps a log (MCP tasks, runs with --log): --tail N, --follow.
calmrun doctorCores, RAM, disk, battery, where state lives, and the suggested config.
calmrun initWrite a commented config.toml with this machine's defaults (--force overwrites).
calmrun guideShort instructions for coding agents.
calmrun setupWrite or remove the calmrun block in agents' global instruction files: --write, --remove, --hook, --agents.
calmrun hold / releaseHold a resource slot (an emulator, a database) without a command and print a lease (with the instance it holds, if the resource lists instances); release <lease> gives it back, release --ticket <id> gives up a kept place.
calmrun hook <agent>The PreToolUse hook of claude, codex, opencode, pi or antigravity (experimental); reads the hook JSON on stdin.
calmrun mcpThe MCP server on stdio: run_task, task_status, cancel_task, queue_status, bump.

Exit codes

the command's ownit ran (a Unix signal n becomes 128 + n)
2refused (watch mode, attached docker compose up), bad arguments or an invalid --id
75not started within --wait-timeout; the place is kept, run the printed calmrun: next: line
124stopped by its run time limit: --timeout, MCP timeout_s or max_run_min (60 min for test-like kinds)
126 · 127the command could not be started · was not found
130Ctrl+C or calmrun stop
137stopped by the memory ceiling or the critical free-RAM floor

Config and environment

Every setting is optional. calmrun init writes a commented config.toml in the state directory; an environment variable wins over the file.

Key · variableDefault and meaning
budget
CALMRUN_BUDGET
Logical cores − 2, capped at floor(RAM GB / 2.5), at least 2. Points that may run at once.
min_free_gb
CALMRUN_MIN_FREE_GB
max(1.5, RAM / 10). Free RAM a job needs to start while others run (in any queue); 0 turns it off.
min_free_disk_gb
CALMRUN_MIN_FREE_DISK_GB
5. Free space needed on the drive of the job's folder; 0 turns it off.
pass_limit_min
CALMRUN_PASS_MIN
10. Minutes a waiter may be passed by smaller jobs that fit; 0 means strict order.
vitest_workers
CALMRUN_VITEST_WORKERS
1 up to 4 cores, 2 below 12, else 3. The --maxWorkers given to direct vitest calls.
ceiling_gb
CALMRUN_CEILING_GB
Half the RAM. Memory one job's process tree may use; 0 turns it off.
critical_free_gb
CALMRUN_CRITICAL_FREE_GB
5% of RAM, at most 1 GB. Below this for 3 seconds, the biggest job is stopped; 0 turns it off.
[resources]
CALMRUN_RESOURCES
Slots per named resource, e.g. db = 1 or db=1,gpu=2. Unlisted resources have 1 slot. Or instances, one per job: android = ["emulator-5554", "emulator-5556"], or a table with discover (adb devices), health (adb -s {instance} get-state) and env; the job gets its instance in CALMRUN_ANDROID and ANDROID_SERIAL.
[kinds.<name>]cost overrides a kind's points; patterns = ["make"] adds a kind of your own; max_run_min sets its run time limit.
max_run_min
CALMRUN_MAX_RUN_MIN
60 for test, vitest, jest, pytest, typecheck, tsc, lint and eslint; no limit for builds and other kinds. Minutes a job may run before it is stopped (exit 124); 0 turns it off.
log
CALMRUN_LOG
Off. Copy every run's output to a log file (as --log) for calmrun logs; tools then see a pipe, not a terminal, and may drop colours.
CALMRUN_LOW_CPU0 keeps normal priority.
CALMRUN_HOOK_MODErewrite makes the hook wrap commands itself instead of denying them.
CALMRUN_HOME · CALMRUN_CONFIGThe state directory and the config file path.
budget = 6
min_free_gb = 4
ceiling_gb = 8          # 0 = off

[resources]
db = 1
android = ["emulator-5554", "emulator-5556"]  # one each per job

[kinds.heavy]
cost = 2
patterns = ["make", "bazel build"]

Platform notes

Install

One binary, no runtime. The installers put calmrun in ~/.cargo/bin (%USERPROFILE%\.cargo\bin on Windows) and add it to PATH; open a new terminal afterwards.

macOS / Linux

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/vannt-dev/calmrun/releases/latest/download/calmrun-installer.sh | sh

Windows (PowerShell)

powershell -ExecutionPolicy Bypass -c "irm https://github.com/vannt-dev/calmrun/releases/latest/download/calmrun-installer.ps1 | iex"

npm (any OS)

npm install -g calmrun

From source (Rust 1.95 or newer)

cargo install calmrun --locked

Manual download

From Releases: calmrun-x86_64-pc-windows-msvc.zip, calmrun-aarch64-pc-windows-msvc.zip, calmrun-x86_64-apple-darwin.tar.xz, calmrun-aarch64-apple-darwin.tar.xz, calmrun-x86_64-unknown-linux-gnu.tar.xz, calmrun-aarch64-unknown-linux-gnu.tar.xz, each with a .sha256. Unpack and put the binary on PATH.

First steps

$ calmrun doctor                  # what this machine has, the suggested budget
$ calmrun -- npx vitest run       # queue, then run at low priority
$ calmrun "npm ci && npm test"    # one quoted string runs in the shell
$ calmrun status                  # what runs, what waits, and why
$ calmrun setup --write --hook    # teach your agents to use it