blog / , updated
Git Worktree Claude Code Tutorial: One Line, One Agent
This git worktree Claude Code tutorial gives each agent its own branch in its own folder, so two sessions never edit the same files. With qoop it is one command per agent:
- From inside your repo, run
qoop worktree new feat/login -- claude. - Read the path: a sibling folder named after the repo and the branch.
- Run
qoop worktree lsto see every worktree and the terminals inside it. - Run
qoop worktree new feat/rate-limit -- codexfor a second agent on a second branch. - When a branch is merged, run
qoop worktree rm feat/login.
The rest of the post expands each step, shows what plain git and claude --worktree do instead, and lists what to check when something goes wrong.
Without qoop: the git worktree Claude Code tutorial by hand
Plain git does the whole job in four moves per agent. Say your repo is ~/code/shop and the first task is a login screen:
cd ~/code/shop
git worktree add ../shop-wt-login -b feat/login
cd ../shop-wt-login
claude
git worktree add creates the folder and, because of -b, a new branch checked out in it. Then you change into the folder and start the agent there. For a second agent you repeat the same four lines with another folder and branch name, in another terminal window. Cleanup is two more commands:
git worktree list
git worktree remove ../shop-wt-login
git worktree remove only removes a clean worktree: no untracked files and no modified tracked files. --force overrides that. If you delete the folder with rm instead, run git worktree prune to clear the leftover bookkeeping. That is the full cost of the manual route: you type the right path three times, you remember which terminal belongs to which branch, and you remember the cleanup.
Claude Code can do the add and cd for you
Claude Code has its own flag. claude --worktree feature-auth (short form -w) creates a worktree under .claude/worktrees/feature-auth/ at the repo root, on a new branch named worktree-feature-auth, and starts the session in it. Run it again with another name in another terminal and you have a second isolated session. By default the new branch starts from the repository's default branch on the remote; the worktree.baseRef setting can make it start from your current HEAD instead. A .worktreeinclude file copies gitignored files such as .env into each worktree Claude Code creates, and the docs suggest adding .claude/worktrees/ to .gitignore. When you exit a named session, Claude Code prompts you to keep or remove the worktree; an unnamed session with no changes is removed automatically.
If you only run Claude Code, that is already one command, and you can stop reading here. What it does not give you is the same command for another agent, or a default location outside the repo folder.
Codex
The Codex CLI reference lists a global --worktree flag ("Start in a new managed Git worktree") and --cd (short -C) to set the working directory. It does not say where that worktree is created or what branch it uses, so run git worktree list after your first try and read the answer there. In the ChatGPT desktop app, where Codex runs worktree chats, a worktree starts in a detached HEAD state by default, so you create a branch on it yourself when you want one. Either way, git by default refuses to check out a branch that another worktree already has, which is why every agent below gets its own branch name.
Before you start
- A git repository, with your shell inside it. Every command below runs from the repo folder.
- qoop installed on that computer. It runs on macOS and Linux, and on Windows only under WSL. Install qoop and start your first agent covers the install.
- qoop running:
qoop worktree newrefuses with "nothing is awake" when it is not, andqooporqoop wakestarts it. - The agents you want on your
PATH:claudeandcodexfor this tutorial. - One branch name per agent, none already checked out in another worktree.
A tab or a space in qoop only groups terminals. It does not keep one agent's files apart from another's. The separate checkout comes from the worktree, which is why these steps start with qoop worktree new and not with a new tab.
Step 1: Run qoop worktree new
From the repo folder:
cd ~/code/shop
qoop worktree new feat/login -- claude
One command makes the git worktree next to your repo, opens a terminal inside it and types claude there. That covers the add, the cd and the open from the manual version. The --base REF option names the starting point of a new branch; without it the branch starts from HEAD. Everything after the lone -- is the command to run in the new terminal, so -- claude starts Claude Code and -- codex starts Codex.
The usage line from qoop worktree --help shows the other options:
qoop worktree new <branch> [--base REF] [--path DIR] [--space ID|NAME] [--name NAME] [--no-setup] [-- CMD...]
This tutorial uses only the branch name and the command after --, and the path in step 2 is the default one. --no-setup skips the per-space setup described in the last section. The new terminal with the agent in it shows up in qoop's agents column like any other agent.
Step 2: See the path
The worktree lands in the parent folder of your repo, as <repo>-wt-<branch>, with the slash in the branch name turned into a hyphen. For the repo ~/code/shop and the branch feat/login, that is:
~/code/shop-wt-feat-login
Confirm it with qoop worktree ls (the path= field, see step 3) or with git worktree list. The tree sits beside the repo, not inside it, so your main checkout's git status has nothing new to show and you need no .gitignore entry for it. If you want a different location, --path DIR sets it.
Step 3: List with qoop worktree ls
qoop worktree ls
You get one line per worktree, the main checkout included, with one indented line under it for each terminal inside. Each worktree line has a path= field, a branch= field and a terminals= count, so it has this shape:
path=<folder> branch=<name> terminals=<count>
The terminals counted are the ones inside that folder, which is how you tell which tree has an agent running in it. For scripts, add --json:
qoop worktree ls --json
That prints a JSON array with path, branch, head, bare and terminals for each tree, where terminals is a list. Git's own view of the same trees comes from git worktree list.
Step 4: Start Codex the same way
For a second task that touches different files, run the same command with another branch and another agent:
qoop worktree new feat/rate-limit -- codex
Now Claude Code works on feat/login in ~/code/shop-wt-feat-login and Codex works on feat/rate-limit in ~/code/shop-wt-feat-rate-limit. Run qoop worktree ls again and it lists the main checkout and the two new trees, plus any worktrees you already had.
Pick tasks that do not touch the same files. Separate checkouts stop the two agents from overwriting each other on disk, but they do not stop two branches from changing the same function and conflicting at merge time. Parallel Claude Code and Codex in separate worktrees covers how to split the work.
Step 5: Remove a tree with qoop worktree rm
The agent from step 1 is still running inside that tree, and rm refuses while a process has the folder as its directory. So after feat/login is merged, close the agent's tab first (ctrl-a x, which asks before closing if the agent is still working), then run:
qoop worktree rm feat/login
This is the one cleanup command, and it carries the safety checks that the manual version leaves to you:
- It refuses while any process still has the tree's folder as its directory. The refusal names the process by pid, and by qoop terminal where qoop knows it.
- It refuses when the tree has uncommitted changes, unless you add
--force. - It removes the tree and keeps the branch. Delete the branch with git once it is merged, or let
qoop worktree finish feat/logindo that for you: it removes the tree and the branch, andorigin/feat/login, but only once it has proof the branch is merged into your main branch. Remove a git worktree without losing work covers its modes.
So the honest version of "one command replaces add, cd, open and cleanup" is: qoop worktree new replaces the first three, and qoop worktree rm or qoop worktree finish is the cleanup command. Remove a git worktree without losing work goes deeper on the failure cases.
Claude Code's own prompt about removing a worktree on exit is described for sessions started with --worktree. For a tree made by qoop or by git worktree add, plan on removing it yourself.
Check it worked
Run these in order. Each one should pass before you hand the agents a task.
qoop worktree lshas a line whosebranch=isfeat/loginand whose path ends in-wt-feat-login, and the terminal running the agent is counted in that folder.git worktree listfrom the main checkout shows the new path with[feat/login]after it.qoop agentshas a row for the new terminal, with its state, program and name.- If the starting point matters, open a plain shell,
cdinto the new tree and rungit log -1to see the commit the branch started from. - Ask one agent to change a file.
git statusin the other tree, and in the main checkout, should show nothing from that change.
When it does not work
| What you see | What it means | What to do |
|---|---|---|
qoop: git worktree: fatal: not a git repository (or any of the parent directories): .git | The command ran outside a git repo. That text is the real output of qoop worktree ls from a plain folder, and the exit code was 1. | cd into the repo and run it again. |
qoop worktree rm refuses and names a pid | A process still has the tree's folder as its directory. | Stop the agent or leave the folder in every shell that sits in it, then run rm again. |
qoop worktree rm refuses over uncommitted changes | The tree has edits that were never committed. | Commit or discard them. --force removes the tree with those changes in it, so look at git status there first. |
| Git says the branch is already used by a worktree | Git by default refuses to check out one branch in two worktrees. | Choose a new branch name. qoop worktree ls shows which branches already have a tree. |
The new tree has no .env or node_modules | A worktree is a fresh checkout, so ignored files are not copied, and qoop copies nothing until your config says what. | Add a [spaces.<name>.worktree] table (see below), then run qoop worktree setup feat/login, or copy and install by hand. |
git worktree list shows a path that no longer exists | The folder was deleted without git worktree remove. | Run git worktree prune. |
About the .env row: Claude Code's .worktreeinclude applies to worktrees Claude Code creates, and the Codex documentation says its copy of that file does not apply to worktrees you create yourself from the command line. A tree made by qoop worktree new falls in neither group, but qoop has its own list. In config.toml, a table named after the space the worktree opens in says what to copy from the main checkout and what to run:
[spaces."my app".worktree]
copy = [".env", "apps/web/.env.local"]
setup = "bun install"
copy takes only files git ignores and never overwrites a file already in the tree. setup runs with sh -c in the new tree, and its output goes to stderr. qoop worktree new then prints a setup= line: done, none, skipped or failed. A failed setup keeps the tree, opens no terminal and exits 1; fix the cause and run qoop worktree setup feat/login. Without a table nothing is copied, so the manual route still applies. What a worktree does not isolate lists the usual suspects: env files, ports and installs.
If you want one terminal that lists every agent and tells you which one needs you, sign up at https://qoop.si.