Back to Learn

    Cursor Rules: How .mdc Files Work, Three to Copy, and What 498 Public Rules Show

    Cursor rules are markdown files that Cursor's Agent reads before it edits your code, so the same conventions hold in every chat without you retyping them. This guide takes the format from Cursor's documentation, measures two public collections of rules against that guidance, writes three rule files for the folder structure a Lovable export actually has, and reports the one controlled study on whether files like these help at all.

    Updated

    Cursor rules hero: the guide title beside an editor card showing a .cursor/rules/lovable-project.mdc file with description, globs and alwaysApply frontmatter and three bullet rules

    What are Cursor rules, and where do they live?

    A Cursor rule is persistent instruction text that Cursor puts into the Agent's context. The rules documentation, read on 26 September 2026, lists four kinds, and the first is the one people mean when they say “cursor rules”:

    The four rule types in Cursor's documentation, with the docs' own wording
     Where it livesWhat the docs say
    Project Rules.cursor/rules/*.mdc, committed with the repoVersion-controlled and scoped to the codebase; the format the rest of this page covers.
    User RulesCursor settings, not in any repo“Global to your Cursor environment. Used by Agent (Chat)” and, per the same page, “not applied to Inline Edit (Cmd/Ctrl+K)”.
    Team RulesThe team dashboard“Team and Enterprise plans can create and enforce rules across their entire organization”; an enforced rule “is required for all team members and cannot be disabled”.
    AGENTS.mdRepo root, or any subdirectory“Agent instructions in markdown format. Simple alternative to .cursor/rules”; nested files apply “when working with files in that directory”.

    Creation is two commands. The docs say to “type /create-rule in Agent and describe what you want”, after which “Agent generates the rule file with proper frontmatter and saves it to .cursor/rules”, or to add one from the Customize sidebar. Either way the result is a plain file you can also write by hand, which is what the rest of this guide does.

    One thing the page does not contain, as of 26 September 2026, is any mention of the single-file .cursorrules format that older tutorials describe. The collection with the most stars on GitHub, awesome-cursorrules, still carries the old name but has converted all 257 of its files to .mdc. Treat the folder as the format and the root file as history.

    How does a .mdc rule file work?

    An .mdc file is markdown with a YAML header. The header has three fields, and the docs define them as: alwaysApply, a boolean that “determines if rule applies universally or conditionally”; description, a string that “explains rule purpose for Agent relevance detection”; and globs, comma-separated “file path patterns triggering auto-attachment”. The example the docs give is short enough to quote in full:

    Example from cursor.com/docs/rules
    ---
    alwaysApply: true
    ---
    
    - All source files must include the company copyright header
    - When you are unsure about implementation details, read the relevant
      source files before proposing changes
    - Never modify generated files in the `dist/` or `build/` directories

    The three fields combine into four application modes. The names below are the docs' names, and the trigger column is quoted from the same table:

    Cursor's four rule application modes and the frontmatter that produces each
     FrontmatterWhen it attaches (docs wording)
    Always ApplyalwaysApply: trueApplied to every chat session.
    Apply Intelligentlydescription set, no globs“When Agent decides it's relevant based on description”.
    Apply to Specific Filesglobs set“When file matches a specified pattern”.
    Apply Manuallyneither, or invoked by name“When @-mentioned in chat (e.g., @my-rule)”.
    How a rule gets into the Agent's context
    1You senda message2alwaysApply rulesload3Globs checkedagainst files in play4Descriptionsread5@rule addedif you named one
    1. You send a message: in Agent, not Inline Edit
    2. alwaysApply rules load: every session
    3. Globs checked: against files in play
    4. Descriptions read: Agent picks relevant ones
    5. @rule added: if you named one

    Sequence assembled from the application modes and frontmatter fields on Cursor's rules page, read on 26 September 2026.

    Three more lines from the docs matter in practice. “Keep rules under 500 lines.” “Split large rules into multiple, composable rules.” And “reference files instead of copying their contents”, which is the @filename.ts syntax that includes a file without pasting it. The next section shows how far public rules sit from those three lines.

    What do 498 public Cursor rules actually look like?

    Most guides quote the 500-line rule and move on. We cloned the two most-starred public collections and measured every file on 26 September 2026: awesome-cursorrules, community-written and converted to .mdc, and awesome-cursor-rules-mdc, whose README says its files were produced by an LLM from web search results. The script is in the site repository, so the numbers are reproducible.

    Two public Cursor rule collections measured file by file on 26 September 2026
     Community-written (awesome-cursorrules)LLM-generated (awesome-cursor-rules-mdc)
    GitHub stars, last push40,839, 2026-05-303,574, 2026-05-19
    .mdc files257241
    Median length (lines)69307
    90th percentile (lines)201427
    Over the 500-line guidance6 files6 files
    globs set to **/* (attached to every file)212 (82%)82 (34%)
    alwaysApply: true10
    Reference a file with @path13
    Length of 257 community-written Cursor rules
    Under 50 lines8950 to 99 lines88100 to 299 lines71300 to 499 lines3500 lines and over6
    Length of 257 community-written Cursor rules
    Categoryrules
    Under 50 lines89
    50 to 99 lines88
    100 to 299 lines71
    300 to 499 lines3
    500 lines and over6

    Raw line counts of every .mdc in PatrickJS/awesome-cursorrules, measured 26 September 2026 with scripts/measure-cursor-rules.mjs.

    The two collections disagree by a factor of four on length. Hand-written rules cluster under 100 lines; the generated ones cluster between 100 and 500, because each is a full “best practices” essay for one library. Both stay under the 500-line limit almost everywhere, with 6 exceptions each. Where both fall short of the docs is scoping.

    What the globs target in 257 community-written rules
    **/* (every file)212.ts33.tsx21.py15.js9.txt7.jsx6.go6.vue6
    What the globs target in 257 community-written rules
    Categoryrules
    **/* (every file)212
    .ts33
    .tsx21
    .py15
    .js9
    .txt7
    .jsx6
    .go6
    .vue6

    Extensions named in the globs field of every .mdc in PatrickJS/awesome-cursorrules, brace groups expanded; one rule can name several. Measured 26 September 2026.

    82% of the community rules set globs: **/*, which attaches them to every file and makes them Always Apply rules in everything but name. Only 1 file in 498 uses alwaysApply: true honestly, and 4 reference another file with @path instead of pasting. The four modes exist; the public corpus uses one of them.

    Whether any of this helps is a separate question, and it has one controlled answer. Gloaguen, Mündler, Müller, Raychev and Vechev at ETH Zurich tested repository context files (AGENTS.md and equivalents) across coding agents and models on SWE-bench tasks plus a fresh issue set, in Evaluating AGENTS.md (arXiv 2602.11988, revised 23 June 2026). Their abstract: “providing context files does not generally improve task success rates, while increasing inference cost by over 20% on average”, and “while instructions in the context files are well followed by coding agents, repository overviews, although popular and recommended by model providers, are not helpful”. Their conclusion is the design rule for everything below: context files “are useful for specifying non-standard coding practices”. Write prohibitions and conventions the agent cannot infer from the code. Do not write a tour of the codebase.

    Which rules should a Lovable export carry?

    Lovable's Git sync documentation says you can “clone that repository, edit the code with your own IDE or coding assistant, and push the result back”, one branch at a time. Every export has the same shape, and ours is no exception: this site's previous version was built in Lovable (the current one is Next.js, which is a story for the Lovable vs Cursor page). Reading that repository gives the non-standard facts a rule should state: Vite 5 with React 18 and TypeScript 5, Tailwind 3 and shadcn/ui with 49 generated primitives in src/components/ui, a lovable-tagger plugin in vite.config.ts, a dev server pinned to port 8080, a generated Supabase client and a 332-line types.ts under src/integrations/supabase whose first line reads “This file is automatically generated. Do not edit it directly”, 23 migrations and 12 edge functions under supabase/. Three rules cover it.

    1. The project rule, always on

    Conventions Cursor cannot infer plus the two Git rules from Lovable's docs, which warn: “Do not force-push, rebase, or squash commits that are already on the synced branch. Lovable keeps its own copy of that branch.”

    .cursor/rules/lovable-project.mdc
    ---
    description: Conventions of a project exported from Lovable (Vite, React, TypeScript, Tailwind, shadcn/ui, Supabase), synced two ways with GitHub.
    globs:
    alwaysApply: true
    ---
    # Lovable export
    
    - Stack: Vite 5, React 18, TypeScript 5, Tailwind 3, shadcn/ui, Supabase JS 2. "@/" maps to "src/".
    - Never edit src/integrations/supabase/client.ts or types.ts. Both are generated and say so in their first line. Regenerate types after a migration instead.
    - Schema changes are new files in supabase/migrations/, never edits to old ones. Enable RLS in the same migration (see supabase-rls).
    - Server-side code lives in supabase/functions/<name>/index.ts and reads secrets with Deno.env.get(). Nothing secret goes under src/.
    - src/components/ui/ is shadcn output. Compose new components in src/components/; do not hand-edit the primitives.
    - Keep lovable-tagger in vite.config.ts and the dev server on port 8080; Lovable's preview expects both.
    - Work on a feature branch. Never force-push, rebase or squash commits already on the synced branch: Lovable keeps its own copy and edits made only in Lovable can be lost.
    - After a merge, the first prompt back in Lovable reads: "I changed [files] outside Lovable to [describe the change]."

    2. The database rule, scoped to migrations and functions

    Row-level security is where generated apps fail. Insufficient RLS in Lovable-generated projects has its own record, CVE-2025-48757, which Lovable disputes on the grounds that customers own their data protection; either way the policy has to be written, and a glob-scoped rule makes Cursor write it every time it touches supabase/. The verification-query habit comes from our build kits, whose schemas ship with the queries that proved their policies.

    .cursor/rules/supabase-rls.mdc
    ---
    description: Row-level security for every table, and the rules for edge functions that touch data.
    globs: supabase/migrations/**/*.sql, supabase/functions/**/*.ts
    alwaysApply: false
    ---
    # Database access
    
    - Every "create table" is followed by "alter table ... enable row level security" and at least one policy, in the same migration file.
    - Policies compare auth.uid() with an owner column or a membership table. Never "using (true)" on a table that holds user data.
    - The service-role key is used only inside edge functions. It never appears under src/ or in a client bundle.
    - Edge functions verify the caller's JWT before reading or writing and return 401 otherwise.
    - After a migration, add two verification queries to the PR: one as the owner (expects rows) and one as a different user (expects zero rows).

    3. The landing page rule, attached by description

    The one rule most exports lack. It is the checklist behind every prompt on the landing page prompts page, reduced to five lines Cursor applies when it decides a marketing page is in play.

    .cursor/rules/landing-copy.mdc
    ---
    description: Copy and structure rules for landing pages, waitlists and any page a visitor sees before signing up. Use when editing marketing pages under src/pages.
    globs:
    alwaysApply: false
    ---
    # Landing pages
    
    - One offer and one primary action per page. Secondary links go in the footer.
    - No invented proof. No placeholder testimonials, logos or user counts; leave a "proof pending" comment instead.
    - Lead capture writes to an insert-only table and stores the UTM parameters from the URL.
    - The file starts with a comment naming the traffic source the page was built for.
    - The headline says what the product does in plain words. No superlatives.

    Total: 39 lines across three files, all under the guidance by a wide margin, one Always Apply, one by glob, one by description. None describes the architecture, because Cursor can read it and the ETH result says the description would not help.

    How do Cursor rules compare with Lovable knowledge, CLAUDE.md and AGENTS.md?

    Every tool a Lovable builder touches has its own version of the same file. The mechanics rhyme; the limits and the scoping do not. Sources are the Cursor rules page, Lovable's knowledge documentation and Claude Code's memory documentation, all read on 26 September 2026.

    Persistent instruction files across Cursor, Lovable and Claude Code, from each tool's documentation
     Cursor rulesLovable knowledgeClaude Code CLAUDE.md and .claude/rules/AGENTS.md
    Where it lives.cursor/rules/*.mdc in the repo; User and Team rules outside itWorkspace settings and Project settings, not in the repoCLAUDE.md at the root or in .claude/, plus .claude/rules/*.mdRepo root or any subdirectory
    Scoping to filesglobs, description or manual @mentionNone; project knowledge overrides workspace knowledgepaths: frontmatter in .claude/rules/, loaded “when Claude reads files matching the pattern”Per directory: nested files apply to that directory
    Length guidance“Keep rules under 500 lines”Up to 10,000 characters per level; “bullet lists and direct rules” over paragraphsNo line cap on the page; a troubleshooting entry for a CLAUDE.md that is too largeNone stated by Cursor; Claude Code reads it like a CLAUDE.md
    Read byCursor Agent only (not Inline Edit for User Rules)Lovable, on every message: “reads your project knowledge, workspace knowledge, and project code”Claude CodeCursor, and Claude Code when no CLAUDE.md exists above the working directory
    EnforcementTeam Rules can be enforced; project rules are contextContext“Context, not enforced configuration”; a PreToolUse hook blocks actionsContext

    The practical consequence for a builder who moves between Lovable and Cursor: the Lovable knowledge file and the Always Apply rule should say the same things, and the file-scoped rules have no Lovable equivalent, so they live only in the repo. If Claude Code is in the mix as well, the memory docs note it reads AGENTS.md “only when you have no CLAUDE.md in your working directory or above it”, which makes AGENTS.md the one file all three tools can share. Our Claude Code commands guide covers the skills side of that setup.

    What goes wrong with Cursor rules, and how do you avoid it?

    • The rule is a codebase tour. The ETH study found repository overviews “are not helpful” while instructions “are well followed”. Delete the paragraph that explains what the app does and keep the bullets that say what not to do.
    • Every rule is attached to every file. 82% of the community rules use globs: **/*. Each one rides along on every request, which is how the cost the ETH study measured accrues, with none of the scoping the format offers. Set globs to the directory the rule is about.
    • Vague guidance. The docs' own line is “Avoid vague guidance. Write rules like clear internal docs.” “Write clean code” changes nothing; “never using (true) on a table with user data” changes the migration.
    • The rule pastes a file that then drifts. Only 4 of 498 public rules use @path. Reference the schema or the config; do not copy it.
    • User Rules expected in Inline Edit. The docs are explicit that User Rules “are only used by Agent (Chat)”. A convention that must hold in Cmd+K edits goes in a project rule.
    • Cursor edits break the Lovable sync. A rewrite of the synced branch is the failure Lovable's docs warn about by name. The Git lines in the project rule exist so the agent never proposes one. The rest of the sync workflow is on the app builder guide, and the mistakes that cost rebuild rounds on the Lovable side are on common mistakes.

    Sources

    All checked on 26 September 2026. Corpus numbers reproducible with scripts/measure-cursor-rules.mjs in the site repository.

    Frequently asked

    What is the difference between .cursorrules and .cursor/rules?↓
    The single .cursorrules file at the project root was the original format. The current one is a .cursor/rules folder of .mdc files, each with frontmatter that decides when it applies. Cursor's rules documentation, read on 26 September 2026, documents only the folder format, User Rules, Team Rules and AGENTS.md, and does not mention .cursorrules at all. The largest community collection has converted every one of its 257 files to .mdc.
    How long should a Cursor rule be?↓
    Cursor's guidance is under 500 lines per rule, split into composable files. The community-written collection we measured has a median of 69 lines; the LLM-generated one has a median of 307 and 6 files over the limit. Given the ETH Zurich finding that context files raise inference cost by over 20% on average without raising task success, shorter is the safer default.
    How many Cursor rules should a project have?↓
    As many topics as you would write separate internal docs for, which for a small app is three to five: project conventions, database access, and one rule per area with its own patterns, such as marketing pages or API handlers. Cursor's docs say to keep rules focused on patterns you use frequently and to split large rules into multiple composable ones; they give no maximum count.
    Do Cursor rules cost anything?↓
    Not as a line item. A rule that is in context is part of the request, so it consumes context window on every message it attaches to. Cursor's rules page gives no token figure. The only measured number we found is from the ETH Zurich study of context files across coding agents: inference cost up by over 20% on average with the file present.
    Can I reuse my Lovable knowledge file as a Cursor rule?↓
    Yes, and it is the fastest start. Lovable's project knowledge is a plain-text brief of up to 10,000 characters that Lovable reads on every message. Paste it into an alwaysApply rule, then cut the parts that describe the codebase (Cursor can read the code) and keep the decisions, conventions and prohibitions. Keep the two in sync by hand; nothing links them.
    Should I use AGENTS.md instead of Cursor rules?↓
    Use AGENTS.md when more than one coding agent works on the repository. Cursor's docs call it a simple alternative to .cursor/rules and apply nested ones per subdirectory, and Claude Code reads it as project instructions when no CLAUDE.md exists. What it lacks is the frontmatter: no globs, no description-based attachment and no manual mode, so file-scoped rules still belong in .cursor/rules.

    Related reading

    Written by

    Marco Kohns

    Marco Kohns

    Founder of ProtoBites - Venture Growth Studio

    Growth PM at a Silicon Valley scale-up (a16z and General Catalyst backed), ex-Techstars where he consulted 13 early-stage startups, Reforge-trained. Every prompt on this site comes out of shipping ProtoBites' own portfolio products.