Agents putting worktrees in /tmp by default can wipe days of work on macOS

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Agents putting worktrees in /tmp by default can wipe days of work on MacOS

I’m a heavy Cursor user on macOS. Over the last week Cursor agents repeatedly put durable project work in /tmp, macOS deleted it, and then Cursor kept the conversation rooted on the empty folder. I lost about 16 hours of work in one wipe. After that I added a user rule and a hook forbidding /tmp. Agents kept using it anyway because the chat workspace itself was /tmp.

Environment

  • macOS 15
  • Long-running agent chats on a large git repo
  • A live local checkout I cannot disturb (dev server already running)
  • Durable work lives under ~/Dev/…

What agents do

To avoid checking out a branch on top of my live IDE folder, agents create isolated git worktrees in /tmp:

git worktree add /tmp/wt-<repo>-<ticket>

This is not a one-off. In my history it is a habit: many chats, many /tmp/wt-… trees. Subagents (Task / isolated worktrees) pick /tmp as the “safe” place.

Cursor then bound the conversation to that path. From then on, the agent’s workspace was the /tmp worktree.

The IDE does not make this obvious

Nothing in the normal UI says “this chat is living in /tmp.” The window, chat title, and file tree look like a regular project. After macOS wiped the folder, the tree was just empty and the chat still looked fine. I only found out by asking the agent. Meanwhile I could keep working and committing under ~/Dev/… while the agent root, and a worker restart record, were still "roots":["/tmp/…"].

If the path were in the title bar or a banner, I would have stopped this on day one. Instead the UI implies you are in a durable workspace when you are not.

Why this is catastrophic on a Mac

/tmp is not a project directory. Reboot and periodic cleanup delete it. Uncommitted (and even committed-but-only-there) work is gone. That is the 16-hour loss.

After recovery, the real checkouts were under ~/Dev/…. The Cursor chat stayed rooted on the empty /tmp folder. Agents papered over it with cd ~/Dev/… instead of moving the window. The editor still looked like the project was open.

move_agent_to_root then failed in a way that made it worse

Calling move_agent_to_root with rootPath set to the durable ~/Dev/… checkout failed with:

Failed to move agent root: Cannot migrate: failed to detach worktree HEAD
(Error executing git: fatal: not a git repository (or any of the parent directories): .git
cwd: /tmp/…
command: "git checkout --detach")

The destination was a healthy repo. The source was an empty husk, so migrate refused to leave it.

Workaround that should not be required:

  1. create_repo on the empty /tmp folder (to get a .git)
  2. empty commit so HEAD exists
  3. move_agent_to_root again

That finally moved the chat. It also checked out a new local master on the destination to match the husk’s branch name, even though the real work was on a different feature branch. I had to switch back and delete that master.

What Should Be Changed

  1. Never put agent worktrees, clones, or chat roots in /tmp, /private/tmp, /var/folders, or $TMPDIR on macOS. Default to something durable, not a directory the OS is designed to wipe.
  2. Show the agent workspace path in the UI, especially when it is not the folder the user thinks they opened. A /tmp root should be a warning, not an invisible detail.
  3. move_agent_to_root must not require the current folder to be a git repo. If the source is an empty husk, still move the chat to the destination. Do not run git checkout --detach as a hard prerequisite.
  4. Do not retarget the destination branch to whatever dummy branch the husk had (master in this case).
  5. If a chat’s workspace path is under /tmp and a durable clone exists, migrate or warn loudly. Do not silently keep the agent in a deleted folder while the user is committing in ~/Dev.
  6. Teach the agent product default: isolated worktrees are fine; /tmp is not. User rules should not be the only backstop after losing a day’s work.

Steps to Reproduce

  1. Open a git repo under a durable path such as ~/Dev/my-project, with a branch already checked out. Do not let the agent check out a different branch in that folder.
  2. Ask the agent to do a feature on a new branch without disturbing the live checkout.
  3. Watch it create an isolated git worktree in /tmp (typically git worktree add /tmp/wt-<repo>-<ticket>) and bind the chat to that path.
  4. Confirm the window, chat title, and file tree still look like a normal project. There is no banner that the agent root is /tmp.
  5. Leave the machine running, or reboot, or wait for macOS to clean /tmp. The worktree is gone.
  6. Keep using the same chat. The UI still looks fine; the folder is empty. The agent may cd to ~/Dev/… and keep working while the chat root stays /tmp.
  7. Ask the agent where the work is, and it will prepare to give you devastating news.
  8. Call move_agent_to_root with rootPath set to the durable ~/Dev/… checkout.

Expected Behavior

  • Agent worktrees, clones, and chat roots never go in /tmp, /private/tmp, /var/folders, or $TMPDIR on macOS. Isolated worktrees go somewhere durable that the OS will not delete.

  • The IDE shows the agent workspace path. A /tmp root is an obvious warning, not an invisible default.

  • move_agent_to_root still moves the chat when the current folder is empty or not a git repo. It does not require git checkout --detach on the old path, and it does not switch the destination to a dummy master branch.

Operating System

MacOS

Version Information

  • Cursor: 3.27.12 (arm64)
  • OS: macOS 15.7.1 (24G231)

For AI issues: which model did you use?

Multiple agent chats over several days. The /tmp worktree default is not specific to one model in my usage.

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @kendistiller,

I’m really sorry about the lost work!

Cursor’s own worktrees (the worktree option in the Agents Window and the /worktree command) are created under ~/.cursor/worktrees in your home folder, not in /tmp.

The /tmp/wt-… folders most likely came from the agent running git worktree add itself, after which the agent moved the chat into that folder. Cursor doesn’t warn today when that folder is a temporary location, and the worktree location isn’t configurable yet.

Your suggestions to show the agent’s workspace path and to warn on temp folders are good ones, and I’m sharing them with the team.

In the meantime, a few things help:

  1. Ask for isolation with /worktree (or start the chat in a worktree from the Agents Window), so the checkout lands in ~/.cursor/worktrees. More on how that works: Worktrees | Cursor Docs
  2. If a chat ever ends up rooted in a temp folder, start a new chat from your ~/Dev/… checkout rather than continuing in the old one.
  3. Worth checking: commits made in a linked worktree are stored in the main repo, so git -C ~/Dev/<repo> branch --list may still show the worktree’s branch with its commits. Run git worktree prune there to clear the stale entry. Uncommitted changes in the wiped folder can’t be recovered this way.

The move failure is a known issue we’re already tracking, and I’ve added your report to it.

Adding an updated note based on recent experience and observations:

On a fresh Cursor installation, a newly started local (non-cloud) agent, operating under ~/.cursor/worktrees, still appears strongly inclined to create additional worktrees (and more) in /tmp.

The initial attempt was blocked by the sandbox, but the agent subsequently retried with elevated permissions and succeeded. More concerningly, this happened despite global Cursor rules explicitly prohibiting the use of /tmp for worktrees.

There were no warnings, approval requests, or other indications that the agent was about to create a worktree outside the expected location.

The agent acknowledged the behavior:

You’re right. There was no good reason to put it in /tmp. I treated it as scratch space and didn’t check the convention, even though .worktrees/ is right there.

What actually happened:

First attempt (/tmp/afur-head-wt): the sandbox blocked it, so it was never created.

Second attempt (/tmp/afur-head-68bd, at 68bd29b): I retried with full permissions and it worked.

My broader concern is the agent’s apparent preference for /tmp as a default scratch workspace, even when an appropriate worktree directory already exists and explicit rules prohibit the behavior.

I’ve also observed that this behavior extends beyond disposable scratch files. Agents often create important tooling, scripts, and other project-relevant resources inside /tmp, treating it as an ordinary development workspace rather than a temporary directory. This is particularly concerning because these resources may be needed later, yet they’re being placed somewhere that is not intended for persistent storage and may be cleared by the operating system.

In general, I think agents should avoid using the macOS system /tmp directory for this kind of work altogether. Even temporary workspaces and scratch files should be created in dedicated, predictable locations outside the system temporary directory.

Using /tmp would be less concerning if:

  1. The agent clearly disclosed what it intended to create, where, and why, and requested approval when appropriate.

  2. Temporary resources were reliably tracked and cleaned up afterward.

  3. Explicit user rules and existing project conventions were consistently respected.

  4. A sandbox denial wasn’t followed by a retry with broader permissions simply to accomplish the same prohibited operation.

The particularly troubling aspect here isn’t just the choice of directory. It’s the combination of ignoring explicit rules, encountering a sandbox restriction, and then successfully retrying with expanded permissions without notifying the user.

I think this deserves attention at the agent tooling level rather than relying solely on user-defined rules to prevent it.

Hi @kendistiller, thanks for the update.

Rules are guidance the model reads, not enforcement, which is why an agent can still talk itself into /tmp. A hook is the hard stop: Cursor runs it before every shell command, inside or outside the sandbox, so a deny still holds when the agent retries with more permissions.

  1. Create ~/.cursor/hooks.json (or add this entry to the one you have):
{
  "version": 1,
  "hooks": {
    "beforeShellExecution": [
      { "command": "./hooks/block-tmp-worktrees.sh", "matcher": "worktree add" }
    ]
  }
}
  1. Create ~/.cursor/hooks/block-tmp-worktrees.sh:
#!/bin/bash
input=$(cat)
if printf '%s' "$input" | grep -Eq '"command": *"[^,]*(((/private)?/tmp|/var/folders)([/ "\\]|$)|TMPDIR|mktemp)'; then
  echo '{"permission":"deny","user_message":"Blocked a git worktree in a temp folder.","agent_message":"Do not create worktrees under /tmp, /private/tmp, /var/folders or $TMPDIR, and do not retry with more permissions. Use .worktrees/ in the repo or ~/.cursor/worktrees instead."}'
  exit 0
fi
echo '{"permission":"allow"}'
  1. Run chmod +x ~/.cursor/hooks/block-tmp-worktrees.sh, then restart Cursor.

After that, a worktree aimed at /tmp, /private/tmp, /var/folders or $TMPDIR is refused, and the agent is told to use .worktrees/ or ~/.cursor/worktrees instead. If you had a hook like this before the reinstall, it’s worth checking that it’s still in ~/.cursor.

On the retry going through without a prompt: that comes down to your Run Mode (Cursor Settings → Agents → Run Mode). In Auto-Review, a classifier approves commands it considers safe, including ones that run outside the sandbox. In Allowlist, an allowlisted command like git can also run outside it automatically. Ask Every Time prompts before each command.