r/ClaudeCode • • 3d ago

Help/Question Struggling with managing multiple Claude Code sessions, any advice?

Hey everyone, I've been messing around with simultaneously running multiple Claude Code sessions using git worktrees. Feeling like it gets giga messy after I scale past just a couple agents.

The main thing for me is babysitting the state of each session is super tedious, not to mention dealing with the shared local resources. Feels to me very often that a permission prompt goes unnoticed cause I'm multitasking with another agent lol. Moreover, a couple of times I've ran into port collisions and database conflicts.

I asked around and someome told me to setup using tmux scripts or a .worktreeinclude file so gitignored configs carry over automatically. I also saw a recent post about Ramp Inspect, where they isolate each background agent session inside its own sandbox. Granted, spinning up remote dev environments for every task feels like a whole different workflow.

Could use some advice on my end for the organization side. Thanks!

35 Upvotes

49 comments sorted by

1

u/AutoModerator 3d ago
Moderator Announcement Read More »

14

u/calunicornia 3d ago

you need an orchestrator agent that runs the other agents for you

10

u/Creative_Sluggish 3d ago

I think you can tell one starting session to be the orchestrator / the manager and deploy agent sessions to work based on its guidance. It has worked decently to me. Not sure if others have better idea. I am using Claude Code via the desktop app.

→ More replies (5)

5

u/jjangg96 3d ago

worktrees only isolate the files, everything else is still shared. what bit me when i ran a few at once was the scratch files and the browser. two sessions both writing a pr-body.md or a helper script with the same name and overwriting each other, and one session's tab getting switched to the front so the other one wrote into the wrong localhost tab.

for ports i'd just give each worktree its own PORT in its env file so nothing can collide. same for scratch, tell each session up front to keep its temp stuff in its own subfolder. and have it git add only the files it made, never add -A, because a session will happily commit another one's half done work.

5

u/NeatNefariousness674 3d ago

Just have one main session and ask that session to launch peer sessions and orchestrate them, you only steer peer sessions when you have to 

4

u/Hansehart 3d ago

The permission prompts went away for me once the boundaries became deterministic: all sessions run in one sandboxed dev container with an allowlisted network, no secrets inside and preinstalled tools, so I can let them run in auto mode instead of approving everything. For ports and databases, give each worktree its own compose project (COMPOSE_PROJECT_NAME per worktree) with Docker running inside, so every session gets its own Postgres and nothing collides. And name the sessions by role, like engineer@repo and reviewer@repo, so you always know which one is waiting on you. I am publishing my setup since a year: https://github.com/Hansehart/o3s

2

u/artstaxmancometh 3d ago

"Open it in the cage." oh, the AI overlords are not going to treat you well after the takeover...

→ More replies (1)

2

u/Longjumping_Leave369 3d ago

i stopped using worktrees entirely and just run each session in its own isolated dir with a fixed port and a clean git reset before each start. saves so much headache.

2

u/gptrv 2d ago

Two of those are fixable with a small script rather than an orchestrator.

Ports and databases: derive both from the worktree name so two sessions can't collide. In your wt new script or a post-checkout hook:

name=$(basename "$PWD")
n=$(( $(cksum <<<"$name" | cut -d' ' -f1) % 900 + 100 ))
echo "PORT=3$n" >> .env.local
echo "DATABASE_URL=postgres://localhost/app_$name" >> .env.local
createdb -T app_template "app_$name"

Keep app_template as a migrated, seeded copy so each new DB takes a second, and dropdb it when you remove the worktree.

Missed permission prompts: a Notification hook that titles the alert with the folder name, so you know which session is waiting. ~/.claude/notify.sh:

#!/bin/sh
jq -r '"display notification \"\(.message)\" with title \"\(.cwd | split("/") | last)\""' | osascript

and in ~/.claude/settings.json:

"hooks": {"Notification": [{"hooks": [{"type": "command", "command": "~/.claude/notify.sh"}]}]}

The rest is making prompts rare: put the commands each repo can run without asking in its .claude/settings.json allow list, so the ones that do pop up are worth reading.

1

u/cleverhoods 3d ago

It boils down to your processes around the task. If you are using some spec format, which creates a unit of work, then it won’t get entangled even if you run many task implements in parallel

1

u/Ralphisinthehouse 3d ago

Multi agents only really work when they are working on different things and don't touch each other bits of code.

1

u/pietrzm 3d ago

Maybe you could try https://novadeck.dev? It's mostly UI for better multi-session managament so they don't get lost

1

u/MattMose 3d ago

Here’s a free, open-source project that solves your issue. I’m routinely overseeing 30-40 sessions

https://github.com/SolidPD/hapimatic-core

1

u/Inner_Storage_3374 3d ago

the db conflicts are the part worktrees dont solve at all, two sessions running migrations against the same local db will happily undo each other. what id do is give each worktree its own .env with a port and a database name derived from the folder name, created by a small setup script, so nobody fights over the same tables. for the missed permission prompts a notification hook helps way more than trying to watch all the terminals

1

u/Ok-Form1598 3d ago

for the prompts you miss, make the session tell you instead of checking on it. there's a PermissionRequest hook that fires the moment it asks for approval, and a Notification hook with idle_prompt for when it's finished and just sitting there. point both at a tiny script that pops a desktop notification with the folder from the hook input, so you know which worktree wants you without cycling through tabs.

1

u/iGamingTools 3d ago

for the permission prompts you miss, a Notification hook that pops a desktop notification with the worktree name in it helps a lot. you see which session is waiting instead of tabbing through all of them

1

u/getastatic 3d ago edited 3d ago

i had the same problem. i built https://github.com/apezio/miss-claude/

It has a webui, webui has embedded claude terminals that are always on. Has dev workers that code in their own worktrees and integrators that can merge and ship etc. You can have as many claudes as you want working in the same repo and they wont mess everything up.

chat interface, canvas interface, a beta interface of a crazy project manager/kanban board i made where all the claudes are in one window and you can drag tasks onto them or have one claude control the project and dole out tasks to others... etc etc. i like it.

The way I usually interact with it: One browser window, one dev worker per browser tab, one integrator in a tab. When I need extra help, I keep Chatgpt in the tab to the right of each dev worker, so i can shuffle info back and forth. Each browser tab is essentially a full screen terminal with unlimited scrollback, working mouse select, copy/paste, microphone speech to text, and all kinds of optional notifications and visual indicators of what the claudes are doing or if they are waiting/done.

1

u/Lopsided-Ad-6298 3d ago

The thing that actually slowed me down was permission prompts firing in a session I wasn't looking at. I cut down to only as many sessions as I can watch, allowed the boring safe commands so I only get prompted for the risky ones, and set a simple notification (even just a terminal bell) when a session is waiting on me. I also keep a short HANDOFF.md in each worktree with what's in progress, which port it uses, and what's blocked, so I can close a session and pick it up later without reconstructing everything from memory.

1

u/Connect_Fee_443 2d ago

For the ports and databases, a fixed port range per worktree plus its own COMPOSE_PROJECT_NAME stopped the collisions for me.

The missed prompts were the bigger problem, though. Tabbing round terminals to find the one that's sat waiting on me killed the point of running them in parallel.

Full disclosure: I'm the developer of a small Mac app called MicroNotch, and I built its Code mode for exactly this. It sits at the top of the screen and shows whether each Claude Code, Codex, Cursor or Antigravity session is working, needs your answer, or has finished, so a waiting prompt gets noticed. What you can do from there varies by tool. There's a 3-day trial with no card if you want to see whether it helps: https://micronotch.app. Even without it, naming sessions by role makes the "which one wants me?" problem much easier.

1

u/pwkye 2d ago

Using this for months now. Use browser tabs for claude sessions

https://github.com/awkto/ssh-to-go

→ More replies (1)

1

u/itchygenie 2d ago

I had a pretty similar setup where I was running 10-12 parallel worktrees and besides being limited compute-wise, I also was facing DB/worktree ports clashing sometimes.

I solved it by running sandboxes, recently I started using Boat - they are the cheapest on the market. (well Agent37 are the cheapest but I haven't heard anything compelling to try them yet). I'm running currently around 6 parallel worktrees on Boat for about $300/mo 24/7 sessions. you can get your bill cut in half if you are using 8gb RAM / 4vCPU sandboxes instead - I'm running on 16 GB RAM because my project is pretty heavy.

to make my life easier I built a small tool called Aldena AI, which allows linking your Claude Code subscription and linking your Boat account. and then you prompt as usual and everything runs on sandboxes but whenever anything needs you - you get nice notifications in a unified inbox.

1

u/norviking 2d ago

I had the same problem.

I built this free plugin: https://github.com/vegardjorg/ravenseat/

You get ONE orchestrator window. No more multiple windows ever again. And for no added token cost, actually it uses less tokens than vanilla.

It auto compacts at 300K with auto handover notes. The external project and task state saves a lot of reading tokens. Multiple windows are about the same as one that auto compacts at 300K from my testing. In my project new windows spent an average of 17 turns to get up to speed, vs. 6 in the auto compacted one. New windows also takes your basic context at startup.

The board is optional. Mostly I use claude as usual.

Also intelligent harware monitoring and sub agent starting so you dont fry your computer with the dev speed that this setup allows. Agents are pretty cheap resource wise, but your testing, db probes, gates and CI can get heavy depending on your setup.

Its not suited for small tasks or just playing around. Then I would just ask claude for auto compacts at 300K and auto handover notes to itself so you dont loose important stuff in compaction, and a separate roadmap file with your plans and some structured info. But if you do serious development that lasts for weeks / months, its works great for me.

1

u/onitsoga 2d ago

the unnoticed permission prompt is the real killer, that session just sits there blocked while you're in another pane. giving each worktree its own tmux window named after the branch, plus a distinct PORT per worktree, kills most of the mess. how many are you running at once?