r/ClaudeCode • • 2d ago

Help/Question How do you run long Claude Code builds on one machine without everything waiting in line?

I run all my projects with Claude Code on one home server: 6 cores, 15 GB RAM, Debian 13, no GPU. /tmp is tmpfs, so it eats RAM too. Right now that's a few web apps (Next.js 16 + Supabase + Vercel), a Shopify store, a browser game and a mobile app (Expo, Android emulator for testing). Often 2 or 3 projects have sessions running at the same time.

THE SETUP

- Sessions run in tmux via a session manager, and I follow them from my phone with Remote Control
- Each project has one lead session (Opus) that works through a task list on its own, often all night
- The lead starts up to 2 builder subagents, each in its own git worktree. Merges go back to main
- Reviews: 1 to 3 reviewer agents per task depending on size, max 2 review rounds. Small findings go into one "sweep" task instead of a new task each
- Agents talk to each other through a mail/file-reservation tool so they don't edit the same files
- I wrote my own Claude Code plugin with all the rules, gates and scripts, so every project works the same way

THE CHECKS EVERY TASK HAS TO PASS

- tsc --noEmit, lint (Biome), Vitest, next build, pnpm audit
- Playwright e2e, but only the specs the change touches. I keep a map of source files to test areas (55 areas), and a new file must join an area in the same commit
- e2e stops at the first failure while iterating. The full suite runs once per batch, before main
- UI tasks: screenshot check against the approved design mockups at 390 and 1440 px, on a production build on its own port
- Mobile screens: every state (5 to 25 per screen) on the Android emulator with Maestro flows, and screenshots compared to the mockups
- DB changes: pgTAP tests on a throwaway local Supabase in Docker

HOW HEAVY JOBS ARE SHARED

- Every heavy step (build, test suite, e2e, emulator flows) from every project goes through one machine-wide queue. Each job has a cost (1 or 2 units) and the queue only lets so many units run at once
- Test runners read their worker count from the queue (3 workers)
- e2e has its own lock with priority, so a run someone waits for goes before background runs
- The lead rotates to a fresh session at 3 compactions, after 8 hours, or when its pace drops below half its own average. It writes a handover file and starts its successor itself

THE NUMBERS

- Fresh lead on web work: about 9 tasks/hour for the first 3 hours, then down to about 5/hour
- Last night, mostly app screens: 12 tasks in 8.8 hours, and 5.6 of those hours were spent waiting in the queue
- Emulator alone is about 2.2 GB RAM. Add two builders with their own Metro bundlers (one per worktree, different ports), a Next build and Playwright from another project, and the machine runs low
- When memory gets low, Claude Code kills idle background shells, so my watcher scripts die quietly

THE PROBLEMS

  1. Queue time. The bottleneck isn't the model, it's waiting for CPU/RAM
  2. One emulator. Every app screen state goes through it, one flow at a time
  3. Memory. 15 GB isn't enough for emulator + 2 worktrees with Metro + builds + e2e across projects
  4. Sessions wear out. Context fills, pace drops, so I rotate every few hours

WHAT I'D LIKE TO KNOW

  1. What does your setup look like for long autonomous runs across several projects? One big machine, several machines, or cloud (and roughly what does it cost)?
  2. How do you share CPU and RAM between projects so one doesn't block the others?
  3. How do you test mobile screens without one emulator being the bottleneck? More emulators, cloud devices (Firebase Test Lab, BrowserStack, EAS), or fewer states per task?
  4. Do you run the full checks on every task, or batch them? Where did you draw the line?
  5. Any tricks for keeping Metro/emulator/Playwright memory down?
  6. What made the biggest difference in speed for you?

Thanks.

3 Upvotes

42 comments sorted by

•

u/AutoModerator 2d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Painter_new8 2d ago

Did you set a limit for the emulator? Like 2-3 cores max. It will take longer but it could help running simultaneously.

1

u/ScarcityOrdinary6877 2d ago

No, I hadn't. Just checked: the AVD is set to 4 cores and 2 GB RAM (hw.cpu.ncore=4), on a 6-core machine. So while it runs, everything else fights over 2 cores. That probably explains a lot of the queue time 🥶

I'll try 2 cores and see if the total gets better even if each flow is a bit slower. Did you also cap the RAM, or just the cores? And do you run the emulator with -no-snapshot or from a snapshot? Wondering if a warm snapshot saves more than the core limit costs?

1

u/Painter_new8 2d ago

Did you already find out if it helps?

Capping ram is worth a try. After setting the limit I was already done with optimizing and testing the app I use to connect to my Claude Cli. But I kept the limit because there's other stuff running on my server and I don't mind waiting for the app.

1

u/ScarcityOrdinary6877 2d ago

Yes, switched it this morning: 2 cores, 2 GB RAM, booting from a quickboot snapshot. From my job queue log: a Maestro flow run went from 193 s average (103 runs the day before) to 151 s (21 runs since), so roughly 20% faster with fewer cores, I'd guess because it's no longer fighting everything else for CPU. Small sample, but the direction is clear.
Queue wait went up at the same time, but I also made the queue stricter that day (one heavy job at a time on this box), so I can't pin that on the emulator. Haven't capped RAM below 2 GB yet, that's next. Thanks for the tip, it was a good one.

1

u/MikeWise1618 2d ago edited 7h ago

In today's world that is a very small machine. Sessions need memory to run their tools. Its fine for 1 or 2 sessions, but If you want to do a lot in parallel you will need far more memory, like 64 gb at a minimum, and probably 12 cores.

I have 192 GB and 16 cores, but 128 would probably be enough for most things.

1

u/ScarcityOrdinary6877 2d ago

Yeah, I think you're right. I checked: it's a Lenovo Tiny with an i7-8700T (6 cores, 35W) and 16 GB, and it's sitting at 8 GB swap right now. So a lot of my "queue time" is probably just the box swapping.

Each Claude session is ~400 MB, each subagent 200-350 MB, Metro 0.2-1.4 GB, emulator 2.2 GB. Two projects at once and it's full.

Going to max the RAM first, then probably look at a bigger box. 192 GB and 16 cores sounds nice. What are you running, a workstation or a server?

1

u/MikeWise1618 6h ago

It's just an hobby ASUS motherboard, but a decent one, cost me like 400 euros. I built it 3 years ago, memory is a lot more now unfortunately. If I was on a budget I would do something with used DDR4 memory, which I think is a lot cheaper.

1

u/ScarcityOrdinary6877 2d ago edited 2d ago

Proposed specifications:
CPU: AMD Ryzen 9 9950X (16 cores, 32 threads)
RAM: 64 GB DDR5-5600 (expandable to 128 GB)
Motherboard: B650M
Storage: Samsung 990 PRO 1 TB NVMe SSD
Cooling: Thermalright Phantom Spirit 120 SE
PSU: Corsair RM650e 650W Gold
Case: Jonsbo D31 Mesh
GPU: Integrated graphics
OS: Debian Linux

Is this configuration sufficient for our current and future workloads? Would you recommend any changes? Would a Ryzen 9 5950X with 64 GB or 128 GB DDR4 be a more cost-effective alternative?

1

u/Xotta 2d ago

Yup I suspect you'd be fine with the DDR4 configuration, and it would probably be fine for ~5 years and in that timescale its quite realistic RAM prices become a bit more sane.

1

u/ScarcityOrdinary6877 2d ago

Here's the DDR4 build I'm looking at (Swedish prices from Proshop, USD roughly converted):

- CPU: AMD Ryzen 9 5950X, 16 cores / 32 threads (AM4) - 4 319 kr (~$411)
- Cooler: Thermalright Peerless Assassin 120 SE - 369 kr (~$35)
- Motherboard: ASUS PRIME B550M-A WIFI II (mATX, 4 RAM slots) - 1 167 kr (~$111)
- RAM: Patriot Viper Steel DDR4-3200, 64 GB (2x32) - 6 266 kr (~$597)
- SSD: Samsung 990, 1 TB NVMe - 2 219 kr (~$211)
- PSU: Corsair RM650e, 650 W, 80+ Gold - 1 015 kr (~$97)
- Case: Fractal Design Pop Mini Air - 1 342 kr (~$128)
- GPU: none, I'll borrow an old card just for the install, then run it headless
- OS: Debian

Total: 16 697 kr (~$1,590)

Two free RAM slots so I can go to 128 GB later. Anything you'd change?

1

u/Xotta 2d ago

https://www.reddit.com/r/buildapc/

I'm pretty good with this stuff but I'd be lying if I said I was absolutely the best at it, there are people in that subreddit who are.

1

u/AgentYurt 2d ago

Two things from running a setup like this. First, the handover file is where the rotation lives or dies — I write it as what the session was trying to do, what actually changed, the calls I made and the reasoning behind them, what's still open, and what happens next. And the next session doesn't take any of that on faith; it checks the diff or the test behind a decision before building on it.

Second, your own numbers say the lead isn't the bottleneck: 5.6 of 8.8 hours was queue time. Rotating earlier won't buy you much there. The single emulator and the checks waiting on it are doing the damage — that's where I'd spend the effort.

1

u/ScarcityOrdinary6877 2d ago

Both good points, thanks.

On the handover: mine has what closed, what's paused, decisions and next tasks, but not the reasoning behind each call, and the next session mostly trusts it. I've already been bitten by stale notes like "no device available" surviving several sessions. Adding "why" to each decision and making the new session check the diff or test before building on it.

On the bottleneck: agreed. Rotation was never the slow part. Right now every small change to an app screen re-runs Maestro on the emulator. Plan is a fast inner loop (render the screen and compare to the mockup without the emulator), and run the emulator once when the screen is done. Also capped the emulator at 2 cores and I'm looking at a bigger box.

1

u/AgentYurt 2d ago

That stale-note trap stings most — 'no device available' is a conclusion, not a fact, so nobody can tell when it stops being true. The fix that worked for me: every claim in the handover carries its check, like 'no device available — checked with the device list at the start of this session, re-check before trusting it.' And the note gets rewritten after each chunk, not appended to, so a dead line can't survive silently. Your fast inner loop is the right call — the 2-core cap helps, but cutting the emulator out of the loop is what kills the queue. Does the render-and-compare step run headless, or does the final screenshot still need the emulator?

1

u/ScarcityOrdinary6877 2d ago

Good point, "no device available" is exactly that kind of line. Changed my rule: every claim in the handover carries its check, like "no device: adb devices empty at 09:40, re-check before trusting", and the note gets rewritten after each chunk instead of appended to.

On the loop: the render-and-compare runs headless. Expo web in headless Chromium, compared to the mockup, no emulator. The final screenshot and the Maestro flow still run on the emulator, once per screen when it's done, because native fonts, gestures and navigation only show up there. So the emulator goes from every edit to once per screen.

1

u/AgentYurt 2d ago

That's the split I'd have guessed, and it's a good one — headless for the loop, emulator only where the native stuff actually lives. The once-per-screen check is the part I'd keep an eye on: if a screen's Maestro flow passes but the headless compare drifts from it, which one do you trust? In my setup the emulator pass is the tiebreaker, because it's the only one that saw the real fonts and gestures. Also glad the claim-plus-check rule landed — 'adb devices empty at 09:40' is exactly the kind of line that makes a handover re-checkable instead of just plausible.

1

u/ScarcityOrdinary6877 2d ago

Yeah makes sense, emulator wins if they don't match. We'll just try it and see how it goes. Thanks a lot, this helped more than I expected 😁

1

u/ScarcityOrdinary6877 2d ago

One more question if you don't mind. Before I spend money: I'm looking at building a Ryzen 9 9950X with 64 GB DDR5 (around $2,700 here, RAM prices are crazy). Or a 5950X with 64 GB DDR4 for about $1,600.

From your setup, how much faster did things actually get when you moved to a bigger machine? Was it the cores or the RAM that made the difference? And would you go 9950X or is the older 5950X with more RAM per dollar good enough for this kind of work?

Going to try the fixes first (tmp on disk, one heavy job at a time, headless loop) and measure, but curious what you'd do?

1

u/AgentYurt 1d ago

Honest answer first: I haven't made that jump myself, so I don't have a before/after number for you and I'm not going to invent one.

From your numbers, I'd put RAM ahead of cores. Both chips are 16 cores / 32 threads, so the 9950X mostly buys faster single-core and efficiency, not more parallelism — and 5.6 hours of queue time on a 6-core box with 15 GB RAM, 6 GB of it sitting in tmpfs, reads like memory and contention, not a shortage of cores. For roughly $1,100 less, the 5950X build gets you the same core count and the same 64 GB, with slots free to go to 128 GB later. That's the one I'd take for this workload.

When you measure after the fixes, which one actually saturates first — RAM or CPU?

1

u/ScarcityOrdinary6877 1d ago

Fair point on cores, they're both 16/32, so it's not a parallelism upgrade. A few things tipped it back to AM5 for me though: the steps I actually wait on (next build, tsc) lean on single-core, where Zen 5 is a big jump over Zen 3; the 5950X has no iGPU, so a headless box still needs a card to get through BIOS; and here 64 GB of DDR4 is order-only with 1–3 weeks lead time, and the cheap kit is 4×16, which fills every slot.

To your question: since the tmpfs and queue fixes, available memory hasn't dropped below 3 GB (median 8.6 GB of 15). So RAM was the problem before the fixes, mostly /tmp eating it. Now the limit is the queue's heavy-job slots, which is CPU, and that's on purpose. So I'm taking both: 64 GB and the faster cores.

1

u/shetritr 2d ago

on 6 cores the fix is usually one lock, not more scheduling. wrap next build and the playwright runs in flock /var/lock/heavy.lock so only one heavy job runs across all projects and the rest wait their turn, while tsc/lint/vitest stay parallel. and with /tmp on tmpfs, point the build caches at disk so three next builds aren't eating your 15 GB

1

u/ScarcityOrdinary6877 2d ago

Checked and you're right. /tmp is tmpfs and is holding 6.2 GB right now: 1.8 GB Playwright transform cache, 1.8 GB of emulator flow output, 0.5 GB node compile cache. On a 15 GB box that explains most of my swap. Moving all of it to disk.

I do have one machine-wide queue already, but it lets a build and an e2e run go at the same time. Going to drop that to one heavy job at a time and keep tsc/lint/vitest outside the lock. Thanks.

1

u/bornmix_dev 2d ago

your own numbers answer half of it: 5.6 of 8.8 hours in the queue means you're short on hardware, not on model. cheapest win is probably moving the emulator off that box. an old android phone over adb or a small mini pc that only runs the emulator frees 2+ gb and stops it blocking web work. second, I'd treat next build like your full e2e: tsc, lint and the touched tests per task, the full build once per batch. and only start metro for the worktree whose task actually needs the device. rotating the lead on pace drop with a handover file is smart, I'd keep that

1

u/ScarcityOrdinary6877 2d ago

Thanks, this was a good breakdown and we ended up doing pretty much all of it.
Build: next build now only runs per task when the change can actually break it (routes, framework config, middleware, deps, the client/server boundary); everything else gets tsc, lint and the touched tests. The full build runs once per batch before release.
Metro: only starts in the worktree whose task needs a device.
Emulator: capped at 2 cores (it was on 4 of 6). Flow runs went from ~193 s to ~151 s average since, small sample but it helped. Next step is exactly what you said: an old Pixel over wireless adb takes the daily flows, and the emulator only boots for baseline screenshots and the newer Android features the old phone can't show.
Lead rotation: kept, and the handover got stricter: five parts, each claim with the command that proves it, and the next lead re-checks before building on it.
Haven't re-measured the queue split since all of this landed, that's the next number I want. Appreciate it.

1

u/SirRobinBlibs 2d ago

If /tmp is tmpfs, parallel agents aren't only competing for CPU. Their tarballs and test artifacts are competing for RAM, and that's often what makes the next build wait.

I'd point TMPDIR at a disk-backed directory per worktree, and keep the flock around the heavy compile or test step, not around the whole session. Light work can overlap; the lock only has to serialize the part that blows up memory.

1

u/ScarcityOrdinary6877 2d ago

Yeah, that matched what I found. /tmp was holding 6 GB of Playwright cache and test output. TMPDIR now points at a disk directory and it dropped to 2 GB. The lock is already per step, not per session: builds and e2e take the slot, tsc and lint run beside them. Per-worktree TMPDIR is a good idea though, makes cleanup automatic when a worktree goes. Thanks.

1

u/SirRobinBlibs 1d ago

Nice, that's a real drop. If part of the 2 GB left is Playwright traces or videos, setting trace (and video) to 'retain-on-failure' keeps only the failing runs' artifacts, which usually shrinks it a lot more.

1

u/ScarcityOrdinary6877 1d ago

Good call, but already there: trace is on retain-on-failure and video is off, so passing runs leave almost nothing behind. What's left in /tmp now is small stuff: some leftover report folders from before the caches moved to disk, and Metro's cache. The big win was the Playwright transform cache and the app-flow output, about 3.6 GB together, and those live on disk now.

1

u/Traditional-Diver160 2d ago

One more angle - I set the depth of the check by risk, not by task. Simple changes (texts/layouts) the agent just rereads, if this is new logic - one independent review, and only things that can delete or damage user files get the full review. And my agents do not build or run tests without my explicit go-ahead (this is a strict rule).

2

u/ScarcityOrdinary6877 2d ago

Good point on risk over task type. Our review depth is set by the kind of change right now (copy/style gets a reread, new logic one independent review, new screens and DB changes the full set), and your comment made me realise a two-line fix in account deletion or billing still gets the light path. Adding a risk tag on top: anything that can delete user data, move money or can't be undone gets the full review regardless of size.

The no-build-without-go-ahead rule I'm skipping though. I let runs go end to end without me, so instead I keep the machine sane another way: one shared queue for heavy jobs, the full build only when the change can actually break it, and tests limited to what the change touches. Curious why you went strict there: was it machine load, or agents "fixing" tests to make them pass?

1

u/Traditional-Diver160 2d ago

Btw - you can ask Claude to classify you modules by the severity (or use some othe criterias) and set different rules in clude.md for each. So this can kind of automate this process if the project is big

1

u/ScarcityOrdinary6877 2d ago

That's a nice way to automate it. I already have every source file mapped to an area (it drives which tests run for a change), so I'll put the severity there: each area gets a risk level, and the review depth is picked from the highest-risk area a change touches. Keeps it out of CLAUDE.md, where a rule is a request; here it's enforced by the pipeline. Thanks, this was useful.

1

u/vladmvp 1d ago

If you want the projects to stop competing for those 6 cores, you could move the heavy sessions to Cobalt (cobaltcode.ai), which gives each task its own persistent cloud computer, so a Next.js build in one project doesn't slow down another. You can keep using Claude Code with your Anthropic API key, and it can run Playwright checks and show a live preview of the app when you review. The flock idea above is a good cheap fix if you'd rather stay on the one server. There's a free account to try it, and I'm the founder, so happy to help you get started.

1

u/ScarcityOrdinary6877 1d ago

Thanks, appreciate the offer. I'm going the other way for now: the queue fixes took most of the contention out, and a bigger box is on order, so everything stays on one machine I own. Keeping the code, the test stack and the keys local matters to me too. Good luck with it.

1

u/Seerix 2d ago

Im making a game with bevy so uh.... I wait a lot

1

u/PilotLost404 1d ago

Batch the checks. Per task, run only type check, lint and the tests the change touches. Run the full suite and e2e once before merge. Full checks on every task are why you spend 5.6 of 8.8 hours in the queue. Cut the number of agents running at once before you buy more RAM, since two builders plus an emulator is already past what 15 GB handles.

1

u/No-Drawing9451 1d ago

I can't speak to the emulator side, but two things helped on the queue.

I wouldn't run more than 3 or 4 agents at once on a machine like that, even if the queue can hold more. Past that I can't actually look at what came back overnight.

And I don't let a builder take a test slot just because it said it finished. I check whether it touched the files I expected. If the change set is wider than the task, I send it back before it sits in the queue for hours.

1

u/vr6wannabe 17h ago

full disclosure i'm the founder of groundbox. we make sandboxes for agents, so each session can send its builds and tests to its own vm instead of all of them fighting over your 6 cores

https://groundbox.dev/docs/sandboxes