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 listCommits 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_modulesand virtual environments are not part of git. Install again in the new folder. - Untracked files, such as
.envfiles. 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 billinggit 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