Programming & Scripting Errors

Cursor or VS Code AI Agent Applies Edits to Backend Workspace Instead of Game Assets - Multi-Root Scope Fix

Stop Cursor Agent and VS Code AI agents from patching Node or Python service folders when you meant Unity Assets or Unreal Source—multi-root scope fences, rules, and pre-accept git checks.

By GamineAI Team

If Cursor Agent or a VS Code AI agent refactors your Node/Python backend while you asked for a Unity Assets/ change, the session scoped the wrong workspace root. Builds look fine until CI shows gameplay scripts never moved—or worse, a service config changed silently.

2026 indie repos almost always pair a game client with a small API or tooling repo in one IDE window. Agent mode batches diffs faster than chat, so wrong-root merges jumped from “annoying” to release-week blockers. This article tightens scope so agent runs stay under your game tree.

Problem summary

Typical symptoms:

  • git status lists changes under services/api/ or tools/pipeline/ after a “fix player movement” prompt.
  • Unity Editor still compiles; you only notice missing Assets/Scripts/PlayerController.cs updates.
  • Agent transcript shows resolved paths outside Assets/, Content/, or Source/.
  • Duplicate folder names (Scripts, Shared, Utils) exist in both client and backend roots.

Exact failure wording teams report:

  • “Agent applied 14 files but none were in my game project.”
  • “Copilot multi-root picked the backend because that file was open last.”

Root causes

  1. @workspace or Agent scope includes every root in the .code-workspace file.
  2. No path-scoped .cursor/rules — agents infer “scripts” generically.
  3. Recently active file was a backend route, biasing the batch toward src/server/.
  4. Accepted agent diff without git status — wrong tree merges look intentional.
  5. Split-brain prompts — “update auth and player” in one run without per-root tasks.

Fastest safe fix (under 10 minutes)

Step 1 — Declare one primary game root for this session

In your .code-workspace:

{
  "folders": [
    { "name": "unity-client", "path": "game/Client" },
    { "name": "backend-api", "path": "services/api" }
  ]
}

Before Agent/Copilot edit:

  1. Close tabs from backend-api unless read-only reference.
  2. Open any file under unity-client/Assets/.
  3. Prefix the task: “Only modify files under unity-client/. Do not touch backend-api/.”

Step 2 — Add path fences in .cursor/rules/

In the game repo (or monorepo root if rules apply globally), create .cursor/rules/game-client-scope.mdc:

# Game client scope (mandatory)

- Editable roots: `game/Client/Assets/`, `game/Client/Packages/` (manifest only).
- Read-only: `services/`, `tools/`, `docs/`.
- Never create new `.cs` files outside `Assets/`.
- Before finishing, list every changed path; abort if any path starts with `services/`.

Point Cursor Rules at this file for Agent and Composer sessions on the client.

Step 3 — Run git status before accepting the agent batch

git status --short

Pass criteria:

  • Every modified path starts with your game prefix (e.g. game/Client/Assets/).
  • Zero unexpected services/ or tools/ lines.

If any wrong path appears, Reject the agent run and restate Step 1’s prefix.

Step 4 — Split workspaces for risky refactors

For large migrations (Input System swap, namespace rename):

  1. Open only game/Client in a single-folder window, or
  2. Use a dedicated .code-workspace with one folder entry.

Multi-root is fine for navigation; high-risk agent batches deserve a single root.

Verification checklist

  • [ ] Agent transcript lists only paths under the game root you named
  • [ ] git diff --name-only matches the same prefix
  • [ ] Unity Refresh shows expected script changes in Project window
  • [ ] Backend integration tests unchanged (no accidental API route edits)
  • [ ] .cursor/rules file committed so teammates get the same fences

Alternative fixes

Situation Approach
Must keep backend open for reference Mark backend root read-only in rules; use Ask mode there, Agent only on client
Two Unity projects in one repo Separate .code-workspace files per game; never one Agent task across both
VS Code Copilot without Cursor rules Use .github/copilot-instructions.md with the same path allow-list
Unreal + services monorepo Replace Assets/ with Source/<GameModule>/ in rules

Prevention tips

  • Add AGENT_SCOPE.md at repo root: one paragraph naming editable vs reference-only trees.
  • CI job: fail PRs that touch both Assets/ and services/ without the cross-cutting label.
  • Onboarding screenshot: bad diff touching services/api/auth.ts during a gameplay task.
  • Re-run Cursor or Copilot Edits Wrong Folder in Multi-Root Game Repo habits before enabling Agent on a new machine.

Troubleshooting

Symptom Likely cause Fix
Rules ignored Rules file not in indexed workspace Move rules to repo root Cursor opened
Still edits backend Prompt lacks path prefix Repeat “under unity-client/ only”
Partial correct diff Mixed task in one run Split backend task to second session
Agent creates file at repo root No Assets/ constraint Add “never create files outside Assets/” rule
Works for you, fails for teammate Rules not committed git add .cursor/rules

FAQ

Is this different from the Copilot wrong-folder article?

Yes. That article covers general multi-root scope. This one targets Agent batch applies in client + backend monorepos where Assets/ must win.

Should I delete the backend folder from the workspace?

Keep it for search/reference. Fence edits, do not delete the root.

Does @folder fix scope?

Helpful if you @ only unity-client/Assets. Still combine with rules and git status.

Will GitHub Copilot Workspace respect .cursor/rules?

No — duplicate constraints in copilot-instructions.md for VS Code-only teammates.

Related links

Run the git status gate before you accept the next Agent batch—wrong-tree edits are cheaper to reject than to ship.