r/ClaudeCode • • 18d ago

Tips & Workflows Five ways ten parallel Claude Code sessions broke each other without a single error, and the rule that fixed each

I run about ten Claude Code sessions at once on one 64 GB workstation, one per product. Every collision so far was silent. Nothing errored, and I found the damage later. These are the five that cost me the most.

1. A compose file with no name takes its project name from its folder. Several of my products had a deploy folder, so they all claimed the project "deploy". One session ran docker compose up and it recreated another session's containers, including its Postgres. Fix: a name line in every compose file.

2. A bare -j is unlimited. cmake --build build -j with no number started about 300 compiler processes, used 49 GB and hard-hung the machine. Twice. Fix: always a number, nproc at most.

3. A subagent chasing a slow test killed a test run that belonged to another session, at test 185 of 361. That run was the last check before a go-live. Fix: never stop a process you did not start. Find out whose it is and ask.

4. The shared "who is working on what" table lost entries, because two sessions read it, edited it and wrote it back at the same time. Fix: one claim file per session in a folder. You only ever write your own file, so nothing can be lost.

5. "I searched and found nothing" was wrong. The search tool inside a session skips gitignored files, so .env files and build output were never searched. A test with five planted strings found one. Fix: before removing anything on the strength of an empty search, search again with the real grep, and first search for something you know is there.

What these have in common: each session did something reasonable with what it could see. The rules all live in one global CLAUDE.md, with the date and the incident next to each, because a rule with its reason gets followed and a bare rule gets argued with.

What has bitten you when running several sessions on one machine?

0 Upvotes

14 comments sorted by

•

u/AutoModerator 18d 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.

2

u/bostonaholic 18d ago

Worktrees separate the files, but every one of these is shared runtime state on the machine. I'd give each session a slot number and generate its env from it: COMPOSE_PROJECT_NAME, a port offset, its own database name, and CMAKE_BUILD_PARALLEL_LEVEL capped at nproc divided by the session count. That way the rules live in the environment instead of in ten prompts. For the process killing, a PreToolUse hook could block kill or pkill on any pid that session didn't start.

1

u/Early-Feed2788 17d ago

That is a better shape than mine for the first two. A rule the environment enforces cannot be forgotten, and COMPOSE_PROJECT_NAME from a slot number would have prevented the deleted Postgres outright.

The one place an offset would not cover me is ports: the same ports file also covers the servers, not just this workstation, so a session still has to look a port up before it claims one.

The PreToolUse hook that blocks kill on a pid the session did not start is the one I have not tried, and it is worth doing. Thanks.

1

u/DuskandFuck 17d ago

Blocking pkill with a hook is clever, how are you tracking which pids belong to the current session though?

1

u/bostonaholic 17d ago

I'd record them when they start instead of working it out later. Have the session launch servers through a small wrapper that appends each PID to a file keyed on something the hook can also see, like the slot number or the session_id that PreToolUse hooks get in their input. Then the hook denies pkill and killall outright and only allows kill when every PID in the command is in that file. Launching with setsid also puts each server in its own process group, so you can kill the group instead of chasing child PIDs.

1

u/ClemensLode Senior Developer 18d ago

just use worktrees?

1

u/Early-Feed2788 17d ago

Worktrees solve two sessions editing the same repo. None of these five were that, because each session already has its own repo. The collisions were on things the whole machine shares: Docker's project names, RAM and CPU, running processes, and one notes file outside any repo. A worktree does not separate any of those.

1

u/onitsoga 18d ago

the never-stop-a-process-you-didnt-start rule is the one i keep relearning the hard way. mine is a lock file per session before touching a shared build dir, basically your claim-file fix extended to builds. do you version that global CLAUDE md anywhere, or just append to it?

1

u/Early-Feed2788 17d ago

Not versioned, and you have just pointed at a gap. It is one file, edited in place, about 250 lines.

What stands in for history is in the text itself. Every rule has the date it was added and the incident behind it, and when a rule changes, the change gets its own date and reason, for example "restructured on this date because the single table lost claims". The long write-up of each incident lives in its own file in a knowledge folder, and the rule just points to it. That keeps the main file short enough that sessions still read all of it.

A lock file per session for a shared build dir is a good one. I only have the blunt version: never start a build without a job limit, and use fewer jobs when other sessions are building.

1

u/Excellent-Issue-5956 18d ago

One that got me was a file saved in the wrong folder. My local agent loads every top level .ts file in its extensions folder as an extension, and it won't start at all if one of them doesn't export the function it expects. A subagent from another session that was adding something to the same agent saved a plain helper module in there. For about 10 minutes every new launch failed. A training run stopped, and a benchmark that was running scored 0 out of 10, which had nothing to do with the model, it just couldn't start.

Quick fix was an empty default export in that file. The rule since then is helper modules go in a subfolder without an index file, which it skips.

1

u/wangadong 18d ago

output ownership is the rule that holds mine together, each session writes one file it owns and the main session is the only one that merges. shared outputs are where parallel runs silently eat each other

1

u/norviking 18d ago

I have worked on a very large project for 5 months, and I had to build this:

https://github.com/vegardjorg/ravenseat

It will solve some of your problems: 

  • Individual work trees and parallel agents handled

  • Merge handling

  • System load handling, ram, cpu etc. And allocate tasks tracks intelligently so you dont fry your hardware or mess up your tests.

  • Full control of project state outside agents "trying" to remember what you want, and compacting away the details. 

  • Options to control it the way you need. 

It will also try to help with gates, probes, ci to ship safe code. Feel free to ignore if you have that handled. 

1

u/gptrv 17d ago

A sixth if any of them drive a browser: Playwright MCP keeps one persistent Chrome profile by default, so the second session that tries to open it fails with "Browser is already in use". Start it with --isolated (an in-memory profile per session), or give each session its own --user-data-dir in its .mcp.json. Same idea as your compose names: anything with a default location on disk is shared state.

1

u/heyramzi 16d ago

Your #2 got me with search instead of cmake. Three subagents started the same local search tool within 30 seconds. It loads its own models, so each one sat at 2.8 GB for 10 minutes, and the 24 GB Mac ran out of memory and kernel panicked.

The fix was a wrapper that queues heavy jobs across the whole Mac. Builds, tests, typechecks and that search share 3 slots, and a job it has measured over 1.5 GB takes 2 of them.

Then the agents started killing their own runs. A test waiting for its slot looks hung, so the session kills it and starts it again, and the rerun goes to the back of the line. Now I make them check the queue first.

Generated files bit me too. A lockfile or a translation catalog gets rewritten whole on every save, so two agents editing the same one drop each other's entries. One save wiped 5 strings another agent had just added. Now one agent owns that file and the others hand it their strings.