An autonomous pipeline for Claude Code: from issue to merge
A queue of issues, headless sessions in separate worktrees, two gates and a merge into an integration branch. What came out of it and what had to be reworked.
In this post I want to describe a pipeline that takes a task from the tracker and carries it to a merged PR without my involvement. The need came up over the summer, when I was building a personal memory system: the task briefs were written, the architecture was accepted, and there was no time left for the code itself.
I really did not want to sit next to an agent and confirm every action, because that is the same work, only slower. I wanted to file a task and come back to the result.
At first the pipeline lived inside that project. Later it was split out into a separate engine (git subtree split, history preserved), and it now works with any repository.
The idea
The queue is a set of issues in a tracker (mine is a self-hosted Forgejo) with the factory label (label and branch names here are placeholders). Each task is executed by a fresh headless Claude Code session in its own git worktree. The deliverable is a PR, followed by two gates and an automatic merge.
issue (#N, label=factory, dependencies closed)
→ worktree, branch factory/issue-N
→ executor session: code, tests, commits, comments in the issue
→ push → PR "closes #N" → verify script (machine gate)
→ reviewer session: approve / request changes
→ fix loop (no more than 2 attempts in total across the gates)
→ merge (squash) into the integration branch → issue closed
The pipeline never writes to main. I make the final PR from the integration branch myself.

What came out of it
The first production run was on 8 July 2026: six tasks went through the full cycle, 6 commits, 56 files, +5792/−100 lines. No tasks were left blocked by the end of the run.
Some notable things from that run:
- the reviewer caught real architectural drift. The executor wrote a core that imported concrete adapters, bypassing the accepted ADR on ports. The PR went back for rework, the fixer introduced the missing port, and the second review approved it;
- an agent filed a sub-issue on its own for a missing piece of environment, and the pipeline executed it in the normal order;
- both blockers were infrastructure ones and took minutes to clear.
The factory in numbers
A single run proves little, so here are the counters from the factory's event log for 19 days, from 20 September to 9 October 2026. There are three projects, and one of them is the engine itself.
| Event | Count |
|---|---|
| Tasks merged | 243 |
| Review approved the work | 246 times |
| Review sent the work back for rework | 94 times |
| Machine gate failed | 14 times |
| Task went into a block | 36 times |
| Blocked as of today | 0 |
Two points are worth noting. The review sends work back in more than a quarter of cases, which means the gate is not a formality. Blocks happen regularly, and this is the normal mode of operation: the task waits for my decision instead of being done by guesswork.
How it works inside
The engine's main properties as of today:
- the driver is an ordinary bash script that only routes. Everything that requires judgement happens inside the sessions;
- a task's stage is determined from facts (whether there are commits, a PR, a review) and is not stored separately. Because of that, restarting the driver continues the work instead of starting from scratch;
- when it hits a wall, the pipeline sets the
factory:blockedlabel and writes in the issue what has to be done by hand. Only the owner can remove the label; - if the tracker did not respond (HTTP 000, 5xx, garbage instead of JSON), the driver waits and retries instead of treating the queue as empty;
- sessions are stopped by the process group ID recorded at launch.
pkill claudeis not an option here, because I work with Claude Code by hand on the same machine; - three interrupted runs in a row count as a crash loop, and the target is no longer brought up automatically.
How to work with it
To submit a task, create an issue with the factory label. A supervisor (a LaunchAgent) walks the repositories once a minute and starts the driver if there is anything in the queue.
Freezing a target and bringing it back:
pause.sh --target <path> # active stages finish, new ones do not start
pause.sh --target <path> --now # sessions are interrupted immediately
resume.sh --target <path> # interrupted sessions continue by their session_id
Restarting a single phase of a task:
rerun.sh --target <path> --issue <N> --stage <executing|verify|review|ci|merge>
The plan gate
For tasks where a misunderstanding is expensive there is the factory:gate-plan label. With it the pipeline first writes a plan and waits for /approve without occupying an execution slot.
The plan is published as a comment in the issue, in two views:
<!-- autopilot:plan v=3 base=2 -->
## What changed in response to the comments on v2
- [n1] addressed: the gate is moved before the transaction is opened
- [n2] rejected: no cache is needed, the reference table is read once per request
<!-- autopilot:view=product -->
…the translator's retelling…
<!-- autopilot:view=arch -->
…the planner's architectural plan…
The architectural view is written by planner, which sees the brief. The product view is written by plan-translator, which sees only the text of the architectural plan. I compare the retelling with my intent: if they diverge, the plan does not express the intent.
It is worth noting how the translator's "blindness" is implemented. An instruction in the prompt is not enough here, so its session is started with --strict-mcp-config and no MCP servers at all, with its working directory in an empty temporary folder. It simply has nothing to read the issue with.
The gate has no state in state.json: the driver computes everything it needs from the issue comments.
Taking over an agent's session
Sometimes an agent gets stuck, and it is easier to finish the task myself without losing its context. For that the editor extension has a five-step scenario:
- the target is paused;
- the
factory/issue-Nbranch is fetched into a local worktree; - the agent's session file is downloaded to the place where Claude Code looks for the sessions of that directory;
- I continue the same conversation in the editor;
- the "Return the task to the factory" button pushes my commits and restarts the verify phase.
To make the fifth step safe, the driver catches up with the branch on origin before it starts working (merge --ff-only). If my commits and the agent's commits have diverged, the task goes into a block with the reason stated.
Problems along the way
- a tracker read error was taken for an empty queue, and this was fixed in a separate task;
- when a phase was restarted on a blocked task, the pipeline would have unblocked itself, so the label is now removed only by the owner;
- the model subscription window is shared across all projects. For that reason there is a single driver for the whole factory, and each project has a daily task cap and a brake.
Downsides
- the result is no better than the brief. A task without a verifiable definition of done passes the gates only formally;
- the reviewer catches deviations only from decisions that have been written down;
- a noticeable amount of tooling has grown around the engine: a dashboard, an editor extension, Telegram notifications. The extension package has 930 tests, but I still have not walked through some of the features by hand in a live window.
The right use case is tasks with a clear boundary in a project where the architectural decisions are already written down. The pipeline is not suited to searching for the decision itself.
The engine's repository lives in my home git for now. Once I publish it, I will add a link here.
Tags: Agents, Automation, Claude Code, Git
Read next
A console for the agent factory: a menu bar item and an editor extension
How to watch an agent pipeline without opening the tracker. What the menu bar shows, what moved into the editor and why neither of them stores anything.
From a script for myself to a product: five months of claude-agents-bar
What I had to add to a working script so that a stranger could install it. An installer, diagnostics, 21 recorded decisions and 16 releases.
claude-agents-bar: every Claude Code session, in the menu bar
A SwiftBar plugin that shows which Claude Code sessions are working, waiting on you, or done - built on hooks and JSONL transcripts alone.
Comments