Agent modifies git internal files outside workspace, corrupting worktree references

Hey, thanks for the detailed report. This is a known issue type. The agent can quietly switch to worktree mode and start writing to ~/.cursor/worktrees/ instead of your real project folder.

The extra issue you hit .git/worktrees/*/gitdir corruption happens because your workspace is already a git worktree. When Cursor creates its own managed worktree using git worktree add, Git updates internal references in the parent repo as a side effect. The sandbox currently doesn’t protect .git/worktrees/*/gitdir files.

Workaround for now:

  • Before you start an agent session, check the environment dropdown at the bottom of the chat panel. Make sure it says Local, not Worktree.
  • If the session already started with worktree enabled, start a new chat and pick Local explicitly.
  • You can also watch for the branch icon to the right of the model picker. If you see it, worktree mode is on.

Similar reports for reference:

The team is aware of this. Your report adds a helpful data point, especially the worktree inside a worktree case and the gitdir corruption detail. There’s no timeline for a fix yet, but this helps with prioritization.

Let me know if you have questions.