skip to content

multiple claude code instances on one repo.

published

you can run multiple Claude Code instances on one repository at once: Claude Code’s docs name no limit on terminal sessions. give each a worktree with claude --worktree <name>. before your agent edits a file a teammate’s Claude Code, Codex or Cursor agent changed in the last 30 minutes or on an unmerged branch, agentmash tells it who and when.

how many claude code instances can you run?

no fixed number for the terminal sessions you start yourself. Claude Code’s docs, checked on 2026-10-16, name no limit on how many of those run at once. some of the features that run sessions or agents for you have caps of their own, listed below. the docs do state the cost. the page comparing the parallel approaches notes that running several sessions or subagents at once multiplies token usage, and agent view’s docs estimate that ten background agents use quota about ten times as fast as one. each session sends its own requests, counted against the plan or API account it’s signed in to.

the other numbers the docs state:

on a Pro, Max, Team or Enterprise plan, /usage breaks recent usage down by skills, subagents, plugins and MCP servers (costs). the breakdown is computed from session history on that machine, so a second laptop’s sessions aren’t in it.

what goes wrong with two sessions in one checkout

opening a second terminal and running claude in the same folder works, and for reading (a review, a question about the code) it’s fine. both sessions share one working tree, one index and one checked-out branch, so once both write, each can edit files the other is changing.

how to run multiple claude code sessions in parallel

give each session its own worktree. a git worktree is a second working directory of the same repository, with its own files and its own branch, sharing one history. Claude Code makes one for you:

claude --worktree feature-auth

-w is the short form. per Claude Code’s worktree docs, the worktree goes under .claude/worktrees/feature-auth/ at the repository root, on a new branch named worktree-feature-auth. run the command again with another name in a second terminal for a second isolated session, or leave the name out and Claude picks one. in an interactive session, in a folder where you haven’t run Claude Code before, --worktree exits with an error until you run claude there once and accept its trust prompt (worktrees), and in a repository with no commits yet the command fails (common workflows).

three details from the worktree page that matter when several sessions run at once:

a new worktree is a fresh checkout, without .env or installed dependencies unless you bring them in: what a worktree leaves out covers .worktreeinclude and the rest, and what happens to it when the session exits.

keep your linters and pre-commit hooks out of .claude/worktrees/ too. in #40850 (March 2026, Claude Code 2.1.87), a session in the main checkout hit a pre-commit hook that tripped over a config file inside .claude/worktrees/, called that worktree stale and deleted it while another session was working in it. the worktree docs say Claude Code locks a running subagent’s or background session’s worktree with git worktree lock; a lock stops git worktree remove, not an rm -rf like the one in that issue.

the desktop app has a worktree option next to the branch name when you start a session. in a git repository, a session you dispatch from agent view (claude agents, a research preview) moves into a worktree of its own before it edits files, unless worktree.bgIsolation is set to "none".

subagents vs separate claude code sessions

subagents are workers inside one session: Claude hands one a side task, it works in its own context window, and only its summary comes back, its requests counted toward the same usage limits as the main conversation. use them to keep one session’s context small, and separate sessions, each in its own worktree, for pieces of work you steer yourself.

agent teams and cross-session messaging

agent teams, experimental and off by default, let one lead session spawn teammates, separate Claude Code instances that share a task list and message each other; teammates don’t get worktrees, so the agent teams page asks you to give each one its own files. cross-session messaging, in Claude Code v2.1.224 or later (v2.1.234 on native Windows), lets Claude list and message your other Claude Code sessions, on this machine or, through Remote Control, on your other machines (cross-session messaging). both stay with one person’s sessions: can claude code sessions talk to each other? covers whose sessions a message reaches and what it carries.

claude code on multiple machines, across a team

in every approach on Claude Code’s parallel-work page, the workers are Claude sessions, and the two features above that coordinate them stay with one person: cross-session messaging reaches the sessions you run yourself, and an agent team lives inside one lead session.

on a team, alice runs two Claude Code sessions in worktrees on her laptop, bob works in Codex, carol in Cursor, all on the same repository. each worktree is a clean checkout on one machine, and none of them knows what a teammate’s session is changing until someone pushes and someone else pulls or merges. with everyone isolated properly, three things still go wrong:

what agentmash adds for teammates

agentmash gives each repository one room. hooks in each developer’s coding agent report its edits there, and every worktree of the repository reports to that same room, each on its own branch. agentmash compares each developer’s edits with their teammates’, never with their own.

before an edit, your agent is told when a teammate’s agent changed the same file: within the last 30 minutes by default, or on a branch of theirs that isn’t merged yet, which the room remembers by person, branch and file for up to a week, until it merges. Cursor’s adapter hears less of that memory: only work from the last 48 hours by default, on a branch the Cursor user hasn’t worked on, in a file they haven’t changed since. in JavaScript and TypeScript it also warns about the break across files. when a teammate’s Claude Code agent changed an exported createUser within the same 30 minutes, your agent is told before it edits a file that imports it, whatever directory that file is in. the week-long branch memory is by file, not by name, and a change made in Codex or Cursor is matched by path only.

the advisory is worded mostly by where the teammate’s change is. on another branch, or in a clone of their own, it’s PARALLEL EDIT: there’s nothing to re-read, so the agent is asked to keep its edit additive, not to reformat or reorder, and to name any divergence in its reply. in the same checkout, a change from the last five minutes is ACTIVE COLLISION, or STALE READ once the teammate has gone, and the agent is asked to re-read the file before it edits; an older one is RECENT EDIT. when a hook can’t tell which checkout a change came from, it picks the same-checkout level and says what to do either way. a confirmed change to a name your file imports keeps its level after the teammate has gone: ACTIVE COLLISION in the same checkout, PARALLEL EDIT from another branch or clone. the five levels have the exact wording.

if both changes happen anyway, the person is told once, as the session finishes. this is the notice after your session changed src/models/user.ts on feat/login while alice’s changed it on main, word for word:

text
[AgentMash: OVERLAP] A file this session changed was also changed by alice@example.com,
so a person decides how the two changes come together: nothing was stopped, merged or
committed for either side.
• src/models/user.ts — also changed by alice@example.com.
  alice@example.com: last write 9 min ago on branch main — you are on feat/login
  while working on 'soft deletes' (+12/-3 lines, touching User, deletedAt).
  You both touched User — that is where the two changes are most likely to meet.
  Your side: 'add a login endpoint' (+8/-1 lines).
Look at both changes with alice@example.com before either one lands.

it only advises: the agent finishes as it would have. Claude Code, Codex and GitHub Copilot give this notice; Cursor’s adapter doesn’t.

set it up for a team

someone who can push to the GitHub repository connects it once, at agentmash.dev/install. nothing is committed to it and there is no pull request. then each developer runs this once per machine, with Node.js 18.12 or newer:

npx agentmash login

it signs in with GitHub and connects the coding agents it finds on the machine, each in its own user settings, never in a repository (Antigravity only when you ask for it by name). restart the agent, and its prompts and edits go to the room from the next prompt on. anyone who could push to the repository when they last signed in gets into its room, if that sign-in was within the last seven days. Codex adds a step, and Cursor gets the warning another way:

for a team where everyone runs Claude Code, claude code for teams goes through each hook. connect your coding agent has the steps for Claude Code and the other coding agents, and a prompt to paste into your agent that runs the login and tells you what’s left.

what reaches the room: who made each edit (your GitHub login, or the email in your git config, or your computer’s user name when there is neither), file paths, branch names, the shape of each change (its line counts and the names it touches) and the first 500 characters of a prompt, with an opaque id of the checkout each edit came from. your code stays on your machine unless the room turns diffs on or you share a session live. what leaves your machine has the full list.

which setup covers what

setupwhat it isolateswhat it can’t see
a second terminal in the same checkoutnothing: one working tree, one index, one brancha branch switch in the other session, or a whole-file write over its changes
claude --worktree per sessioneach session’s files and branchthe other sessions’ changes, until you merge
agent teamseach teammate’s context; teammates get no worktreessessions outside the lead’s team
agentmashnothing: it makes no checkoutsyour own sessions, to each other: they all report as you

the worktree and agent-team rows are read from Claude Code’s docs, checked on 2026-10-16; the first row is from the issues and the tools reference above. the side by side with subagents and cross-session messaging is on claude code agent teams and agentmash, linked below.

what it doesn’t do