Cursor Rules for Large Monorepos: Scope by Package, Not Globally
One global rules file fails in a monorepo. Learn Cursor rules for large monorepos: scoped per-package rules mapped to the package graph, with an impact pass.
What Cursor Rules in a Monorepo Have to Solve
Cursor rules for monorepos are the per-package conventions that keep an AI agent applying the right standard in the right directory. Cursor reads scoped rules from .cursor/rules, so a backend package and a UI package can each carry their own conventions instead of sharing one global file that fits neither.
The official and community advice gets the mechanism right and the hard part wrong. Cursor's own agent best-practices post is generic. Instructa's guide to large codebases in Cursor recommends per-package rules and .cursorignore. The ai-monorepo-scaffold repo shows one worked example.
The advice lands at "put .cursor/rules per package and use .cursorignore." Correct, and incomplete. It tells you to scope rules but not how to derive the scoping from the repo's actual package graph, and it skips the move that matters most in a monorepo: an impact-analysis pass before the agent edits, so a change to a shared package doesn't quietly break six consumers.
Why One Global Rules File Fails Here
A single rules file is fine in a single-purpose repo. In a monorepo it actively misleads. The agent reading a global file gets backend conventions while editing the design system, and frontend conventions while touching the API. It then applies whichever rules it weighted, which is rarely the right set for the package in front of it.
The deeper failure is blindness to blast radius. In a monorepo, the cost of a change isn't local. Edit a shared types package and every consumer inherits the change, including the three you forgot existed. A global rules file says nothing about this. The agent edits the shared package, the build passes locally, and a downstream package breaks in CI because nothing mapped the dependency before the edit.
So two problems compound: wrong rules applied to the wrong package, and edits made without knowing what they touch. Scoping fixes the first. An impact pass fixes the second.
What Scoped Monorepo Rules Need
- A package map. Which packages exist, what each owns, and which depend on which. The rules scoping follows this graph.
- Per-package conventions. Each package's own rules in its own
.cursor/rules, so the agent reads only what applies where it's editing. - A thin root file. The genuinely shared rules, kept short, so common conventions aren't duplicated across every package.
- An impact-analysis pass. Before editing a shared package, list the consumers a change will reach.
- An ignore scope. Use
.cursorignoreto keep generated and vendored packages out of the agent's context entirely.
The package map is the input everything else derives from. Get the dependency graph wrong and the scoping inherits the error.
A Prompt That Maps the Graph to Scoped Rules
A prompt can read the monorepo's structure and produce both the scoping plan and the impact pass.
You scope Cursor rules across a monorepo.
Package graph: {{package_graph}}
Shared conventions: {{shared_rules}}
Do two things:
1. For each package, list the rules that belong in its
.cursor/rules. Pull shared rules up to a thin root file.
Output a table: Package | Scoped rules | Inherits from root.
2. Impact pass: given a planned change to {{target_package}},
list every consumer that change reaches, depth-first, and
flag any public-API change as "breaks consumers."
Use only the graph provided. Don't assume packages not listed.
The second half is the part the existing guides skip. Before the agent touches a shared package, it gets a list of what the change reaches. That turns a blind edit into a scoped one.
The depth-first instruction is doing specific work. The packages that break in CI are rarely the direct consumers, which a developer usually remembers. They're the transitive ones, two or three hops down the graph, that nobody holds in their head. A change to a shared validation helper breaks the API package directly, and the API package's break ripples into the two services that import it. An impact pass that walks the graph depth-first surfaces those second-order consumers. A shallow "who imports this directly" check misses exactly the packages that cost you the failed pipeline. Tell the prompt to go deep, and feed it the real dependency edges, because a guessed graph produces a confidently wrong impact list.
Scoping rules per package stops the agent from applying backend conventions to the UI. But the failure that actually costs a CI run is editing a shared package without knowing its consumers. An impact-analysis pass that lists every downstream package before the edit is the step generic Cursor advice leaves out, and it's the one that matters most at monorepo scale.
How the Agent Handles Scope Across a Monorepo
Scoped rules and an impact pass change agent behavior in measurable ways.
| Setup | Agent behavior | Risk |
|---|---|---|
| One global rules file | Applies mixed conventions everywhere | Wrong rules in half the packages |
Per-package .cursor/rules | Reads only the editing package's rules | Low, if the graph is right |
| No impact pass on shared edits | Edits shared code, misses consumers | Downstream breaks in CI |
| Impact pass before shared edits | Lists consumers, scopes the change | Catches public-API breaks early |
.cursorignore on generated packages | Keeps noise out of context | Cleaner reasoning, fewer wrong edits |
The pattern: scope the rules to the package graph, and never let the agent edit a shared package without the impact pass first. Cursor will read whatever rules you place where. It won't reason about blast radius unless a prompt makes it. That reasoning is the prompt's job, not the editor's.
Variables You'll Set
| Variable | Required | What it is |
|---|---|---|
{{package_graph}} | Yes | The packages and their dependency edges, so scoping follows reality |
{{shared_rules}} | Yes | Conventions common to all packages, pulled up to the root |
{{target_package}} | Optional | The package about to change, for the impact pass |
Getting Started
- Build the package map: every package and what depends on what.
- List the conventions that are truly shared versus package-specific.
- Run the scoping prompt to place rules per package plus a thin root.
- Add
.cursorignoreentries for generated and vendored packages. - Before any shared-package edit, run the impact pass.
- Scope the edit to the consumers the impact pass surfaced.
- For a packaged impact workflow, start with the Monorepo Impact Analysis Agent Pack.
Scoped rules in a monorepo are just per-package versions of a good rules file, so the authoring technique carries straight over. The Code Review Policy System Prompt pairs with the impact pass: the impact analysis says what a change reaches, and the review policy grades whether each touched package's change is sound.
The Monorepo Impact Analysis Agent Pack does this end-to-end: a {{package_graph}} variable feeds a scoped-rules table plus a depth-first impact pass that flags public-API changes before the agent edits. It's part of The Complete AI Prompts Bundle, a one-time lifetime license to the whole catalog plus packs added later, which is the obvious buy if your monorepo runs more than one of these agent jobs.
A monorepo needs rules scoped to its package graph and an impact pass before any shared edit. One global file gives the agent the wrong conventions and no sense of blast radius. For the single-file version of this technique, see how to write a .cursorrules file that actually works. And for the cross-tool config that sits above per-package rules, how to write an AGENTS.md file with AI covers the root-plus-scoped pattern that mirrors monorepo rule scoping.
See all coding agent prompt packs →Common questions
How do Cursor rules work in a monorepo?
Should I use one .cursorrules file or many in a monorepo?
Why does my agent edit the wrong packages in a monorepo?
Get the prompt packs this guide is built on
Ready-to-paste prompts with documented variables and worked examples for ChatGPT, Claude, and Gemini. One-time payment, own it forever.
More prompt guides

A Production Readiness Review Prompt That Grades a Service
A service ships, and two weeks later it pages someone at 3 a.m. because nobody asked whether it had alerting before launch. The production readiness review checklist exists to catch that. Most teams k…

Write an AI Code Review Prompt That Actually Finds Bugs
A developer pastes a 400-line diff into ChatGPT, types "review this," and gets back three friendly paragraphs ending in "overall this looks solid." The off-by-one in the pagination loop is still there…

An AI PR Review Prompt Template for Clean Diffs
The difference between a PR review that catches the regression and one that waves it through usually isn't the model. It's whether the prompt has a workflow or just a wish. "Review this pull request"…