Worktrees in Codex, Cursor and Claude Code compared

How Codex, Cursor and Claude Code each use git worktrees for parallel agents: where the worktrees live, branches vs detached HEAD, setup for .env and dependencies, and cleanup.

Short answer: all three tools isolate parallel agents with git worktrees, but they differ in the details. Claude Code puts worktrees in .claude/worktrees/ on worktree-* branches. Codex keeps them under $CODEX_HOME/worktrees in a detached HEAD until you create a branch. Cursor creates them from its Agents Window and runs setup commands from .cursor/worktrees.json.

Compiled from each tool’s official documentation as of November 2026: Claude Code, Codex, Cursor. These features change often.

At a glance

Claude CodeCodex (ChatGPT desktop app)Cursor
How to startclaude --worktree <name>, or ask Claude mid-sessionPick “Worktree” under the composerAgents Window; /worktree in the IDE
Location.claude/worktrees/<name>/ in the repo$CODEX_HOME/worktrees (configurable)Managed by Cursor
BranchNew branch worktree-<name>Detached HEAD; “Create branch here” when readySeparate checkout per agent
Starting pointRemote default branch (or local HEAD via setting)Branch you choose, including uncommitted changesYour project
Copy .env.worktreeinclude.worktreeincludeSetup commands, e.g. cp $ROOT_WORKTREE_PATH/.env .env
Install dependenciesAsk Claude or run it yourselfLocal environment setup scriptsetup-worktree in .cursor/worktrees.json
CleanupPrompt on exit; clean unnamed sessions removed automaticallyKeeps the 15 most recent by default, snapshot before deleting/delete-worktree

Claude Code

Run claude --worktree feature-auth and Claude Code creates .claude/worktrees/feature-auth/ on a branch named worktree-feature-auth, branched from your remote’s default branch. Subagents can get their own temporary worktrees with isolation: worktree. On exit, Claude removes clean worktrees from unnamed sessions and asks about everything else. While a session runs in a worktree, Claude Code blocks edits to the main checkout. The full guide: Claude Code worktrees.

Codex

In the ChatGPT desktop app, choose Worktree and a starting branch, and Codex creates a worktree under $CODEX_HOME/worktrees. It works in a detached HEAD state, so it doesn’t create branches you didn’t ask for. When you want to keep the work, use Create branch here, then commit, push and open a PR, or Hand off the chat to your local checkout. Codex keeps your 15 most recent managed worktrees by default and saves a snapshot before deleting one.

The detached HEAD has a cost. Commits made there belong to no branch. If a worktree is deleted before you create a branch, those commits are reachable only through Codex’s snapshot or git’s reflog.

Cursor

Cursor’s worktrees are built around its Agents Window: start or move an agent into a worktree and it gets its own checkout. In the IDE, /worktree runs a task in an isolated checkout, /apply-worktree brings the result into your main checkout, and /delete-worktree cleans up. Setup is the most scriptable of the three. .cursor/worktrees.json holds commands such as npm ci and cp $ROOT_WORKTREE_PATH/.env .env, with separate keys for Unix and Windows. Cursor advises against symlinking dependencies into worktrees.

Which one should you use?

  • You live in the terminal: Claude Code’s --worktree is the most transparent. The folders and branches are ordinary git ones you can see and script.
  • You start lots of throwaway tasks: Codex’s detached, auto-pruned worktrees create the least clutter. Just remember to create a branch for work you want to keep.
  • Your setup is heavy: Cursor’s worktrees.json runs your install and migration steps automatically.
  • You use more than one: that’s common. Many developers run Claude Code and Codex side by side, which means worktrees in two different places with two different naming schemes.

One view across all of them

Each tool shows only its own worktrees. Orchard shows all of them: every worktree in every project on your Mac, whether Claude Code, Codex, Cursor Agent, Gemini CLI, Aider, opencode, Amp or Goose made it. It tracks commits on a detached HEAD as unlanded work, so Codex’s branchless commits aren’t lost. It also shows which agent is working where and which worktrees are already in main and can be cleaned up.

FAQ

Where does Codex store its worktrees?

The ChatGPT desktop app creates Codex-managed worktrees under $CODEX_HOME/worktrees by default. You can change the location in Settings under Worktrees by setting a different worktree root.

Why is my Codex worktree in a detached HEAD?

Codex starts managed worktrees in detached HEAD on purpose, so parallel chats don’t create a branch each. Use Create branch here in the chat header when you want to commit, push and open a pull request.

How do I copy .env into Cursor worktrees?

Add a setup command to .cursor/worktrees.json, such as cp $ROOT_WORKTREE_PATH/.env .env under the setup-worktree key. Cursor runs these commands every time it creates a worktree.