TL;DR: To run multiple Claude Code agents in parallel, give each session its own git worktree (claude -w <name> does it in one flag), send the sessions you are not watching to the background with claude --bg, and pick the merge order before the agents finish, because isolated branches still collide when they land. Two sessions sharing one checkout is how one agent’s commit ends up carrying the other’s half-written code. This guide is for developers already on Claude Code who want two to five sessions going at once.
It starts with a second terminal. Claude Code is refactoring the auth module in the first one, so you open another and ask a new session to fix the flaky date test. Then a third for the docs. Twenty minutes later three sessions are writing to one working directory, git status lists files you don’t remember asking for, and nobody can say which session touched config.ts.
Running multiple Claude Code agents is easy: open more terminals. Running them without the sessions corrupting each other’s work takes three decisions: where each session’s files live, how you follow the sessions you are not looking at, and in what order their branches land. This post covers all three with Claude Code’s built-in commands and two failures we reproduced on a toy repository. If worktrees are new to you, read our guide to git worktrees with AI coding agents first, or the git worktree reference.
Why multiple Claude Code agents break a shared checkout
Running multiple Claude Code agents in parallel means two or more sessions working on the same repository at the same time, each with its own task and its own context window. The sessions don’t know about each other. Each one reads files, edits them, runs the tests and commits as if it were alone.
A checkout has one working directory, one index and one HEAD, so “as if alone” fails quickly. We reproduced the most common version on a toy Python repo, with two shell writers standing in for the agents. Agent B has saved a half-written truncate() to textutils.py. Agent A finishes its own task in a different file and commits the way many prompts tell it to, with git add -A && git commit:
$ git show --stat --format='%an: %s' HEAD
agent-a: add slugify
slug.py | 2 ++
textutils.py | 4 ++++
2 files changed, 6 insertions(+)
$ python3 -m pytest -q
1 error in 0.09s
Agent A’s commit carries agent B’s unfinished function, and the test suite no longer imports. Nothing was overwritten. The index was shared, so A’s commit swept up B’s work in progress, and the history now says agent A wrote broken code. The same-file version of this problem is covered in what happens when two coding agents edit the same file.
Run multiple Claude Code agents with one worktree each
The fix is one working directory per session, and Claude Code ships it as a flag:

# interactive sessions, one task each, each in its own worktree
claude -w auth-refactor
claude -w flaky-date-test --tmux # opens the session in its own tmux or iTerm2 pane
# fire-and-forget work: starts in the background and prints an id
claude --bg "update the README examples for the new config format"
Per the worktrees documentation, claude -w <name> creates a worktree at .claude/worktrees/<name>/ on a new branch called worktree-<name>, and a second terminal with a different name gets a second isolated session. When we ran it, git listed the new worktree as locked, which keeps git worktree prune from deleting it underneath a live session. Background sessions started with --bg or /bg move into their own worktree under .claude/worktrees/ before they edit anything, according to the agent view page.
Three setup details save an afternoon:
- Ignore the folder. Worktrees live inside the repo, so
git statusin the main checkout shows.claude/as untracked until you add.claude/worktrees/to.gitignore, which the docs also recommend. - Expect a fresh checkout. A new worktree has no
node_modules, virtualenv or.env. List gitignored files you need copied, such as.env, in a.worktreeincludefile, and budget an install per worktree. - Clean up headless runs yourself. Interactive sessions offer to remove their worktree on exit. Runs started with
claude -pnever clean up, so remove those withgit worktree unlockand thengit worktree remove.
Background sessions are managed from the shell. These descriptions come from claude --help on version 2.1.283:
| Command | What it does |
|---|---|
claude --bg "<task>" |
Starts the session in the background and returns immediately, printing an id |
claude agents |
Opens agent view, the list of running sessions (--json for scripts) |
claude logs <id> |
Prints a background session’s recent terminal output |
claude attach <id> |
Opens a background session in the current terminal |
claude stop <id> |
Stops it; the conversation is kept and claude attach <id> reopens it |
--bg can’t be combined with -p. For a scripted fan-out, Anthropic’s guide to working with Claude Code shows a shell loop over claude -p with --allowedTools and --permission-mode dontAsk. Pair it with -w so each run gets its own directory.
Isolated Claude Code agents still collide at merge time
Worktrees stop sessions from stepping on each other while they work. They don’t make the work compatible. We gave two worktree branches the same kind of change, each appending one function to the end of textutils.py, then merged both:
$ git merge agent/slugify
Fast-forward
$ git merge agent/truncate
Auto-merging textutils.py
CONFLICT (content): Merge conflict in textutils.py
Automatic merge failed; fix conflicts and then commit the result.
Neither agent did anything wrong. Both added code at the same spot and git can’t choose an order. On a real codebase with four or five sessions, this is the normal case for any file that everything touches: route tables, __init__.py exports, changelogs, lockfiles. The difference from the shared checkout is that the collision is now loud, visible and attributable. Three habits keep it small:
- Split tasks by file, not by feature. Two tasks that both need the router are one task, or two tasks run one after the other.
- Merge in a fixed order and rebase the rest. Land the first branch, then tell the next session to rebase on
mainand rerun its tests before you review it. The session that wrote the code has the context to resolve its own conflict. - Name each worktree after its task.
claude -w fix-date-testbeatsclaude -w agent2when you readgit worktree listan hour later.
The real ceiling usually isn’t git. It’s you reading five diffs. Our post on why human review is the bottleneck for parallel agents covers how to size that queue.
Subagents, agent teams or separate sessions for multiple Claude Code agents
Claude Code now has several ways to run work in parallel, and the parallel agents overview lists them side by side. They are not interchangeable. The column that matters most is isolation:

| Option | What runs | File isolation | Use it when |
|---|---|---|---|
| Subagents | Helpers inside one session, each with its own context window | Shared checkout, unless the subagent sets isolation: worktree |
One task needs side research, a review pass or parallel reads |
/batch |
One change split across 5 to 30 subagents | A worktree per subagent | A large mechanical change spread over many files |
| Agent teams | A lead session plus teammates that share a task list and message each other | None: the docs say to partition the work | Teammates need to talk mid-task; experimental, off by default |
Separate sessions (-w, --bg, Desktop) |
Independent sessions | A worktree per session | Independent tasks you review one by one |
Cloud sessions (claude --cloud) |
Sessions in isolated VMs that clone your pushed branch | A VM per session | Work that shouldn’t tie up your laptop |
For independent tasks, use separate sessions with worktrees. Use agent teams when the pieces depend on each other and the teammates need to negotiate, and give each teammate different files, because the agent teams page is blunt: “Two teammates editing the same file leads to overwrites.” Whatever you choose, usage is shared. The agent view docs put it plainly: “running ten agents in parallel uses quota roughly ten times as fast as running one.”
Where Sharkly fits when you run multiple Claude Code agents
If you run two or three sessions on your own laptop and review every diff yourself, the commands above are enough and you may not need Sharkly. The equation changes when the sessions belong to more than one person, or when the question “which session has the date-test fix?” takes longer to answer than the fix took to write.
You already have coding agents. Sharkly turns them into a team. Each piece of work becomes a Task. You assign it to an Agent that runs on the Claude Code Runtime on one of your Computers, and setting the Assignee starts the run. With the default working directory, Create temporary directory, each Task gets its own directory and repository-backed runs get an isolated git worktree: the same isolation as claude -w, without anyone naming worktrees by hand. When an Agent has to reuse an environment already on a local Computer, Run in isolated worktrees delivers each Task’s result on its own agent/<agent>/<task> branch. Max concurrency (assigned tasks) on the Agent caps how many runs go at once, which is the review limit from above, written down where the whole team can see it.
Progress, run history and the result return to the Task, and anything that needs a person lands in Inbox. Nothing merges on its own: a person reviews the worktree changes, keeps, merges or discards them, and sets the Task to Done. Runs still bill against your own Claude Code plan, because Sharkly does not sell tokens. The Agents feature page shows the setup, and how Sharkly runs agents in parallel covers the execution side.
If you’re past three terminals and want every Claude Code session’s result in one place a reviewer can work through, that is the problem Sharkly is designed around.
FAQ
How many Claude Code agents can I run at once? The docs set no cap on separate sessions. Subagents default to 20 running at once, and the agent teams page suggests starting with 3 to 5 teammates. The practical limits are your plan’s usage, your laptop’s CPU and memory, and how many results you can review in a day; the review-capacity math is worth doing before you add a sixth session.
Do parallel Claude Code sessions share my usage limits? Yes. On Pro and Max, usage limits are shared across Claude and Claude Code, with a five-hour window and a weekly limit, and every parallel session draws from the same pool. If ANTHROPIC_API_KEY is set, Claude Code bills the API instead.
Does claude --worktree copy my .env and dependencies? No. Each worktree is a fresh checkout. Add gitignored files you need, such as .env, to .worktreeinclude, and run your install step in each worktree.
Can I run Claude Code and Codex on the same repo in parallel? Yes, with the same rule: one worktree per session and a merge order. Our guide to running Claude Code and Codex together on one codebase covers the routing side.



