How to run several Claude Code agents in parallel
How do I run more than one Claude Code agent at the same time without them breaking each other's work? Give each agent its own git worktree: run claude --worktree <name> in a separate terminal for each task, or switch on Worktree in the desktop app. Then watch them from one screen with claude agents , and merge each branch only after you've checked it. Why not just open two terminals? Two agents…
To run multiple Claude Code agents simultaneously without conflicts, create a separate git worktree for each task. Start by running Claude once in the project folder to avoid an error about resolving the base branch. After that, initialize a worktree with a unique name for each agent's task, such as "contact-form" or "pricing-page". This creates a new branch for each agent, ensuring their edits don't collide until you choose to merge them.
Add .claude/worktrees/ to your .gitignore so the worktree folders don't appear as new files in your main project. If your project includes files like .env that aren't tracked by Git, create a .worktreeinclude file at the project root to list the ignored files, so they're copied into each worktree.
When launching an agent, use a name to identify its task, like claude --worktree contact-form. The agent creates a folder for that worktree with a new branch and starts the session there. To monitor all agents, use the claude agents view, which lists the sessions by state—waiting, working, idle, done, or failed. You can view the latest output, send tasks to the background, or open the full conversation from this view.
Start by running a single agent to install dependencies, then launch subsequent agents with their unique names. If tasks depend on each other, execute them one after the other. Review each agent's changes against the main branch before merging, using git diff --stat. If there are no conflicts, create a pull request or merge the branch yourself.
When you're done with a worktree session, Claude Code checks for unsaved work and removes the session and its branch if there's nothing left. To manually remove a worktree, use git worktree list to view them and git worktree remove to delete a specific one. Remember, each session consumes your plan's quota independently, so start with a few agents (2-3) and add more as needed based on your plan's usage.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to