Where does the bug appear (feature/product)?
Cursor IDE
Describe the Bug
When I start two different agent chats in quick succession using WorkTrees, one agent will often get confused and try to implement the work specified for the other agent. I’m not sure if this is WorkTree-specific necessarily because I always use WorkTrees whenever I start multiple parallel agents. For what it’s worth, I’m running in SSH mode, meaning that I run the cursor UI on my laptop, but it is connected via remote SSH to a development server.
I have a custom /worktree command stored on the laptop. It’s content are at the end of this file.
This is how grok 4.7 describes the bug when I ask it to investigate:
With two agent chats open in one Cursor window, both using the
/worktree slash command a few seconds apart, the laptop UI put the
other chat’s message inside this chat’s expanded command.
The IDE was connected to a remote Linux development server over SSH.
The /worktree command file lives only on the laptop. That file
contains only the worktree procedure. It does not contain the other
chat’s task.
This chat’s own message was /worktree plus a request about feature 2,
including an instruction not to implement it yet. The expanded
command the agent received contained:
- The saved worktree procedure.
- The other chat’s task, feature 1.
- This chat’s feature 2 request again.
The feature 1 request was not in this chat’s own message. The agent
followed the expanded command and started working on feature 1.
The other chat created its worktree and branch for feature 1 at
8:24:42 AM America/Chicago on 21 Oct 2026. This chat created a
second worktree at 8:25:00 AM. Its branch name had a suffix because
the feature 1 branch name was already taken. The shared git branch
explains the renamed branch. It does not explain the other chat’s
text appearing in this prompt. The agent had not read the other
chat’s files.
~/.cursor/commands/worktree.md content:
Run the task in a separate git worktree, and always create that worktree on a
named branch before doing any task work.
Always use the current `HEAD` as `WORKTREE_START_REF`. Do not use a fixed
branch such as `master`, and do not use remote refs such as `origin/master`
or `upstream/master`.
Choose a short, descriptive, filesystem-safe `<NAME>` from the task. Choose a
random 8-character lowercase hexadecimal `<SUFFIX>`. Set:
```bash
WORKTREE_ID="<NAME>-<SUFFIX>"
WORKTREE_BRANCH="<NAME>"
```
If `WORKTREE_BRANCH` already exists, append the same suffix:
```bash
WORKTREE_BRANCH="<NAME>-<SUFFIX>"
```
Create the worktree with a branch, not detached `HEAD`:
```bash
set -euo pipefail
WORKTREE_ID="<NAME>-<SUFFIX>"
WORKTREE_BRANCH="<NAME>"
REPO_ROOT="$(git rev-parse --show-toplevel)"
REPO_BASENAME="$(basename "$REPO_ROOT")"
if command -v shasum >/dev/null 2>&1; then
REPO_HASH="$(printf '%s' "$REPO_ROOT" | shasum -a 256 | cut -c1-12)"
else
REPO_HASH="$(printf '%s' "$REPO_ROOT" | sha256sum | cut -c1-12)"
fi
REPO_KEY="${REPO_BASENAME}-${REPO_HASH}"
WORKTREE_SET_DIR="$HOME/.cursor/worktrees/$WORKTREE_ID"
WORKTREE_DIR="$WORKTREE_SET_DIR/$REPO_KEY"
mkdir -p "$WORKTREE_SET_DIR"
if [ -d "$WORKTREE_DIR" ]; then
echo "ERROR: worktree directory already exists: $WORKTREE_DIR" >&2
exit 1
fi
if git show-ref --verify --quiet "refs/heads/$WORKTREE_BRANCH"; then
WORKTREE_BRANCH="$WORKTREE_ID"
fi
WORKTREE_START_REF="HEAD"
git worktree add -b "$WORKTREE_BRANCH" "$WORKTREE_DIR" "$WORKTREE_START_REF"
if [ -f "$REPO_ROOT/cabal.project.local" ]; then
cp "$REPO_ROOT/cabal.project.local" \
"$WORKTREE_DIR/cabal.project.local"
echo "COPIED_CABAL_PROJECT_LOCAL=yes"
else
echo "COPIED_CABAL_PROJECT_LOCAL=no"
fi
HEAD_COMMIT="$(git -C "$WORKTREE_DIR" rev-parse HEAD)"
echo "WORKTREE_ID=$WORKTREE_ID"
echo "WORKTREE_BRANCH=$WORKTREE_BRANCH"
echo "REPO_KEY=$REPO_KEY"
echo "WORKTREE_PATH=$WORKTREE_DIR"
echo "REPO_ROOT=$REPO_ROOT"
echo "HEAD_COMMIT=$HEAD_COMMIT"
echo "WORKTREE_START_REF=$WORKTREE_START_REF"
```
After creation, record this mapping for the chat:
```text
workspace folder -> repo root -> worktree path
```
## Stay in the designated worktree
After `WORKTREE_PATH` is established, treat that absolute path as the only
checkout you may use for this repo until the user says to stop or uses
`/apply-worktree` or `/delete-worktree`.
Put every later read, edit, build, test, and repo-local git command under
`WORKTREE_PATH`. Prefer absolute paths under `WORKTREE_PATH` for tool calls
and shell `working_directory` / cwd. Before any edit or git write, confirm
with `git rev-parse --show-toplevel` (or the tool path) that you are still
inside `WORKTREE_PATH`, not `REPO_ROOT`.
Do not modify the primary checkout (`REPO_ROOT`) in this session, even when
it is on the same commit, the same branch tip, or shows the same file
contents in the IDE. Matching commits across checkouts are especially easy
to confuse: the IDE workspace often stays on `REPO_ROOT` while session work
must stay in `WORKTREE_PATH`. Same content at two paths is not permission to
switch. If a tool or the IDE opens a file under `REPO_ROOT`, retarget the
work to the corresponding path under `WORKTREE_PATH` instead of editing the
primary tree.
Give every sub-agent the absolute `WORKTREE_PATH` explicitly, and forbid
edits under `REPO_ROOT`.
## Commit as you go
After you make durable file changes in `WORKTREE_PATH`, commit them in that
worktree before moving on to the next substantial step. Do not leave a pile
of uncommitted work until the end of the task. After each logical unit of
edits (and again before you hand control back to the user), run `git status`
and `git diff` with cwd / `-C` set to `WORKTREE_PATH`, then create a commit
in `WORKTREE_PATH` when there are changes to keep. Write a clear commit
message that explains why the change was made. Do not commit in `REPO_ROOT`.
Skip a commit only when the tree is clean or the user has explicitly asked
you not to commit.
Do not search for or run `.cursor/worktrees.json`. The creation script
above copies `cabal.project.local` from `REPO_ROOT` into `WORKTREE_PATH`
when that file exists. That is the only worktree setup step. If the copy
fails, stop and report the failure. Do not switch branches or change the
main working tree.
At the end, report `WORKTREE_ID`, `WORKTREE_BRANCH`, `WORKTREE_PATH`,
`REPO_ROOT`, `HEAD_COMMIT`, `WORKTREE_START_REF`, and whether
`cabal.project.local` was copied. Tell the user merge-back is
`/apply-worktree` and cleanup is `/delete-worktree`.
Steps to Reproduce
- Open Cursor on the laptop, connected with SSH to a remote project.
- Keep a custom /worktree slash command on the laptop. Its file is
only the worktree procedure. There is no/worktreecommand on the server. - Open two agent chats in the same window on that remote project.
- In chat B, send /worktree followed by a feature 1 task.
- Within about 20 seconds, in chat A, send /worktree followed by a
different feature 2 task. - Inspect the prompt chat A receives. (By asking the AI to review it’s chat history)
The command block contains the saved worktree text, then the feature
1 task, then the feature 2 task. Chat A’s own message contains only
the feature 2 task.
Expected Behavior
Each chat’s expanded /worktree command contains the saved command
text plus only the text typed after /worktree in that same chat.
Another open chat’s message stays out of this command body.
Operating System
Linux
Version Information
Version: 3.26.13
VS Code Extension API: 1.128.0
Commit: 3bfec373749d3d4a53a151283022d49743ab50b0
Date: 2026-10-20T01:50:17.051Z
Layout: IDE
Build Type: Stable
Release Track: Default
Electron: 42.10.0
Chromium: 148.0.7778.280
Node.js: 24.18.1
V8: 14.8.178.38-electron.0
xterm.js: 6.1.0-beta.291
OS: Linux x64 7.0.0-38-generic
For AI issues: which model did you use?
grok 4.7
Additional Information
Provided by Grok 4.7:
The slash command is expanded on the laptop, then the finished prompt
is sent over SSH. The remote server does not have the worktree
command file. The laptop copy contains only the worktree procedure.
It ends at the instructions to report the worktree id and to use
/apply-worktree or /delete-worktree. The next text in the received
command block, still inside the command, was the other chat’s
feature 1 task, followed by this chat’s feature 2 task.
Two worktrees were created about 18 seconds apart. The feature 1
worktree kept the feature 1 branch name. The feature 2 worktree used
the same branch name plus a suffix because that branch already
existed.
If this request was made with Privacy Mode enabled, the request ID
may not include the prompt text. The command contents described above
are the record of what the agent received.
Does this stop you from using Cursor
No - Cursor works, but with this issue