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 statuslists changes underservices/api/ortools/pipeline/after a “fix player movement” prompt.- Unity Editor still compiles; you only notice missing
Assets/Scripts/PlayerController.csupdates. - Agent transcript shows resolved paths outside
Assets/,Content/, orSource/. - 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
@workspaceor Agent scope includes every root in the.code-workspacefile.- No path-scoped
.cursor/rules— agents infer “scripts” generically. - Recently active file was a backend route, biasing the batch toward
src/server/. - Accepted agent diff without
git status— wrong tree merges look intentional. - 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:
- Close tabs from
backend-apiunless read-only reference. - Open any file under
unity-client/Assets/. - Prefix the task: “Only modify files under
unity-client/. Do not touchbackend-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/ortools/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):
- Open only
game/Clientin a single-folder window, or - Use a dedicated
.code-workspacewith 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-onlymatches the same prefix - [ ] Unity Refresh shows expected script changes in Project window
- [ ] Backend integration tests unchanged (no accidental API route edits)
- [ ]
.cursor/rulesfile 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.mdat repo root: one paragraph naming editable vs reference-only trees. - CI job: fail PRs that touch both
Assets/andservices/without thecross-cuttinglabel. - Onboarding screenshot: bad diff touching
services/api/auth.tsduring 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
- Cursor or Copilot Edits Wrong Folder in Multi-Root Game Repo - Rules and Workspace Scope Fix — baseline multi-root discipline
- Cursor or VS Code C# IntelliSense Dead in Unity Project - OmniSharp and SDK Fix — when the wrong root also breaks language service
- ElevenLabs Conversational AI Unity SDK 502 Bad Gateway - Retry and Fallback Fix — backend + client split for AI voice stacks
- Help queue #9 (Ollama local LLM fallback + Unity
Processredirect on Windows 11) — same client/backend monorepo wiring pattern when that article ships - Official: VS Code multi-root workspaces
Run the git status gate before you accept the next Agent batch—wrong-tree edits are cheaper to reject than to ship.