Prevent agents from switching worktrees unexpectedly

In my opinion, one of Cursor’s biggest problems today is how it handles worktree and branch context for agents.

When I am working with a specific agent inside a specific worktree, that context should be explicitly preserved. Whether in the agent context itself or in the Git changes area, there should be something like a clear indicator or even a checkbox such as:

“This is the primary worktree for this agent.”

Because right now the workflow breaks like this:

I start working in a worktree.
I make a commit.
I open a PR.
I keep working with the same agent, on the same line of development.
I make another commit.
I update the PR.

And then suddenly Cursor starts working in another worktree for no clear reason.

The issue is that this other worktree often:

  • does not contain the code I was working on;

  • does not contain the real context of the task;

  • does not even contain the codebase related to the description of the work in progress.

So the agent completely loses continuity.

For people who use worktrees seriously as part of their development workflow, this is not a minor issue. It breaks context, productivity, and trust in the tool.

To me, this is one of Cursor’s most critical problems today:
the agent needs an explicit and persistent binding to the correct worktree/branch for as long as that line of work is active. In my opnion this is not a agent.md configuration or skill it is a cursor harness controlling it

Hey, thanks for the feedback. This is a known issue. The agent can lose its binding to the current worktree and switch to another one for no clear reason. You’re not the first user to report this.

A few similar threads for context:

Worktree support is being actively reworked. The team knows the current implementation isn’t reliable, especially around keeping the agent tied to a specific worktree. What you’re describing, explicit and persistent binding, is part of what’s planned. There’s no timeline yet, but your report helps us prioritize it.

For now, the workaround is to keep an eye on which worktree the agent is using. If it switches, tell it in your prompt to go back to the right worktree and branch.

Let me know if you have any questions.