Rightshold™ Sign up

Answers · agent safety

How do I run parallel Claude Code sessions with git worktrees without them overwriting each other?

Short answer: Give each session its own git worktree: a separate working directory on its own branch that shares the repository's history. Two Claude Code sessions in the same folder edit the same files and step on each other; two sessions in two worktrees can't. Claude Code builds this in: run claude --worktree feature-auth (or -w) in one terminal and claude --worktree fix-login in another, and each gets a checkout under .claude/worktrees/ on a new branch named worktree-<name>. A worktree is a fresh checkout, so install dependencies in it and copy gitignored files such as .env with a .worktreeinclude file. Keep the tasks independent (different files or areas), give each session its own dev-server port and test database, and merge the branches back one at a time through review and CI, the same as work from two people.

Checklist

  1. Commit first: a worktree is created from an existing commit, so a repository with no commits can't make one. Add .claude/worktrees/ to .gitignore so worktree contents don't show up as untracked files in your main checkout.
  2. Start each session in its own worktree: claude --worktree <name> (or -w). Running the same name again reopens that worktree; omitting the name makes Claude generate one.
  3. To start from a specific existing branch or put the worktree outside the repository, use git directly: git worktree add ../project-feature-a -b feature-a, then cd there and run claude. List them with git worktree list.
  4. Set up each worktree like a fresh clone: install dependencies, and list gitignored files the app needs (.env, .env.local) in a .worktreeinclude file at the project root so Claude Code copies them into every new worktree. Only files that match and are gitignored are copied.
  5. Avoid shared-resource collisions git can't see: give each worktree its own dev-server port, its own local or test database (or schema), and its own build cache when the tool keeps one outside the folder. Never point parallel sessions at production.
  6. Split work so sessions touch different files: one feature per worktree, not two sessions on the same component. Overlapping edits become merge conflicts later instead of overwrites now, which is better, but still work.
  7. By default new worktrees branch from the repository's default branch on the remote; set worktree.baseRef to "head" in settings if a session must start from your unpushed local work.
  8. Merge back one branch at a time through a pull request with CI, rebasing the next branch on the updated main. Then clean up: git worktree remove <path>, or let Claude remove a clean worktree when you exit the session.

What a worktree shares and what it doesn't

Worktrees vs subagents

Ask Rightshold (free, no key)

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “My parallel Claude Code branches added these packages. Are their licenses OK for our commercial, closed-source app before I merge?”

One-click setup

{
  "tool": "check_rights_batch",
  "arguments": {
    "intended_use": {
      "commercial_use": true,
      "redistribution": true
    },
    "items": [
      {
        "ref": "<package-added-in-worktree-a>",
        "license": "MIT"
      },
      {
        "ref": "<package-added-in-worktree-b>",
        "license": "<its SPDX id>"
      }
    ]
  }
}

Rightshold does not create worktrees, run Claude Code or merge branches; worktree isolation lives in git and Claude Code. It checks the licenses of packages your sessions add.

Sources

Related

Not legal advice. Updated 2026-10-29. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'