Tutorial · Intermediate

Get three coding tasks done at once without them clashing

Waiting for one coding task to finish before you start the next wastes your day. We give each Claude Code task its own copy of the repo, called a git worktree, so three sessions can edit the same project at once and you review and merge each one on its own.
[ The result ]

Three Claude Code sessions work at the same time on three separate branches, and you review and merge each change on its own without them clashing.

[ How it's wired ]
  1. Install Claude Code and trust your project

    If you don't have Claude Code yet, open a terminal and run the install command below (macOS, Linux, WSL). Then open a new terminal window and run 'claude --version'. You should see a version number. Next, go into your project folder and run 'claude' once. Accept the trust dialog and log in, then type /exit. You need to do this once, because 'claude --worktree' quits with an error in a folder you haven't trusted yet.

    curl -fsSL https://claude.ai/install.sh | bash
    claude --version
    cd your-project
    claude
  2. Ignore the worktrees folder and commit a clean state

    Claude Code creates each worktree in .claude/worktrees/<name>/ at the root of your repo. Add that folder to .gitignore so it doesn't show up as untracked files in your main checkout. Then commit or stash everything else. Note that new worktrees branch from your repo's default branch on the remote (usually origin/main), not from your local edits. Push your commit if you have a remote. If you'd rather start from your local, unpushed work, set "worktree": { "baseRef": "head" } in your Claude Code settings. Run 'git status' at the end. It should say the working tree is clean.

    echo ".claude/worktrees/" >> .gitignore
    git add .gitignore
    git commit -m "Ignore Claude Code worktrees"
    git push
    git status
  3. Copy .env files into every new worktree (optional)

    A worktree is a fresh checkout, so gitignored files like .env aren't in it. If your app needs them to run, create a file called .worktreeinclude in the project root and list them there. It uses the same pattern syntax as .gitignore. Claude Code only copies files that match a pattern and are gitignored, so tracked files are never duplicated. You also need to install dependencies in each worktree: ask Claude to do it, or run your usual setup command inside the worktree folder.

    .env
    .env.local
  4. Start three sessions in three terminals

    Open three terminal tabs in your project folder and run one command in each. Each command creates its own folder under .claude/worktrees/ and its own branch called worktree-<name>. For example, you type 'claude -w fix-login' and get a normal Claude session that works in .claude/worktrees/fix-login on the branch worktree-fix-login. -w is the short form of --worktree. If you leave out the name, Claude picks a random one like bright-running-fox, so give it a name you'll recognise later. We use the terminal here because you name each branch yourself, which keeps the review and merge commands below simple. If you prefer the Claude desktop app: open the Code tab, start a new session with + New (Cmd+N on macOS, Ctrl+N on Windows), and turn on Worktree in the row under the prompt box before you send your first message.

    # Terminal 1
    claude -w fix-login
    
    # Terminal 2
    claude -w add-tests
    
    # Terminal 3
    claude -w docs
  5. Give each session one narrow task

    Parallel work goes smoothly when the tasks touch different files. Give each session one small job, and ask it to run the tests and commit on its branch when it's done. For example, you paste the Terminal 1 prompt below, and Claude edits the login form, runs your tests, commits on worktree-fix-login and tells you what it changed. Meanwhile the other two sessions do the same on their own branches. If two sessions edit the same lines, you'll get a merge conflict later. Worktrees keep the sessions apart while they work, but they can't stop that. Change the example prompts to fit your project.

    Terminal 1:
    Fix the bug where the login form accepts an empty password. Keep the change small, run the existing tests, then commit on this branch with a clear message.
    
    Terminal 2:
    Add unit tests for the date helpers in src/utils. Don't change the helpers themselves. Run the tests, then commit on this branch.
    
    Terminal 3:
    Update README.md so the setup section matches the current scripts in package.json. Only edit documentation files, then commit on this branch.
  6. Review each branch from your main checkout

    Keep the three sessions open. In a fourth terminal in your main project folder, run 'git worktree list'. You should see your main checkout plus the three worktrees. Then look at each branch's changes against main, one at a time. If a change isn't right, go back to that session's terminal and ask Claude to fix it.

    git worktree list
    git log --oneline main..worktree-fix-login
    git diff main...worktree-fix-login
  7. Merge each change on its own

    When a branch looks good, merge it into main from your main checkout, then run your tests. Do the branches one by one so a problem in one doesn't block the others. If git reports a conflict, fix those files, commit, and move on to the next branch. If you use pull requests, push the branch instead and open a PR.

    git switch main
    git merge worktree-fix-login
    git merge worktree-add-tests
    git merge worktree-docs
  8. Exit the sessions and clean up

    Type /exit in each session. If the worktree is clean, Claude removes it and its branch on its own. Unnamed sessions don't ask; named sessions ask you first. If the worktree still has changed files or new commits, Claude asks whether to keep it or remove it. Remove deletes the folder and its branch, together with all the work in them, so only choose it after you've merged. Choose keep if you want to come back later, and Claude prints a 'claude --worktree <name> --resume' command for that. To clean up by hand, use the commands below.

    git worktree remove .claude/worktrees/fix-login
    git branch -d worktree-fix-login
    
    # if git says the worktree is locked:
    git worktree unlock .claude/worktrees/fix-login
DoneStuck on a step? Reply to any Daily AI Brief email and ask.
[ One tutorial a week ]

Get the next automation before it's posted.

One short email with the AI stories that matter. What happened in AI, why it matters, one tool worth trying. Free. Unsubscribe anytime.

More tutorials

All tutorials
01Find out what you missed in a long lecture with a free quiz and flashcards20 min · Beginner · 7 steps02Make Claude Code follow your project's rules in every session15 min · Beginner · 7 steps03Turn your most frequent app error into a tested fix you can review20 min · Intermediate · 7 steps
[ Daily AI Brief ]

The AI news that matters, in your inbox.

One short email with the AI stories that matter. What happened in AI, why it matters, one tool worth trying. Free. Unsubscribe anytime.