DeepDojo.AIPublished 2026-11-15中文
Managing Multiple Claude Code Sessions at Once
Docker is building an image, a CI pipeline is running remotely, and a long local test suite hasn't finished. You watch the logs scroll by, afraid of missing something. Meanwhile, the Claude Code task in another tab stopped a while ago and has been waiting for your approval.
When several things run at once, the mess usually comes from two layers:
- You: there are too many tasks to track, and you lose track of which window is doing what and which one is waiting on you.
- Files and resources: several sessions edit the same working tree, or two processes fight over the same port or test database.
Each layer needs its own tool. Tabs tell you what each task is doing. Git worktrees keep different branches' files from overwriting each other. Ports and test databases still need to be divided up separately.
While long tasks run, slow your checks down: wait 1, 2, 4, then 8 minutes between looks, and save your attention for success, failure, and the moments that actually need you. When you step away from the computer, Remote Control lets you check progress and approve requests from your phone. Disconnect it when you're done.
01 Tabs Track the Work, Worktrees Separate the Files
Terminal tabs help you keep track: older tasks on the left, newer ones on the right, one goal per tab, and the tab title naming that goal. Three or four main tasks is a reasonable starting point. If you can't keep up, run fewer, and close tabs as tasks finish.
Git worktrees isolate files and branches. As the Git documentation puts it, one repository can have multiple working trees, each with a different branch checked out:
One repository
├─ my-app/ main
├─ my-app-feature-a/ feature-a
└─ my-app-bugfix-b/ bugfix-bEach directory has its own working tree, and you can open Claude Code in each one. You can have Claude Code create it:
Create a Git worktree from this repo for the `feature-a` branch, in a sibling directory named `my-app-feature-a`.List and clean up worktrees:
git worktree list
git worktree prunegit worktree list shows which directory holds which branch. git worktree prune removes stale administrative records; it doesn't save any work for you, so make sure the work in a worktree is safely stored before cleaning up.
The two jobs don't swap:
Tabs: tell you what each task is doing
Worktrees: keep different branches' files from overwriting each other02 Separate Directories Still Share Ports and Databases
A worktree only separates files; backups and system isolation are separate jobs. Commit important changes or save them some other reliable way. Processes in different directories can still connect to the same database or grab the same port.
Say you have two Claude Code sessions in two worktrees, one fixing the frontend and one the backend. The files really are separate. But when both run npm run dev at the same time, both try to grab port 3000. Both test suites also write to the same default PostgreSQL test database.
Errors at this point may come from the two sets of processes competing for local resources, so check ports and the test database first. Splitting directories is only step one. Before starting, assign shared resources like port numbers, database names, and test caches to each side, for example ports 3000 and 3001, and then let each one run. A worktree only separates files; processes can still reach the whole machine. When you need system-level isolation, see whether running Claude Code in a container is safe enough.
Large changes can go to /batch:
/batch <instruction>It researches the codebase, splits the work into independent units, and shows you a plan. Once you approve, a background subagent implements each unit in its own worktree, runs the tests, and then opens a PR or reports what happened. So before using it, make sure pushing and opening PRs fall within what you've authorized.
Before running in parallel, also confirm which files each unit owns, how each is verified, and who will merge and review at the end. If two units both need to change the same core file, agree on the order for that part first.
03 Stretch the Wait Between Checks
Watching scrolling logs while Docker builds, CI runs, or long local tests grind on is wasted attention. If nothing urgent is waiting, slow down and use exponential backoff, stretching the interval each time:
1 minute → 2 minutes → 4 minutes → 8 minutes → keep stretching as the task allowsGive Claude Code a clear checking protocol:
Don't watch continuously. Check status at 1, 2, 4, and 8 minutes, reading only the summary each time.
If you see a clear failure, or the same error twice in a row, analyze the cause. If a query times out, re-check the same run instead of starting another.
When it succeeds, summarize the duration, key output, and next step.Check GitHub Actions from time to time:
gh run view <run-id>Look at just the job you care about:
gh run view <run-id> | grep "<job-name>"gh run watch streams output continuously; use it only when you really need live updates. When CI finishes with a failure, debugging CI failures with Claude Code walks through the four layers of investigation.
04 Send Long Commands and Whole Sessions to the Background
While a long local command runs, press Ctrl+B to move it to the background, then check progress with /tasks. In tmux, Ctrl+B is tmux's prefix key, so press it twice.
You can move the whole session to the background too:
/backgroundThe current session keeps running as a background agent and frees this terminal. To see and manage all background sessions in one place:
claude agentsIt opens an overview that lists sessions that are running, waiting for your input, or done. Builds, tests, deployment checks, data processing, and downloads all suit the background, but they still need a checking rhythm and stop conditions.
05 Parallel Analysis With Background Subagents
Large-scale analysis can be split across several background subagents, for example one each for the frontend, backend, and test directories:
Start 3 subagents to analyze the frontend, backend, and test directories.
Each one handles only its own directory and reports key findings, evidence, and open questions. Combine the results at the end.When assigning, also spell out the number of agents, the model, foreground or background, the file scope, and what counts as done. If a shared file needs changes, decide in advance who handles it. Background tasks still use resources and quota, and the main session has to check and combine every report.
06 Follow Along With Remote Control When You Step Away
When a long task is running and you need to leave your desk, Remote Control lets you view and drive the running session from your phone or a browser. Turn it on inside an existing session:
/remote-controlThe short form /rc works too. It's useful for checking status, adding a few instructions, or approving permission requests while a long task runs. Once your phone connects, the task still runs on your computer, so the local process, the network connection, and the machine itself all need to stay up.
The Claude Code Remote Control docs list the requirements: you sign in with a claude.ai subscription account, and setups such as API keys, Bedrock, Vertex, and Microsoft Foundry aren't supported. On Team and Enterprise plans, an admin has to turn the feature on first. Long-lived tokens from claude setup-token can only make model requests, so they can't open a Remote Control session either.
If you want every session created remotely to get its own working directory, start a server:
claude remote-control --spawn=worktree --capacity=N--spawn=worktreegives each on-demand session its own Git worktree. It needs a Git repository.--capacity=Ncaps the number of sessions running at once. SetNto what you can actually track.
When the server starts, it pre-creates one session in the current directory. That one isn't in its own worktree, so tell it apart from on-demand sessions when you check. With alias cr='claude remote-control' set up, cr --spawn=worktree --capacity=N works too.
Remote Control doesn't open any inbound ports on your machine. The local process only makes outbound HTTPS connections to Anthropic's servers, which relay messages to the web or mobile client. The risk comes from the session still running on your computer: it can reach local files, project config, MCP servers, and tools.
Before turning it on, confirm five things:
- You're signed in to the right account.
- This session and project are fine to continue remotely.
- You know which files, MCP servers, and credentials the machine exposes.
- The network and devices are trustworthy.
- Someone is responsible for closing the session when the task ends.
When you're done, run /remote-control again in the terminal session to disconnect. Stop a standalone claude remote-control server with Ctrl+C. Wait until the terminal shows it disconnected or exited before you consider the remote session over.
Say you check a long refactor from your phone and approve a few permission requests. Back at your desk, the remote connection may still be open. When the task ends, check for remote connections you no longer need and close them. A remote session can reach your machine's resources, and logged-in devices and browser sessions need managing with the same care.
07 Pick the Parallel Setup by Need
The right setup depends on what you're trying to solve:
| Need | Tool |
|---|---|
| Track several independent tasks yourself | Tabs |
| Edit files on several branches at once | Git worktree |
| Free the foreground from one long command | Ctrl+B |
| Move the current session to the background | /background |
| Change a large task in parallel units | /batch with worktrees |
| Analyze several independent areas at once | Background subagents |
| Keep following along after leaving your desk | Remote Control |
With this in place, the image build, the pipeline, and the tests each get a summary check on their own schedule. The session waiting for you shows up in the claude agents list, and you can handle it from your phone if you're away. The limit on parallel work is how many tasks you can clearly track, and every task needs a checking rhythm and a confirmed end.