r/cursor • u/malwaremel • 2d ago
Question / Discussion How do you structure rules files when one project spans several repos?
I've been using AI coding tools daily and the single repo setup is easy: one rules file at the root and done. Once a project touches a few repos (say an API, a frontend and some shared config) I can't decide where the rules should live.
Do you keep one shared rules repo and copy or link it into each project, or let every repo have its own short file? And how do you handle the stuff that is true across all of them, like naming conventions or how the pieces talk to each other, without it going stale in three places?
7
Upvotes
2
u/ThamaraStudio 1d ago
We settled on thin per-repo files plus one shared conventions doc, and the split that works is: anything true across the whole system lives once in the shared doc (naming, error shape, commit style), while anything that describes this repo lives in its own rules file (how to run it, where the traps are, which commands are safe). The per-repo file starts with two or three lines pointing at the shared doc.
On distribution: we copy the shared file into each repo rather than linking it. Symlinks break on CI and fresh clones, and a stale copy is easy to spot and refresh while a broken link just silently removes your rules. A tiny script syncs them and diffs before overwriting, so local edits in one repo get reviewed back into the shared one instead of lost.
One thing that surprised us: keep each file short. Once a rules file passes a page or two the agent starts ignoring the middle of it, so we trim ruthlessly and move detail into the repo's docs folder with a pointer.
1
u/Numerous_Suit_2124 2d ago
are you opening the repos in separate windows or together in one workspace? if theyre separate, a quick pre-commit or install hook that pulls a shared global rules file from your config repo is probably the cleanest way to keep them from drifting
1
u/notarshzzz 2d ago
one thing i'd add — version the shared file like a dependency. i updated mine once and it quietly changed how the agent behaved in all three repos at the same time, took me forever to figure out which edit did it
3
u/locbuilds 2d ago
i'd keep one small shared rules repo and symlink it into each repo's .cursor/rules folder, so the cross-repo stuff like naming and how the services talk lives in exactly one place. then each repo only keeps a short file for its own quirks and nothing goes stale in three spots.
3
u/faceninjahq 1d ago
What tends to work is splitting rules by scope. Each repo keeps its own short rules file for things that are only true there (its stack, test commands, folder layout), and the cross-repo stuff like naming conventions and service contracts lives in one place, for example a shared rules repo pulled in as a git submodule or synced by a small script. That way there's a single source to update and nothing drifts across three copies. It also helps to keep the cross-repo rules about interfaces (API shapes, event names, who owns what) rather than implementation details, since those change far less often.
2
u/Michael_Jeffords 2d ago
what helped me was splitting by what the rule is about instead of by repo, so the shared file only holds the stuff that's actually a contract between the pieces, like naming and the shape of the api responses, and everything else lives in each repo next to the code it describes. i'd keep the shared one in a small config repo and copy it in with a script rather than symlinking, since symlinks tend to break on windows and in some ci checkouts, and then add a ci step that diffs each copy against the source and fails if someone edited it locally. that drift check is the part that actually fixes the going stale in three places problem, the layout alone doesn't. also worth scoping the per-repo rules with globs so the frontend ones don't load when you're working in the api, and keeping the shared file under 50 lines or so because past that the agent starts quietly ignoring the bottom half
1
u/chuch1234 2d ago
Maybe you could do a package and install the common rules as a dependency. I haven't tried it but it seems like it would make sense, just like shared code.
1
u/DoOmXx_ 1d ago
short file per repo for local quirks and the cross-repo stuff in one shared file, rules go stale mostly when the same convention lives in three places