One agent per PR
I asked Claude whether Solo could keep one agent per open PR in its own worktree, and it worked out all the heavy details.
1 min read
I've been experimenting with my review process and my current workflow, and I decided it might be nice to try having an agent per PR in my Solo workspace for a client project. So I asked Claude if it was possible, or how we could set it up, and it figured out all of the heavy details.
What I liked
Claude figured out all of the heavy details, which was fantastic. So far it seems to be working as intended: I have all of the PRs on the left side of Solo, and it automatically pulled in a new PR as soon as it was opened. Hopefully, when some of these PRs merge, their agents will get closed. That way I always know what's open, and I hope it'll help me keep track of where each one is in the process.
What I'd do differently
I don't think I'd do anything differently yet, but I set this up 10 minutes ago. I should follow up in a week or so and see how it's working.
The session
Prompt 1
If I wanted this solo project to always have a single solo agent per open PR, and named "{First initial}: {Jira ticket}/{PR Number}" i.e. "M: PROJ-184/#105", "A: DX/#103", "C: PROJ-163/#104" How could we go about doing that? I'd like one to open when a PR is opened (for folks other than me) and them to close when the PR is merged
- solo › help ×4
- solo › whoami
- solo › list_processes
3 more Hide
- ran "List open PRs with authors and tickets"
- ran "Inspect the Solo CLI's commands"
- ran "Check solo.yml, PR #103, agent tools and an existing PR agent"
I'm checking whether GitHub can push PR events to us so we don't have to poll.
- ran "Read gh event listen options"
There's no way to get a push when a PR is opened. Solo only wakes agents with timers, and gh event listen only watches one PR that already exists. So the dependable approach is a small script that runs every couple of minutes and compares open PRs with the Solo agents you have. It can do the whole job from a shell, because the solo CLI can spawn, rename, send input to and delete agents.
How it would work
Run a script as a Solo command in the monorepo project (next to npm:dev and queue:work), looping every ~2 minutes. That way it starts and stops with the project and its log is visible in Solo. Each pass:
Get open PRs:
gh pr list --state open --json number,title,authorBuild each name: take the first letter of the author's GitHub display name ([a teammate] →
M), the ticket from the start of the title (PROJ-186:), orDXif there isn't one, and the PR number. For example:M: PROJ-186/#107.Find existing agents:
solo processes list --project-id <id> --json, matching agents to PRs by the/#107at the end of the name. Matching on the number means a renamed agent still counts.Spawn missing ones: for each open PR not by you that has no agent, run
solo processes spawn --kind agent --agent-tool-id <id> --name "…", then send the first prompt withsolo processes input <id> --text "…".Close merged ones: for any agent whose PR is now merged, run
solo processes delete <id> --confirm-stop-running. This includes your own PRs, since you open those agents yourself but want them gone on merge too. The conversation is still in~/.claude, so you can resume it withclaude --resumeif needed.
Your current agents already follow this naming, so nothing needs renaming. Right now the first pass would spawn agents for #107, #106 and #101.
I'd keep the script out of the repo, in ~/.local/bin or similar, because it's your personal setup and not the team's.
Before I build it, I need three answers:
First prompt: what should a new agent be told to do? For example, "Review PR #107 with /code-review", or just "You own PR #107; wait for instructions."
Working directory: the CLI spawn can't set a working directory, so every agent would start in the main checkout and share it. Should each agent get its own lerd worktree on the PR's branch? The script would create the worktree and
cdthe agent into it.PRs closed without merging: should their agents also be closed, or kept so you can look at them?
Prompt 2
if it's not mine and it's open, yes review. if it's in draft, just pull down and wait each agent gets its own lerd worktree on the PR's branch Closed and code cleaned up (and worktrees should be cleaned up when a PR is merged)
- ran "Inspect lerd CLI worktree commands and current worktrees"
- ran "Read lerd worktree add/remove/wait help"
- ran "Read lerd setup and db isolate help, project lerd config"
- ran "Read Solo CLI spawn, input and agents add help"
- ran "Check Solo status for an MCP endpoint"
The Solo CLI can't set an agent's working directory, so I'm checking whether a script can reach Solo's MCP (which can) directly.
- ran "Find how the Solo MCP server is registered"
- ran "Inspect Solo HTTP API config and MCP registration"
- ran "Find Solo HTTP API spawn endpoints"
- ran "See where existing PR agents are working"
- ran "Find the Solo MCP server command"
The CLI and HTTP API can't set a working directory, but Solo's MCP server is a stdio binary a script can drive. Testing that:
- ran "Test driving Solo's MCP server from a script"
Driving the MCP works. Now checking how to register the script as a project command in Solo:
- solo › help
- ran "Check remotes, PR draft states and author names"
- write ~/.local/bin/solo-pr-agents
- ran "Make script executable and dry-run it"
Dry run matches what's expected: #101, #106 and #107 need agents, and the existing ones are left alone. Adding a list limit, then running a real pass:
- ran "Run one real reconcile pass"
While that pass runs (each worktree needs composer, npm and a database), I'll register the watcher as a local Solo command, keeping it out of git:
- ran "Add a git-excluded solo.yml with the watcher command"
- ran "Check Solo picked up the command and kept the others"
pr-agents shows up as a Solo command, still stopped because Solo needs you to trust it first. Your other commands are untouched. Waiting on the first real pass now.
- read the background task's output
Still running lerd worktree setup for the first worktree. I'll report once the pass finishes.
- background task finished: "Background command "Run one real reconcile pass" completed (exit code 0)"
- ran "Check pass output, agents and worktrees"
- ran "Check the pr-agents command and each new agent"
5 more Hide
- ran "Close the two duplicate agents from the manual run"
- ran "Add a single-instance lock and a pre-spawn re-check"
- ran "Let dry runs skip the lock; check watcher progress"
- ran "Wait for the watcher's #107 spawn"
- ran "Read wait result and list agents"
Closing the newer #107 duplicate (401) and restarting the command onto the fixed code:
- ran "Close duplicate, restart watcher, confirm a clean pass"
It's clean now: one agent per open PR, and the restarted watcher's first pass had nothing to do. Checking that a review agent actually started work:
- ran "Peek at the #101 review agent"
- write ~/.claude/projects/<project>/memory/solo-pr-agents-watcher.md
- ran "Index the new memory"
The watcher is set up and running. Every open PR now has exactly one agent, each working in a worktree on that PR's branch:
| PR | Agent | Worktree |
|---|---|---|
| #101 | M: PROJ-72/#101 (new, reviewing) | monorepo-proj-72-reports |
| #106 | M: PROJ-176/#106 (new, reviewing) | monorepo-proj-176-settings |
| #107 | M: PROJ-186/#107 (new, reviewing) | monorepo-proj-186-calendar |
| #102, #103, #104, #105 | your existing agents, left as they were | — |
The #101 agent has already finished its first /code-review pass and reported its findings in Solo.
How it works. The script is ~/.local/bin/solo-pr-agents. It runs as the Solo command pr-agents and checks every 2 minutes:
Someone else opens a PR that's ready for review: it creates a worktree on the PR's branch, runs
lerd worktree setup(dependencies, asset build, database), and starts an agent that runs/code-reviewagainst the PR's base branch. Agents report findings in Solo and don't post anything to GitHub unless you ask.Someone else opens a draft PR: same worktree and agent, but the agent only waits. When the PR leaves draft, the agent is told to review it.
A PR is merged or closed (yours too): the agent is closed, the worktree is removed with its lerd setup, and the local branch is deleted.
Worktrees for other people's PRs are force-removed.
Worktrees for your own PRs are not forced, so uncommitted work survives. If yours has uncommitted changes, removal stops and the log says why.
The main checkout is never removed. It's currently on #102's branch, so merging #102 closes its agent but leaves the checkout alone.
Names use the first letter of the author's GitHub display name and the ticket at the start of the PR title, or
DXif there isn't one.
Setup details:
Spawning goes through Solo's MCP server, because the
soloCLI and its HTTP API can't set an agent's working directory.The command is defined in
solo.yml, which I excluded through.git/info/exclude, so it can't be committed.New PRs are picked up on the next check, plus about a minute for worktree setup.
One problem I caused, now fixed. Solo started pr-agents on its own as soon as solo.yml appeared, while I was also running a pass by hand. That spawned duplicate agents for #101, #106 and #107. I closed the three duplicates, which were a minute or two old. I also added a lock so only one copy can run, and a check right before spawning so a slow worktree setup can't lead to a second agent.
To preview what it would do without changing anything, run solo-pr-agents --dry-run.
You’re on the list!
Your first Enby·Mail is on its way. Keep an eye on your inbox for a welcome note.
More from the Log
The whole log-
Moment
Finished Hunter x Hunter
-
Moment
Finally visiting Alcatraz