Cursor Worktrees: Run a Cursor Agent in a Git Worktree
Cursor supports worktrees natively. Since Cursor became Grok Build on November 30, 2026, the Agents Window, the IDE's /worktree command and the grok -w terminal flag each start an agent in its own Git worktree.
The Fix
Pick the surface you use:
- Agents Window. Start an agent in a worktree, or move a running agent into one. Grok Build creates a separate checkout for it.
- IDE chat. Prefix the task with
/worktree, for example/worktree fix the failing auth tests. When the agent finishes, ask it to commit, push and open a pull request, or run/apply-worktreeto bring the changes into your main checkout./delete-worktreeremoves the checkout. - Terminal. The Grok Build terminal app, which now runs Cursor's agent, takes a worktree flag:
grok -w
grok --worktree=feat "refactor module X"
grok -w --ref main "fix the flaky test"
grok worktree list, grok worktree rm <id> and grok worktree gc manage the terminal app's worktrees.
To install dependencies or copy .env into each new IDE worktree, add .cursor/worktrees.json at the project root:
{
"setup-worktree": ["npm ci", "cp $ROOT_WORKTREE_PATH/.env .env"]
}
setup-worktree-unix and setup-worktree-windows override the generic key per platform.
Why It Works This Way
Each worktree is a real git worktree checkout, so two agents never write to the same files. The surfaces keep their worktrees in different places and clean them up differently:
| Agents Window and IDE | Terminal app | |
|---|---|---|
| Location | Managed by the app | ~/.grok/worktrees/<repo>/<name> |
| Cleanup | Keeps the newest 25 by default, set by cursor.worktreeMaxCount | Removes session worktrees older than seven days |
| Checks before deleting | Skips worktrees an agent or window is using, but not uncommitted work | Keeps worktrees with uncommitted or unpushed work |
A terminal app worktree starts from your current HEAD, including uncommitted changes. --ref starts from a clean checkout of another ref instead.
The IDE cleanup does not check git status. A worktree with uncommitted changes or unpushed commits can be deleted once it falls outside the cap, so commit or push work you want to keep. That cleanup also counts worktrees you made yourself with git worktree add.
Terminal app worktrees start detached at their base commit. Create a branch with git switch -c <name> before you commit work you plan to push.
How Treq Handles It
Treq starts Cursor Agent as one of its supported agents, in plan or edit mode. Each agent runs in its own Treq workspace, a separate working copy and branch under .treq/workspaces/, so you do not need Cursor's worktree option inside Treq. treq agent start <branch> "<prompt>" -a cursor does the same from the CLI. See Agent Sessions for what each mode passes to the agent.