Home › Agent workflows › Parallel agents with git worktrees CLAUDE.md

Parallel agents with git worktrees CLAUDE.md

CLAUDE.md conventions for running several coding agents in parallel with git worktrees, task scoping, and safe merging.

Claude Code (CLAUDE.md)Agent workflows

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

CLAUDE.mdDownload  
# CLAUDE.md: Parallel agent sessions

Several agent sessions may work on this repo at once. Each one follows these rules.

## Isolation
- One task per session, in its own git worktree and branch:
  `git worktree add ../<repo>-<task> -b agent/<task> main`
- Never edit files in another session's worktree or switch branches in the main checkout.
- Install dependencies per worktree; don't share `node_modules`/virtualenvs across them.
- Use a unique port and database/schema per worktree (e.g. `PORT=31<NN>`, `DATABASE_URL=...<task>`), configured in that worktree's `.env.local`.

## Scope
- Stay inside the task's described files/modules. If you need to change shared code (configs, schema, shared components), stop and report it, because another session may be touching it.
- Keep diffs small and focused so they merge cleanly.

## Coordination
- Write progress in `notes/<task>.md` in your worktree: goal, decisions, status, and anything other sessions should know.
- Rebase on `main` before finishing (`git fetch && git rebase origin/main`), rerun tests, and resolve conflicts carefully. Don't force-push shared branches.

## Finish
- All tests, lint, and typecheck pass in your worktree.
- Summarize the branch, files changed, and merge notes. Don't merge into `main` yourself unless asked.
- Cleanup (when told): `git worktree remove ../<repo>-<task>`.

More: all Agent workflows rules · all Claude Code (CLAUDE.md) rules

Related rules

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

Code review prompt file (Copilot)

A Copilot prompt file (/review-changes) that reviews the current changes and reports issues by severity without editing.

GitHub CopilotAgent workflows

Code reviewer subagent (Claude Code)

A Claude Code subagent definition that reviews the current diff for bugs, security, and tests, reporting by severity.

Claude Code (CLAUDE.md)Agent workflows

/commit slash command (Claude Code)

A Claude Code /commit slash command that reviews staged changes and writes a Conventional Commits message.

Claude Code (CLAUDE.md)Agent workflows

Context management for long agent sessions CLAUDE.md

CLAUDE.md practices for keeping Claude Code effective in long sessions: lean memory, notes files, subagents, and resets.

Claude Code (CLAUDE.md)Agent workflows

Git commits & PRs AGENTS.md

AGENTS.md rules for how agents commit: Conventional Commits, atomic changes, safe git commands, and PR descriptions.

AGENTS.mdAgent workflows

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.