Automating Code Review With Long-Running Agents
11 min läsning
Key takeaways
- Give every long-running agent its own git worktree and branch so parallel review sessions never clobber each other's work.
- Dispatch agents with fixed acceptance criteria for routine review, and reserve remote control for ambiguous or drifting sessions.
- Token burn comes from steering, retries, and vague criteria, not from the remote-control channel itself, so write acceptance criteria up front.
- Agents reliably resolve mechanical merge conflicts in lockfiles and imports, but architecture-level conflicts need a human.
- Claude Code's remote control lets you approve and redirect sessions from your phone, though diff review and rebasing still need a laptop.
Automating code review works when each long-running agent gets its own git worktree, a clear dispatch loop, and a way to steer it mid-session. This guide covers the worktree setup, dispatch versus remote control, token overhead, phone control, and when agents can fix their own merge conflicts.
What does automating code review with long-running agents actually cover?
It means agents that open review-ready merge requests, check their own work against acceptance criteria, and stop for direction instead of stopping for rescue. The Ticksly team runs up to thirty Claude Code and Codex sessions and pays roughly $8 per merge request in API costs, with three humans supplying tasks and direction (their writeup). The scope here is that split: agents do the doing, humans do the thinking.
What the agent reviews before a human ever looks at the diff
The agent checks the diff against the stated acceptance criteria, runs the test suite, and retries on its own failures. Only work that passes those gates reaches your review queue. If you run Cursor Cloud Agents across repos, the same gates apply; see our notes on Cursor background agents.
Where humans stay in the loop
You set acceptance criteria, approve anything gated, and answer questions from waiting agents. You do not watch terminal tabs.
How do you set up git worktrees so multiple agents can review code in parallel without conflicts?
The worktree-per-agent pattern
A git worktree is a second checkout of the same repository in its own directory, sharing the same .git folder. Run git worktree add ../review-agent-3 agent-3/review-auth and agent three gets a full working copy on its own branch, isolated from every other session. Because each agent commits to its own branch and worktree, two agents editing the same file never see each other's half-finished changes, and nobody overwrites anyone's work. Conflicts surface only at merge time, where they belong, instead of mid-session where an agent will "fix" them by deleting a teammate's code. This is the same isolation model behind Cursor's background agents, which run each session in its own container (Cursor background agents in parallel). The isolation also makes failures cheap: an agent that wrecks its checkout only wrecks its own worktree, and you reset it with a single git command instead of untangling a shared directory.
The pattern matters most for review work specifically. A review agent reads code, runs tests, and leaves comments or small patches. If it shares a directory with a coding agent mid-refactor, it reviews a moving target and its findings are garbage. One worktree per agent means the reviewed snapshot is stable, and the diff under review is exactly the branch's diff against main.
The rule is simple: if an agent has a task, it has a worktree. If it has no worktree, it has no task. Disk space is the only real cost, and git worktree uses hardlinks for unchanged objects, so ten worktrees cost far less than ten clones.
Branch and naming conventions that keep sessions separable
Give every agent a stable prefix and encode the task in the branch name: agent-1/review-auth, agent-2/fix-billing-retry, agent-3/review-api. The prefix maps terminal tab to agent at a glance, which answers the "which screen is which" problem before it starts. The suffix should match the Linear ticket or merge request, so state tracking lives in your tracker, not in your memory. Never let two agents share a branch, and never let an agent commit to main directly.
Cleaning up worktrees after merge
Once the merge request lands, remove the worktree with git worktree remove ../review-agent-3 and delete the branch. Stale worktrees are the main failure mode of this setup: an agent left running against a merged branch burns tokens reviewing dead code. Prune weekly with git worktree prune and list what exists with git worktree list.
What's the difference between dispatch and remote control when running long agent sessions?
Dispatch means handing an agent a task with acceptance criteria and letting it run to completion. Remote control means attaching to a live session and steering it while it works. Most coordination pain comes from using the wrong mode for the job.
Dispatch: fire-and-forget with acceptance criteria
Dispatch suits review tasks you can specify upfront: check this diff against the criteria, flag violations, propose a patch. The agent runs in its own git worktree, so a wrong turn costs tokens, not your working tree. As one developer running four coding agents in parallel puts it, splitting the thinking from the doing is what keeps agents from wandering off into a big codebase.
Remote control: interactive steering mid-run
Remote control fits ambiguous work: an agent stuck on a failing test, a review that surfaced something unexpected, a session burning its token budget on retries. You intervene, correct course, and detach. Tools like Vibe Kanban and Aerunit exist largely to make this steering visible across a whole fleet instead of one terminal tab.
Which one fits automated code review
| Dispatch | Remote control | |
|---|---|---|
| Task clarity | Fixed acceptance criteria | Emergent, needs judgement |
| Your attention | None until the merge request | Periodic check-ins |
| Failure cost | Wasted tokens | Wasted tokens plus drift |
| Best for | Routine diff review | Debugging, conflict resolution |
Honest limitation: Aerunit leans dispatch-first. Remote control works, but if your reviews need constant mid-run steering, the acceptance criteria were too thin, and no orchestrator fixes that. More on our approach.
Why is Claude Code remote control not working, and how do you fix it?
Most remote control failures fall into three buckets: the session died, the auth expired, or two sessions are fighting over the same worktree. Each has a distinct signature.
Session and auth failures
A stale session shows up as a daemon that accepts commands but never responds. Kill the process and restart from the original worktree rather than reconnecting to a zombie. Auth expiry looks different: the session runs locally but refuses cloud dispatch. Re-run the login flow, then verify the token works before resuming the session, not after.
Multiple sessions pointing at the same worktree
Two remote sessions on one worktree means duplicate edits and clobbered state. One session per worktree, enforced by naming: the worktree branch, the session label, and the task in Linear should all match. If a second agent needs the same repo, cut a new worktree.
A quick diagnostic checklist
- Is the daemon running in the right worktree?
- Does
claude --resumelist the session you expect? - Is auth current, tested with a trivial prompt?
- Is exactly one session bound to this branch?
If retries burn budget while you debug, track the cost per session so a stuck remote session is a number, not a surprise.
Does running remote control use more tokens than a local session?
The remote-control channel itself adds little: you are passing prompts and status over a connection, not re-running the model. What burns tokens is steering and retries. Every course correction you send mid-run, every re-read of a diff after the agent went down the wrong path, and every restart after a drifted session multiplies context re-ingestion. A review run you leave alone is cheap; a review run you keep nudging is not.
What actually burns tokens in a review run
Three things dominate: re-reading large files after a retry, agents duplicating each other's work on the same repo, and long back-and-forth when acceptance criteria were vague at dispatch. Write the criteria once, up front, and you skip most of the correction loop.
Budgeting across parallel sessions
Track spend per session, not per day. Cap retries explicitly, and assign one agent per worktree so two sessions never burn tokens fixing the same conflict. The same discipline applies to Cursor background agents and local Claude Code runs alike. Aerunit surfaces per-agent token state so you can kill an expensive session before it drifts further, though it does not yet forecast spend before you dispatch.
How do you control a Claude Code session from your phone?
Claude Code's remote control feature lets you start or resume a session on your machine and steer it from the Claude mobile app, so approvals and course corrections happen wherever you are. Anthropic documents the setup and session management in its Claude Code documentation.
Approving and redirecting sessions from mobile
Approval prompts are the main win. When an agent pauses to ask permission to run a command or push a branch, you get it on your phone and answer in seconds instead of letting the session idle for an hour. You can also send short redirect messages, which is enough to stop an agent fixing the wrong thing before it burns your token budget.
What still needs a laptop
Reviewing diffs, editing acceptance criteria, and rebasing across repos stay awkward on a small screen. Treat the phone as a remote control for approvals and direction, not a place to do dispatch. Anything that touches task distribution or merge requests deserves a keyboard.
Can Claude Code fix merge conflicts on its own, and when should you intervene?
Rebasing agent branches onto a moving main
Give the agent two things and it handles most routine conflicts: the current base branch and the intent behind the change. A prompt like "rebase onto main; our change adds the retry queue, theirs touched the same file's imports; preserve both" resolves the mechanical cases. Conflicts in generated files, lockfiles, and import blocks are where agents are reliably good. Run the rebase per worktree so a stuck rebase never blocks the rest of the fleet.
When to take over manually
Intervene when a conflict is really an architecture decision: two agents changed the same function's contract, or the conflict spans repos and someone has to pick which change wins. Agents will resolve those too, confidently and wrongly, and you find out in review. Also take over when the same file is contested across three or more parallel branches; the merge order itself is a task-distribution call, not a git problem.
How do long-running Cursor agents change what automated code review can catch?
From lint comments to task-level verification
A short-lived agent reviews a diff. A long-running agent can verify the task: run the test suite, read the failure, patch, rerun, and only then open the merge request. That moves automated code review upstream from "does this diff look right" to "does this branch satisfy the acceptance criteria." Cursor's long-running agents work this way, and the same pattern holds in Claude Code, whose documentation covers letting the agent resolve merge conflicts and retry failing steps itself. The tradeoff is token burn: every retry loop is billable, so cap iterations per task.
Coordination cost at fleet scale
Whole-task verification only pays off if you can see what each agent is doing. With ten parallel sessions across repos, the bottleneck is state tracking: which agent is blocked, which is looping, which finished an hour ago. Vibe Kanban and Linear-style boards help, but you still need a human triaging approval prompts. Budget for that role explicitly, or the fleet reviews nothing while you herd terminals.
How do you keep a fleet of review agents on target without becoming the bottleneck?
At thirty parallel sessions, the constraint is not the agents. It is you: reading approval prompts, noticing which session has been idle for an hour, and catching the one that spent three hours fixing the wrong thing. State tracking, retries, and task distribution have to live somewhere other than your head.
What to demand from an orchestrator
An orchestrator should show per-session state (waiting, running, stuck), enforce acceptance criteria before a merge request reaches review, and handle retries and token budgets without a human in the loop. Task distribution should split work across repos so agents do not overwrite or duplicate each other. Vibe Kanban, Cursor, and Linear each cover a slice of this; none covers all of it.
Where Aerunit falls short today
Aerunit is built for exactly this loop: run more agents, keep them on target. It handles state tracking and task distribution across a fleet. It does not manage your git worktrees, replace Linear for human task planning, or pick your models, and you will still write the acceptance criteria yourself. If your fleet is five sessions and a shared terminal works, you do not need it yet.
FAQ
How many Claude Code sessions can I run in parallel before coordination breaks down?
Teams like Ticksly run up to thirty sessions with three humans supervising, so the ceiling is high if state tracking lives in a tool rather than your head. The real limit is your capacity to read approval prompts and spot idle or drifting sessions. Past roughly ten parallel sessions, budget for someone triaging agent state explicitly.
What acceptance criteria should I give an agent doing automated code review?
State the expected behavior, the tests that must pass, and what counts as a violation worth flagging. Tie the criteria to the Linear ticket or merge request so tracking lives in your tracker. Vague criteria are the main token sink: every mid-run correction and retry loop exists because the spec was thin at dispatch.
Do I need a separate orchestrator if I already use Linear and Cursor Cloud Agents?
Maybe not. Linear handles human task planning and Cursor handles per-session execution. What neither covers fully is fleet-level state tracking: which agent is stuck, looping, or finished, plus retries and token budgets across sessions. If you run five sessions and check terminals manually, skip the orchestrator. At ten or more, the gap shows.
Can I run agent review sessions against local models to cut API costs?
Yes, and it cuts the roughly $8 per merge request that API-based sessions cost. The tradeoff is capability: weaker models handle mechanical conflict resolution and lint-level review fine, but whole-task verification, like running tests, patching, and rerunning, degrades. Match the model to the task tier, and keep the retry loops on whatever model you trust.
How do I stop two agents from editing the same file in a multi-repo setup?
One git worktree per agent, enforced by naming: the worktree branch, session label, and tracker ticket all match. Never let two agents share a branch or commit to main. If a second agent needs the same repo, cut a new worktree, since worktrees share the .git folder and cost far less than clones.