Zum Inhalt springen

Lektion 12 · Agent Mode

Worktrees and Cloud Agents

Run Cursor agents in isolated Git worktrees or on cloud machines, set up worktree scripts, compare results safely and avoid losing uncommitted work.

Two agents editing the same folder can overwrite each other. And a long task should not have to stop because you close your laptop. Cursor offers two kinds of separation: Git worktrees on your own machine and cloud agents on remote machines.

Worktrees

A Git worktree is an extra checkout of the same repository in another folder, with its own files. When an agent works in one, your main checkout stays untouched.

The documentation describes two ways to use them. In the Agents Window, you can start or move an agent into a worktree. In the editor view, slash commands do it:

Command Purpose
/worktree Run the rest of the chat in a separate checkout
/apply-worktree Bring the changes into your main checkout for testing
/delete-worktree Remove the isolated checkout
/best-of-n Run one task with several models, each in its own worktree

Example:

TEXT
/worktree fix the failing date tests and keep the public API unchanged

/best-of-n lets you compare the results. It does not merge anything by itself, and each extra model run adds usage.

Prepare a worktree

A fresh checkout has no installed dependencies and no ignored files such as .env. You can describe the setup in .cursor/worktrees.json. The documented keys are setup-worktree-unix, setup-worktree-windows and the general fallback setup-worktree. Each takes a list of commands or a path to a script. This is an example for a Python project:

JSON
{
  "setup-worktree-unix": [
    "python3 -m venv .venv",
    ".venv/bin/pip install -r requirements.txt",
    "cp \"$ROOT_WORKTREE_PATH/.env.development\" .env"
  ]
}

The variable $ROOT_WORKTREE_PATH points at your main checkout. Copy only development settings with limited credentials. The documentation advises against symlinking dependency folders, because it can break the main checkout.

Cleanup can delete work. The documentation says that old worktrees created for the Agents Window are removed automatically when there are more than a set maximum (25 by default), and that cleanup does not check Git status. Uncommitted changes, untracked files and unpushed commits can be lost. Commit your work, and push or merge anything you need to keep.

A safety check for unsaved work

This stand-in shows a simple policy that you could follow before deleting a checkout by hand. The statuses are made up.

Python Stand-in: which worktrees are safe to delete?

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In a real repository, start with git status in the worktree, and compare its commits with the remote branch.

Cloud agents

Cloud agents, formerly called background agents, run in isolated virtual machines in the cloud, each with its own development environment. They keep working while your computer is off, can run in parallel, and can open pull requests. You can start them from the desktop app, the web, a phone app, or tools such as Slack, GitHub and Linear.

Key facts from the documentation as of December 2026:

  • They need Premium or a higher plan, Teams, Enterprise or an older paid plan. The Free and Plus plans do not include them.
  • Source control, such as GitHub or GitLab, must be connected.
  • You can set up the environment with an agent, from a saved snapshot, or with a Dockerfile configured through .cursor/environment.json.
  • Command hooks from the repository's .cursor/hooks.json run in the cloud. Your personal user hooks do not.
  • Secrets are added when an agent starts. Agents that are already running do not receive new ones.
  • The privacy documentation says cloud agents keep encrypted copies of the repositories they work on.

The documentation also says cloud agents do not ask you to approve commands the way local agents can, because they run on their own machine. That makes the secrets, network access and repository rights you give that machine very important.

Choose where to work

Where should it run?

Local checkout Watch closely
Worktree Separate files
Cloud agent Remote, unattended

A worktree isolates files, not your computer

1 / 2

A worktree protects your main files from the agent's edits to its copy. It does not, by itself, protect your computer, database or network from a command. Two worktrees on one machine may also share a local database or fight over the same port.

Before you hand off a task

TEXT
[ ] The task has clear acceptance tests
[ ] The branch starts from an up-to-date base
[ ] Secrets are for testing only, with minimal rights
[ ] A person will review the pull request
[ ] A spending limit is set

Parallel work without chaos

Parallel agents save time only when their tasks do not collide. Pick tasks that touch different parts of the code and have separate checks. Two agents that both restructure the same module will produce a painful merge.

Plan for review capacity too. Five finished branches still need five reviews. A practical limit is the number of diffs you can read carefully today, not the number of agents the product can start.

Merge one branch at a time. After each merge, run the full test suite, because two changes that pass separately can fail together. For example, one branch renames a function while another adds a new call to the old name. Git may merge both without a conflict, and only a test or a type checker notices.

When you compare several models on one task, choose by evidence: which result passes the checks, has the smallest sensible diff and is easiest to explain. Discard the others deliberately, after saving anything you want to keep.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What does a worktree isolate?

    It is a separate checkout. Commands can still reach other things on the machine.
  2. 2. What is the main risk of automatic worktree cleanup?

    The documentation says cleanup does not check Git status.
  3. 3. Which secrets should a worktree or cloud agent receive?

    Give the least access needed, ideally for test systems only.

Summary

  • Worktrees give parallel agents separate checkouts.
  • .cursor/worktrees.json prepares each new checkout.
  • Protect your work: cleanup does not check Git status.
  • Cloud agents run remotely, need an eligible plan and need careful permissions.

Next: Project Rules and AGENTS.md

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.