Claude Code

Claude Code parallel agents: subagents and worktrees, step by step

How to run Claude Code agents in parallel: subagents inside one session and separate sessions on git worktrees, without file clashes.

Running more than one Claude Code agent at a time can mean two different things. One is letting Claude split a task across subagents inside a single conversation. The other is opening several independent sessions on the same repository, each handling its own job. The official Claude Code documentation covers both, and each has its own way to keep agents from getting in each other’s way.

What running Claude Code agents in parallel means

Before picking a path, it helps to separate the two models:

  • Subagents: specialized helpers Claude calls from inside a session. Each one handles a piece of the work in a context of its own and hands a summary back to the main conversation.
  • Parallel sessions: two or more claude instances in different terminals, each with its own conversation. To keep them from editing the same files, the documentation points to git worktrees.

The Claude Code subagents page makes it clear that subagents live inside one session. For many independent sessions, the same page links to other features: background agents, for watching parallel sessions from a single place; cross-session messaging; and agent teams, where Claude starts and supervises a group of sessions. This guide sticks to the two most common paths: subagents and worktrees.

Subagents: several agents inside one session

According to the Claude Code documentation, every subagent gets a separate context window, its own system prompt, a defined set of tools and independent permissions. When a task fits a subagent’s description, Claude hands the work over, and only the result comes back to the main conversation.

That fixes a practical problem: digging through a large codebase fills your context with file reads you will never look at again. With a subagent, that reading happens outside the main conversation.

Claude Code ships with a few ready-made subagents, per the official page:

  • Explore: read-only, built for finding files and analyzing code. Write and Edit are blocked.
  • Plan: also read-only, used in plan mode to collect context before Claude proposes a plan.
  • General-purpose: can use all the tools open to subagents and fits multi-step tasks that mix research and code changes.

To use one, just ask in plain language. A request like “use a subagent to find where this project validates the session token” makes Claude start a subagent, read the files in that separate context and bring back only the conclusions. The common workflows page in the documentation shows this same pattern for delegating research.

How to create your own subagent

When you keep asking for the same kind of helper with the same instructions, the documentation suggests turning it into a custom subagent. The format is a Markdown file with a YAML header.

  1. Pick where to save it. In ~/.claude/agents/, the subagent is available in all your projects. In .claude/agents/ inside the repository, it applies only to that project and can go into version control so your team shares it.
  2. Write the file, or ask Claude to write it. A minimal example:
---
name: test-reviewer
description: Runs the test suite and sums up the failures. Use after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You run the project tests, read the failures and explain the likely cause of each one, without editing files.
  1. Call it by name. For example: “use test-reviewer to check what broke in the api folder”. According to the documentation, the delegation shows up in the transcript as a row with the subagent’s name and a short description of the task.

A few details from the official page that save trouble:

  • The description field is what Claude reads to decide when to delegate. Keep it direct.
  • The tools field limits what the subagent can do. A reviewer does not need Write or Edit.
  • The model field lets you send simple jobs to cheaper models such as Haiku, which the documentation lists as a way to keep costs down.
  • To try a subagent without saving anything, the --agents flag takes the definition as JSON when you launch claude, and it only lasts for that session.

How to run parallel sessions with git worktrees

Subagents help inside one conversation, but they do not replace two sessions working at once, say one on a new feature and another fixing a bug. If both run in the same folder, one can overwrite what the other just changed.

The common workflows page in the Claude Code documentation solves this with git worktrees. Each worktree is a separate working copy on a branch of its own, created from a commit that already exists. Step by step:

  1. Make sure the repository has at least one commit.
  2. In the first terminal, inside the project, run:
claude --worktree feature-auth
  1. In a second terminal, run the same command with another name:
claude --worktree fix-login
  1. Work in each session as usual. Since each one has its own copy and branch, the edits stay apart.
  2. When you are done, review and merge the branches like any other git work.

The official worktrees page explains how to clean up the copies and how the .worktreeinclude file works. To pick a session back up later, claude --continue opens the latest one in the folder and claude --resume shows a list to choose from.

Subagents or worktrees: which to use

Situation Best path
Searching the code without filling the conversation context Subagent (Explore or your own)
Reviewing, testing or analyzing with fixed, repeated rules Custom subagent with limited tools
Two tasks that edit code at the same time Separate sessions with --worktree
Long jobs you want to follow on their own Separate sessions, each on its own branch

The two paths work well together: each session in a worktree can still call its own subagents.

Common mistakes with parallel agents

Two sessions editing the same files. Opening two claude instances in the same folder without a worktree is the most frequent mistake, and the edits can collide. Use --worktree with a different name in each terminal.

Creating a worktree in a repository with no commits. As the documentation explains, a worktree is built from a commit that already exists. In an empty repository, the command stops with an error saying it could not find the base branch. Make a first commit before you start.

Assuming subagents don’t use your limit. The Claude Code subagents page explains that every subagent makes its own calls to the model, and all of them are charged against the same plan limits that your main conversation uses. Many subagents at once drain your plan faster.

Filling the context with descriptions. The descriptions of all your subagents take up context. Per the documentation, once the descriptions of your custom subagents add up to more than 15,000 tokens, Claude Code displays an alert when it launches. Keep descriptions short and move the detail into the body of the file, which only loads when the subagent runs.

A new subagent that doesn’t show up. If ~/.claude/agents/ did not exist when the session started, the running session won’t notice the new folder. The documentation recommends restarting Claude Code and trying again.

Duplicate names. Two files with the same name in the same folder make Claude Code load only one of them, with no guaranteed order. According to the official page, /doctor flags these cases.

How to keep track of many agents at once

With subagents and several sessions running, the hard part becomes knowing what each one is doing. In the terminal, every session sits in its own window, and subagents show up as rows in the transcript.

Ramo is a desktop app for Linux, Windows and Mac (Apple silicon, in testing) that drives the Claude Code already installed on your computer, with your settings. When you pick a session, it shows every subagent that session launched in a live graph, with its status (running, stopped or done), last tool used, tokens and the report it returned. From there you can stop a subagent, relaunch it with another model or use its report as context.

Other things that help here:

  • You can open several new sessions at once, and sessions open in the terminal also show up in the sidebar and in the graph. While a session is open somewhere else, Ramo’s chat stays read-only so two conversations don’t mix in the same history.
  • Every conversation has a context meter, and the usage view shows your plan limits.
  • If you use more than one Claude account, Ramo can switch accounts on its own when one hits its limit, if you turn that option on.
  • Ramo also runs Codex and OpenCode, and one agent can hand a task to another.

Ramo has a 7-day free trial with no credit card. After that, the lifetime license costs US$ 19 as a one-time payment. Ramo is not an Anthropic product.

Frequently asked questions

How do I run two Claude Code agents at the same time on one project?

Open two terminals and run `claude --worktree` with a different name in each. According to the Claude Code documentation, every worktree is a separate copy on its own branch, so one session's edits don't touch the other's.

What is the difference between a subagent and a parallel session in Claude Code?

A subagent runs inside one session, with its own context, and returns a summary to the main conversation. A parallel session is a whole separate conversation in another terminal, ideally running in its own worktree.

Do Claude Code subagents count toward my usage limits?

Yes. The Claude Code documentation says each subagent makes its own calls to the model, and they are charged against the same limits as the main conversation.

Where do Claude Code subagent files go?

In `~/.claude/agents/` to make them available in all your projects, or in `.claude/agents/` inside the repository for that project only. Each subagent is a Markdown file with a YAML header.

Why does claude --worktree fail with a base branch error?

According to the documentation, a worktree has to start from an existing commit, so in an empty repository the command can't find a base branch and stops. Make a first commit and run it again.

How can I see the subagents of a Claude Code session?

In Ramo, pick the session from the list: it shows every subagent the session launched in a live graph, with status, last tool used, tokens and the report it returned.

Sources

Keep your agents in view.
Start here.

Download it and use it free for 7 days, no credit card. Then a lifetime license for US$ 19, one-time payment.

Read next