These days almost everyone writes code with AI agents. So do I: I've been building a side project with Claude Code for a while now. It's not a toy app. It has an Angular frontend split into microfrontends, a NestJS backend, a database and a fair amount of business rules.
Three VS Code windows, three agents and me in the middle
My first idea was the obvious one: if one agent does one task, three agents do three. So I cloned the repository into three folders, opened three VS Code windows and ran Claude Code in a terminal in each one, working on a different task. I was playing at shipping several tasks in parallel.
It lasted two days.
On paper, great. In practice, every time an agent finished, it was my turn:
- Go to that folder.
- Start the backend, the database and the three frontends.
- Test by hand that the feature actually worked.
- Shut everything down.
- Review the code, open the PR.
- Move to the next folder and start over.
It was like a cook with three burners going and a single spoon to taste with. The burners take care of themselves; the cook is the one who can't keep up.
That's when something that now seems obvious hit me: the bottleneck of coding with agents isn't the coding. An agent finishes a task in minutes. Checking that it's right takes me a lot longer. Adding more agents only makes my review queue longer. And my laptop, running everything three times over, wasn't too happy either.
What comes before the code
The agent doesn't work blind. Before it writes a single line, it reads:
- PRDs. One general product document and one per area of the app, describing what it has to do and why.
- The Jira ticket, which is the source of truth. Its acceptance criteria are written as BDD scenarios (Given / When / Then). Claude Code reads it through an MCP.
- The API contract, in an OpenAPI file.
With that, and using SDD with OpenSpec, the agent writes a proposal with what it's going to change and a task list. I answer its questions, tell it to go ahead, and it implements the change with tests that check those scenarios and opens a PR.
What a PR Preview is
A PR Preview is a deployment of your app with the exact code of a pull request, at its own URL. It's created when you open the PR and torn down when you close it.
I first saw them on big projects, a bank among others, and they
always felt like a luxury for teams with plenty of infrastructure. The
idea is simple: you open the PR and, a few minutes later, a comment
shows up with a link like https://pr-42.preview.example.dev. You
click it and see the app exactly as it would be after merging.
It's the show flat for every renovation. You don't have to picture the kitchen from the blueprints: you walk in and see it.
For my problem it was exactly what I needed. If every PR deploys itself, reviewing no longer means starting anything on my machine. And if my machine isn't needed for reviewing, the agents don't need to live on it either.
How I set it up
I didn't want to pay for a service for this, so I built it on a single small EC2 instance on AWS with Docker, for about 22 euros a month. This is the layout:
Internet
│
▼
Caddy (80/443, automatic HTTPS)
*.preview.example.dev
│ │
▼ ▼
pr-42.preview... pr-43.preview...
├── /api/* → backend ├── /api/* → backend
│ (container pr-42) │ (container pr-43)
└── /* → static └── /* → static
│ │
└──────────┬──────────────┘
▼
Mongo (shared)
databases pr_42, pr_43...
│
Mailpit
(catches all email)
There are two layers:
- A base that's started once and left alone: Caddy, Mongo and
Mailpit, in their own
docker composefile. - One stack per PR, containing only the backend container. Each
one is named after its PR (
pr-42,pr-43…), which is what lets several run at once without stepping on each other.
Let's go piece by piece.
Caddy and one subdomain per PR
Caddy is the front door. I picked it because it gets HTTPS certificates on its own for every new subdomain, with nothing for me to do.
DNS has a single wildcard record, *.preview.example.dev, pointing at
the machine. With that, any pr-<number> works without ever touching
DNS again.
When a PR is deployed, the workflow writes a small config file for that subdomain and reloads Caddy:
pr-42.preview.example.dev {
handle /api/* {
reverse_proxy pr-42-backend:3000
}
# The frontend is a SPA: any route falls back to index.html
handle {
root * /srv/previews/pr-42
try_files {path} /index.html
file_server
}
}
The frontend isn't built on the server
This was one of the first decisions and one of the most important.
The machine is small, and an Angular build eats all the RAM. So the
frontends are built in GitHub Actions and only the static files are
uploaded to the server with rsync. Caddy serves them using almost no
memory.
The result: each PR runs a single container, the backend. Around 350 MB per PR.
Microfrontends add one extra detail. The shell needs to know where the
remotes live, and locally that points to localhost. Before building,
the workflow rewrites the federation manifest so it points to the
PR's subdomain:
{
"mf-catalog": "https://pr-42.preview.example.dev/mf-catalog/remoteEntry.json"
}
Without this, the preview starts up and loads nothing.
One database per PR
PRs can't share data: if one test deletes customers, the other one shouldn't notice. But I didn't want one Mongo per PR either, that's a lot of memory.
The fix: a single Mongo with a separate database inside it (pr_42,
pr_43…). Full isolation for the cost of one process.
A preview with an empty database is useless for reviewing, so the
repository holds a small test dataset with no real data. When the PR
is opened, it's restored with mongorestore into that PR's database.
Only when it's opened: later pushes leave it alone, so you don't lose
whatever you were testing.
Mailpit: a preview never sends a real email
The app sends emails. A preview with test data emailing real addresses is a scare I don't need. Mailpit acts as a fake mail server: it catches everything that goes out and shows it on a separate web page. As a bonus, I can review the emails as part of the PR.
The lifecycle, in two workflows
Two GitHub Actions workflows drive all of the above.
When a PR is opened or pushed to:
- Tests run.
- The frontends are built.
- The static files and the backend code are uploaded to the machine.
docker compose -p pr-42 up -d --buildbuilds the backend image and starts its container.- If the PR is new, the dataset is loaded.
- The Caddy route is written and Caddy reloads.
- The URL is posted as a comment on the PR.
When the PR is closed, the other workflow removes everything: container, image, Caddy route, database and files.
docker compose -p pr-42 -f docker-compose.preview.yml down -v --rmi local
rm -f /srv/caddy/sites/pr-42.caddy
rm -rf /srv/previews/pr-42
That second workflow isn't optional. Without it, the disk fills up in a few weeks.
What broke along the way
It didn't work first time. Some of the things I ran into:
- RAM is tight. I had to add 2 GB of swap to the machine and put a memory limit on the backend container.
- Mongo grabs half the machine by default. Its cache takes half the available RAM and starves the previews. I had to cap it by hand.
- Transactions. The backend uses transactions, and Mongo only supports them on a replica set, so even with a single node it has to start as a replica set.
- CORS. If the backend doesn't know its PR's subdomain, the
browser blocks the calls and the preview looks broken without giving
you any clue. Each backend gets its own
CORS_ORIGINwith the PR number. - Access to the machine. At first GitHub Actions came in over SSH with port 22 open. I switched to OIDC and AWS Session Manager: GitHub proves the run comes from my repository, AWS hands it temporary credentials and the tunnel goes through SSM. No port 22 open to the internet and no long-lived AWS keys stored in GitHub.
How I work now
With previews in place, the last step was to move the agents off my laptop too and use Claude Code in the cloud. The loop looks like this:
Jira ticket
│ (MCP)
▼
Claude Code in the cloud
│ OpenSpec: proposal → questions → plan
▼
I say go → it implements → opens the PR
│
▼
GitHub Actions: tests + deploy
│
▼
https://pr-42.preview.example.dev
│
▼
I review code and feature ──► merge ──► preview is deleted
Everything happens in the cloud, from the plan to the PR. I hand it a ticket, it raises its questions about the plan, I answer them, tell it to go ahead and forget about it. A few minutes after it opens the PR, there's a comment with the preview link. I can have several tasks running at once and my machine doesn't start a thing.
What I haven't handed over
I still review every PR: the code, the commits and the feature with the app in front of me. What PR Previews changed is that reviewing is no longer a chore, not that I stopped doing it.
And I still decide what gets built: the PRDs, the tickets, the scenarios and the API contract. If something isn't in the ticket, the agent doesn't make it up.
This is how I work today. In a few months I'll probably be doing it differently. But I'm keeping the lesson: when agents write the code, the work doesn't go away, it moves. And it pays to know where it went.