mergetrain
Parallel agents need a serial integration spine.
mergetrain is a local-first deploy train for coding-agent worktrees. Agents commit and enqueue their branches; one runner assembles them in order, tests the combined tree, and atomically updates your Git refs only after explicit approval. It is intentionally optimized as an owner-operated local utility, not a hosted team platform.
The problem
Worktrees let several agents edit one repository without sharing a checkout. They do not decide landing order, test the combined result, prevent push races, or tell you what happened if a laptop dies mid-push.
Without an integration boundary, the human becomes that boundary: rebase every finished branch, rerun gates after each merge, resolve cross-branch failures, and decide which session may push. The parallel coding gain disappears at the last mile.
mergetrain makes that last mile a durable protocol:
agent branches → FIFO queue → isolated integration worktree → combined gates
→ explicit approval → one atomic push → post-push verification
Who should use it?
Use mergetrain when:
- multiple coding agents finish branches in the same repository throughout the day;
- agents work in Git worktrees and should enqueue rather than push deploy refs;
- the combined result must pass local tests before it lands;
- you want unattended processing only for explicitly pre-approved jobs; or
- one local hub should show queues and runners across several repositories.
It is harness-agnostic: Codex, Claude Code, scripts, and humans all use the same CLI and JSON contract.
Who should not use it?
You probably do not need mergetrain when:
- one person or agent lands one branch at a time;
- every change already goes through a PR and your forge-native merge queue;
- you need a hosted review UI, organization-wide permission system, or remote runner service; or
- you are looking for a general job queue, CI provider, or deployment platform.
For PR-first teams, use GitHub Merge Queue or GitLab Merge Trains. mergetrain is for local-agent, worktree-first integration, with or before a PR.
Enforcement boundary
Lease tokens fence concurrent and stale mergetrain runners. They do not
intercept an arbitrary git push from a task agent that has shell access and an
integration-branch credential. To make “one runner owns the push” an enforced
property rather than a protocol assumption, use this topology:
task agents: commit + exact-SHA enqueue; no integration push credential
runner: separate deploy identity
remote: protected integration branch; runner or reviewed PR path only
Without credential separation and remote protection, mergetrain still provides safe train assembly and recovery semantics, but it cannot prevent a participant from bypassing the queue. See the security boundary.
See it in 60 seconds
uvx mergetrain demo
The demo creates a disposable repository and local bare remote, then runs four
real branches through FIFO merge, a combined-only gate failure, conflict
attribution, and deployment of the compatible train. Use --keep to inspect the
result afterward.
Install and first run
# Install the machine-level CLI
uv tool install mergetrain # or: pipx install mergetrain
# macOS: brew install yongjip/tap/mergetrain
cd /path/to/your/repo
# Write .mergetrain.yaml plus agent instructions
mergetrain init --project my-app --write
# After an agent commits its task branch
mergetrain enqueue \
--task "add health check" \
--branch agent/health
# Inspect first, then validate or deploy explicitly
mergetrain status --json
mergetrain run-batch --validate-only
mergetrain run-batch --deploy
deploy names the configured atomic Git ref update; it does not imply an App
Store, Kubernetes, or other provider release.
mergetrain init also writes agent-facing instructions. The essential rule is
simple: agents commit and enqueue; one runner owns merge → test → push → verify.
Unattended daemons process only jobs that a human explicitly enqueued with
--auto. For manual jobs, daemon --validate-only can run merge and gates in
the background, but it pauses at the validated-train approval boundary and
never pushes.
See the quickstart for configuration, dashboard, daemon, and multi-repository Hub setup.
Why not just worktrees and git merge?
Worktrees solve parallel editing. mergetrain solves serialized integration.
| Integration concern | Worktrees + manual merge | mergetrain |
|---|---|---|
| Landing order | A person or agent decides repeatedly | Durable FIFO queue |
| Combined validation | Rerun manually after each merge | Gates run over the exact assembled train |
| Cross-branch failure | Diagnose by hand | Isolation runs identify the conflicting pair |
| Push ownership | Every session can race the ref | One lease-fenced runner owns the push |
| Approval | Shell convention | Explicit validate/deploy intent; --auto is opt-in |
| Crash recovery | Infer from local logs | Reconcile SQLite evidence against remote refs |
Plain worktrees remain the execution lanes. mergetrain is the spine that joins their results without turning the operator into a merge coordinator.
Why not GitHub or GitLab merge queues?
They solve a related problem for a different operating model.
| Forge-native queue | mergetrain | |
|---|---|---|
| Primary unit | Pull/merge request | Committed local task branch |
| Validation | Forge merge group + remote CI | Local assembled train + shell gates |
| Review | Built-in conversation and approvals | No code-review UI |
| Infrastructure | Forge integration and hosted services | Local SQLite, Git worktrees, any Git remote |
| Best fit | PR-first teams and distributed review | High-throughput local agent integration |
The models can coexist: push a validated train to a review branch and open one PR, or reserve individual PRs for changes that need discussion. The PR workflow guide covers direct, one-PR, split-PR, and validation-only patterns.
Core safety guarantees
- Exact train identity. Approval names the task HEADs and integration base; changed branches or a moved base cannot silently reuse that approval.
- Combined gates before push. A green branch is not enough. The assembled train passes the configured gates, or nothing lands.
- One fenced mergetrain owner. SQLite claims and lease tokens prevent concurrent or stale mergetrain runners from mutating the same train; remote enforcement additionally requires the credential topology above.
- Atomic remote update. Payload refs and a permanent
refs/mergetrain/deploys/<sha>recovery ref update together. - Remote-truth recovery. Write-ahead markers and pinned commits let
reconcile/recoverdetermine whether a killed push landed, without replaying a successful deploy or calling a missing one shipped. - Explicit automation. A bare run never deploys. Daemons touch only
pre-approved
--autojobs whose destination and gate/reuse/verify policy still match, and MCP deploy still requires attributable human confirmation. - Observable state.
doctor,status, inspection, events, and statistics expose structured state and the next safe action instead of asking an agent to infer it from processes or prose.
Queue state, locking, train assembly, and gates stay local. Your configured Git remote and post-push verification may still use external services. Gate and verify commands are trusted code; review the security boundary before enabling unattended jobs.
These guarantees are exercised on macOS and Linux across Python 3.10–3.14 and
on Windows, including real-Git fault injection around git push --atomic. A
dedicated soak repository completed 20 landed trains at a 100% land rate,
including planned conflict recovery and a real killed-push reconciliation whose
verdict matched the remote. See the
soak evidence,
then use mergetrain stats --json to inspect evidence from your own queue.
Go deeper
- Start: Quickstart · Install · CLI · Config
- Understand: Design and architecture · Machine contract · PR workflow comparison
- Operate: Efficient operation · Failure modes and recovery · Daemon · Multi-repo Hub
- Trust and extend: Security · Agent contract · Agent adoption benchmark · Local multi-agent benchmark · MCP server · Adapter pattern · Product scope
Status
The latest published release is shown by the PyPI badge above. Machine-contract major 2 is additive-only: existing JSON keys are not removed or renamed without another contract-version change. Issues and operating reports are welcome on GitHub.
License
Released under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mergetrain-2.4.2.tar.gz.
File metadata
- Download URL: mergetrain-2.4.2.tar.gz
- Upload date:
- Size: 14.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21f758ab8d1813f44d9c90bf054389c73644b906f7f0e88cadde2ccbcb469a29
|
|
| MD5 |
a39ffbf7f04a88e5fc0e2bda51b1bb54
|
|
| BLAKE2b-256 |
cb894028181ca098aa19c3919accd831ea6a80c65a3daef05f7a84b2bcc3d1c9
|
Provenance
The following attestation bundles were made for mergetrain-2.4.2.tar.gz:
Publisher:
release.yml on yongjip/mergetrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mergetrain-2.4.2.tar.gz -
Subject digest:
21f758ab8d1813f44d9c90bf054389c73644b906f7f0e88cadde2ccbcb469a29 - Sigstore transparency entry: 2687113885
- Sigstore integration time:
-
Permalink:
yongjip/mergetrain@8db0585d3b0e6a148c93e30ff4aa55213d736eab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yongjip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8db0585d3b0e6a148c93e30ff4aa55213d736eab -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mergetrain-2.4.2-py3-none-any.whl.
File metadata
- Download URL: mergetrain-2.4.2-py3-none-any.whl
- Upload date:
- Size: 610.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
595989be5808e215dedfd2488bd8ecd7d410f30c31eb1cf9d88a478a6d30ad04
|
|
| MD5 |
5c97ae760394364dd41417e17ce3b8f1
|
|
| BLAKE2b-256 |
8387353624a6f35d608ed77d4853462557e3f7aebc6fc1023d8e7dc3a165dc2c
|
Provenance
The following attestation bundles were made for mergetrain-2.4.2-py3-none-any.whl:
Publisher:
release.yml on yongjip/mergetrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mergetrain-2.4.2-py3-none-any.whl -
Subject digest:
595989be5808e215dedfd2488bd8ecd7d410f30c31eb1cf9d88a478a6d30ad04 - Sigstore transparency entry: 2687113923
- Sigstore integration time:
-
Permalink:
yongjip/mergetrain@8db0585d3b0e6a148c93e30ff4aa55213d736eab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yongjip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8db0585d3b0e6a148c93e30ff4aa55213d736eab -
Trigger Event:
workflow_dispatch
-
Statement type: