Skip to content

BlogGuide · · 2 min read

One session per branch: git worktrees with Claude Code

The short answerRun `git worktree add ../repo-task -b task main` for each task and start Claude Code inside that folder. Each session gets its own files and branch, so parallel sessions never overwrite each other.

The problem with one folder

Two sessions in one checkout share one set of files and one checked-out branch. One runs the tests while the other is halfway through an edit; one switches branch and the other’s changes come along. A worktree gives each session its own folder on its own branch, backed by the same repository.

The commands

# a new folder next to the repo, on a new branch cut from main
git worktree add ../acme-api-billing -b billing main

cd ../acme-api-billing
claude

# see them all
git worktree list

Commits made in any worktree are visible from all of them at once, because they share one .git. There is nothing to push or pull between them.

What a new worktree does not have

  • Installed packages. node_modules and virtual environments are not part of git. Install again in the new folder.
  • Untracked files, such as .env files. Copy the ones the task needs.
  • A free port. Two dev servers cannot share one port; give each worktree its own.
  • The same branch twice. Git refuses to check out one branch in two worktrees, which is what you want.

Cleaning up

When the branch is merged, remove the folder and the branch:

git worktree remove ../acme-api-billing
git branch -d billing

git worktree remove refuses if the folder has uncommitted changes, so nothing is lost by accident.

With HeyJason

HeyJason starts a session in any folder you pick, so a worktree per task fits naturally: one folder, one session, one task. If two sessions still end up editing the same file, it shows the overlap and which one should go first. See how to run several sessions.

By The HeyJason team. Found a mistake? support@heyjason.dev

Keep reading

  • Guide

    How to run several Claude Code sessions in parallel

    Give each session one task and its own working copy (a git worktree), name it after the task, and check on a schedule which ones are waiting for you. The limit is your attention, not the number of sessions.

  • Guide

    Claude Code from your phone: what works, and what should stay on the computer

    From a phone it makes sense to answer a session’s question, send a prompt, interrupt it, and start or replace a session. With HeyJason you can also answer a permission prompt by picking one of its options, while sign-ins, settings and anything you cannot judge from a small screen stay on the computer.

  • Guide

    When a Claude Code session runs out of context: handing off cleanly

    Before the context is full, have the session write a handoff note (goal, current state, decisions made, what is left, how to verify), then start a fresh session that reads the note first. A fresh session with a good note beats a long session that has forgotten its own decisions.

Get started

Try it on your own sessions.14 days free, no card.

Every feature for 14 days, on up to 3 computers. Then Solo is $10 a month and Pro is $20.

Start on the web

Start freePricing

Or install first, on the computer that runs Claude Code

$ curl -fsSL https://heyjason.dev/install | sh

Install guide