Scope each rule to the code it protects: that is the first of the Cursor rules best practices. Cursor loads a .mdc rule from .cursor/rules in one of four ways: always, when its globs match a file in context, when the agent finds its description relevant, or on an @-mention, so a payments rule can attach only around payment code.

Cursor rules best practices: the ten-line checklist

Good Cursor rules are short, scoped and checkable: one concern per .mdc file, globs instead of always-on rules, a protected path and a command that passes or fails in every guard rule, files referenced rather than pasted, and a CI check behind every rule that must hold.

In its section on Team Rules, Cursor’s documentation says some teams use enforced rules in internal compliance workflows, and then adds: “AI guidance should not be your only security control.” That sentence is the reason for line 10 below, and the hooks and CI checks that enforce rules are the layers that turn a rule from advice into a gate.

#PracticeWhyThe check that proves it
1One concern per rule file; split a large rule into smaller, composable onesA rule that covers five topics loads for all five or for noneEach file’s description fits in one sentence
2Keep each rule short: Cursor’s docs say under 500 linesA long rule costs context every time it loads and gets skimmed in reviewgrep -rc '' .cursor/rules shows no file near 500 lines
3Scope with globs; use alwaysApply: true only for lines every request needsAn always-on rule sits in every chat, including the ones about CSSgrep -rl 'alwaysApply: true' .cursor/rules lists only a few files
4Write a guard rule as a path plus a command that passes or fails”Be careful with payments” cannot fail; “no change under the payments folder unless the payment tests pass” canEvery guard rule names a test command
5Name the protected paths: auth, roles and permissions, payments and webhooks, migrations, secretsThese are the paths where one wrong line leaks data or moneyEach path has a rule whose globs cover its folder
6Reference files instead of pasting themKeeps rules short and stops them going stale as the code changesThe rule points at files with @filename instead of copying their contents
7Leave style to the linterCursor’s docs say the agent already knows common style conventionsFormatting lives in the linter config, not in a rule
8Add a rule when the agent repeats a mistake, and update it when it happens againRules written ahead of real mistakes guess at problemsEach rule’s history points to a mistake it answers
9Commit rules to gitThe team, and the client at handover, inherit them with the codegit ls-files .cursor/rules lists every rule
10Put a CI check behind every rule that must holdA rule is context the agent weighs, not a controlA branch that breaks the rule fails CI

Lines 1, 2 and 6 to 9 restate Cursor’s own best practices for Cursor rules; lines 3, 4, 5 and 10 are ours, written for repositories where a wrong edit reaches auth or money. Well under Cursor’s 500-line guideline, we’d keep a guard rule to about a screenful, short enough that a reviewer reads all of it before approving a change. Those two size limits are the Cursor rules file best practices that keep a rule cheap to load. Line 4 decides whether the rule protects anything, and as we see it the best Cursor rules have its shape: a path, a constraint and a command that can fail.

The four rule types and the .mdc frontmatter that sets them

Cursor rule types are set by three frontmatter fields: alwaysApply, description and globs. Always Apply loads in every chat session, Apply to Specific Files loads when a matching file is in context, Apply Intelligently loads when the agent finds the description relevant, and Apply Manually needs an @-mention.

Rule typealwaysApplydescriptionglobsWhen it loads
Always ApplytrueignoredignoredAlways included in the chat session
Apply to Specific Filesfalsenot neededprovidedAuto-attached when a matching file is in context
Apply IntelligentlyfalseprovidedomittedThe agent reads the description and pulls the rule in when relevant
Apply ManuallyfalseomittedomittedOnly when you @-mention the rule in chat, for example @my-rule

The table restates Cursor’s rules documentation as read on October 5, 2026. Older posts on Cursor’s forum call the two middle rule types Auto Attached and Agent Requested, and the same frontmatter block selects each one under either name.

The Cursor MDC format is that frontmatter between two --- lines, followed by the rule itself in ordinary Markdown. An Apply to Specific Files rule looks like this:

---
globs: src/payments/**, src/webhooks/**
alwaysApply: false
---

- Verify the webhook signature on the raw request body before parsing it.

Project rules must use the .mdc extension. A plain .md file in .cursor/rules is ignored by the rules system, because it has no frontmatter to say when it applies, so plain .md files written for Cursor belong in AGENTS.md instead. Setting alwaysApply: true in a Cursor rule’s frontmatter overrides the other two fields: globs and description are ignored. Keep Cursor rules on Always Apply for the few lines every request needs, such as the package manager and the command that must pass before a task is done.

Cursor’s MDC guidelines allow subfolders inside .cursor/rules, and its help page calls a flat folder simpler to manage. New rules come from /create-rule, typed in Agent with a description of what you want, or from Customize in the sidebar, then Rules, then Add Rule; both create the file in .cursor/rules, and /create-rule also writes its frontmatter. A Cursor rules MDC file made either way is an ordinary file in the repository, so you edit, review and commit it like the code around it.

Globs: scoping a rule to the files it guards

Cursor rules globs are file patterns in a rule’s frontmatter: ** matches any number of folders and a comma separates patterns, so one rule can cover the auth and the payments folders.

PatternMatches
*Any single file name segment
**Any number of directories (recursive)
*.tsAll .ts files in the root
**/*.tsAll .ts files in any directory
src/**All files anywhere under src/
src/**/*.tsxAll .tsx files anywhere under src/
docs/**/*.md, docs/**/*.mdx.md and .mdx files under docs/ (comma-separated)

The patterns come from the same documentation page, read on the same date.

For guard rules, group paths by the lines they share. The security rule further down covers auth, permissions, payments and webhooks because the same lines apply to all four; migrations get a rule of their own, since a migration’s checks are different. Each rule’s globs name those folders and nothing wider. A rule scoped to **/* attaches whenever any file is in context, which in practice makes it an always-on rule in disguise. Scoping guard rules by path is one of the standards for teams that build with AI agents, and it only works if the patterns are right, so test Cursor globs against one real file path before trusting them.

Cursor global rules, project rules and team rules: where each lives and which wins

Cursor global rules are User Rules, set once under Customize, Rules and applied in every project; Project Rules live in the repository and Team Rules come from the dashboard. When they conflict, Team Rules win, then Project Rules, then User Rules, and all of them are merged.

Rule sourceWhere it livesWho it applies toHow it is turned on or off
Project Rules.cursor/rules in the repository, as .mdc files under version controlEveryone who works in the repositoryThe type in each file’s frontmatter; Customize shows every rule and its status
User Rules (settings)Customize, Rules; stored on your Cursor account and synced when you sign in on another machineYou, in every project, in Agent (Chat)Added or removed in Customize
User rule files~/.cursor/rules (Windows: %USERPROFILE%\.cursor\rules); they stay on the machine and do not syncYou, on that machineNot stated in Cursor’s docs (October 5, 2026)
Team RulesThe Cursor dashboard, on Team and Enterprise plans; stored on Cursor’s serversEvery team member, across all repositories; a Team Rule can be scoped with glob patternsAdmins can enforce a rule so members cannot disable it; members can switch off a rule that is not enforced
AGENTS.mdPlain Markdown in the project root and in subfoldersAnyone working in that folder or below itNo frontmatter; Cursor picks the file up automatically

Cursor’s docs state the precedence in one line: rules are applied in the order Team Rules, Project Rules, User Rules; all applicable rules are merged, and earlier sources take precedence when guidance conflicts. So a personal preference cannot override a rule your team or the repository set.

For client work the split we recommend is simple. Personal habits, such as reply style or a preferred test runner, go in User Rules as global instructions that follow you into every Cursor chat. Anything the client’s repository needs goes in Project Rules, so it travels with the code at handover. The location is the decision: a rule in your settings leaves with you, and a rule in the Cursor rules directory, .cursor/rules, stays with the client. Cursor’s docs list four types of rules, and none is called a workspace rule; in Cursor, rules local to one repository are Project Rules. The home-folder files are useful for a personal rule you want on one laptop only, since they do not sync.

Rules, AGENTS.md and Skills: which file for which job

AGENTS.md is the plain-Markdown alternative: no frontmatter, read from the project root and from subfolders, where a nested file applies to work in its own folder and below. Cursor reads CLAUDE.md the same way and applies it to every conversation, whatever its frontmatter says. The old single .cursorrules file in the project root is legacy and will be deprecated; Cursor’s help page says to copy its contents into a new rule set to Always Apply and then delete it.

Cursor Skills are a separate feature: a skill is a folder with a SKILL.md file that packages a task, and the agent decides when it is relevant or you call it by typing / in chat. On Cursor rules vs AGENTS.md, we’d use rules when a guard must attach by path, and AGENTS.md when every tool on the repository should read the same instructions. Every repo an agent edits needs a rules file for its guard rules; personal style can stay in User Rules. The full map of which instructions file each coding tool reads covers the other agents.

Cursor security best practices: a filled rule for the paths that break

A Cursor security rule guards the code where one wrong line exposes another customer’s data. In our audits, 7 of the 21 third-party apps had confirmed cross-user or cross-tenant authorization failures, where a logged-in user could read or write another customer’s data.

Those 21 are third-party apps from our June and July 2026 audits, picked for review rather than drawn at random, so the count describes that group and not AI-built apps in general. A rule cannot fix that class of bug, but it can put the right lines in front of the agent every time it edits the folders where such a bug would live.

The Cursor rules example below is ours, written for this page: it guards auth, permissions, payments and webhooks, and the two test commands are placeholders you replace with your own, as are the folder names.

---
description: Guard rules for auth, permissions, payments and webhooks
globs: src/auth/**, src/permissions/**, src/payments/**, src/webhooks/**
alwaysApply: false
---

- Every query reads the user from the session, never from the request body.
- A role or plan value sent from the browser is never written to the database.
- Webhook handlers verify the signature on the raw body before parsing it.
- Never print, log or commit a secret, an API key or a service-role token.
- No change in these paths unless `<your auth tests>` and `<your payment tests>` pass.

What each line does:

  1. The frontmatter makes it an Apply to Specific Files rule, so it loads only when a file in those four folders is in context.
  2. Reading the user from the session closes the gap where a request names someone else’s ID.
  3. Ignoring a role or plan sent from the browser stops a user from granting themselves admin or a paid tier.
  4. Verifying the signature on the raw body means a forged webhook is rejected before it can mark an order as paid.
  5. The secrets line names three places a key can leak while you debug: printed output, logs and commits.
  6. The last line ties every change to a command that passes or fails.

What makes Cursor rules examples like this one actually work is that every line can fail a test, so the check in the next section has something to catch. The rule shapes what the agent writes; Cursor’s own settings, privacy and what the agent may run are a separate subject, covered in Cursor’s security settings and what they leave open.

Awesome Cursor rules and other shared collections: read before you import

Shared collections save time. One of them, the awesome-cursorrules collection on GitHub, gathers .mdc Project Rules grouped by framework and topic, from frontend libraries to testing and security, and tells you to copy the file you choose into .cursor/rules and then adapt it. Cursor itself imports rules from a repository only when they are packaged as a plugin and installed through a marketplace, after which they appear in Customize next to your own.

The risk is text a reviewer cannot see. On March 18, 2025, the security firm Pillar Security published research it named “Rules File Backdoor”: instructions hidden in rule files with invisible Unicode characters, such as zero-width joiners and bidirectional text markers, could steer Cursor and GitHub Copilot into adding code the developer never asked for. The researchers reported that, at the time, the hidden characters were also invisible in GitHub’s pull request review, so a poisoned rule could pass a shared collection’s review. Cursor’s reply, as the researchers record it, was that the risk falls under the users’ responsibility. GitHub’s changelog of May 1, 2025 announced a warning on github.com when a file contains hidden Unicode text, noting that such characters can make code appear one way and be interpreted another way, “especially by AI”.

The lesson we take is that a rules file is code the agent obeys, so an imported one gets the review any dependency would. Before you commit one from an awesome Cursor rules list or any other Cursor rules library, open it in an editor that shows hidden Unicode characters, such as Visual Studio Code, which highlights them by default, or view the file on github.com, which displays a warning when a file’s contents include hidden Unicode text.

How to check your Cursor rules are applying

Cursor rules are proven to apply in 5 checks: the rule shows in Customize, a matching file pulls it in, a non-matching file does not, a deliberate forbidden request is refused or flagged, and CI fails when that change is pushed.

  1. 01 Open Customize, then Rules, confirm the rule is listed with its status, and open it to check that the type dropdown shows the type you meant. Evidence: a screenshot.
  2. 02 Open a file the globs match in a new Agent chat and ask the agent, without opening any files, to quote the first line of each rule in its context. Cursor's rules docs describe no in-chat marker for applied rules, so the quote is the evidence. Keep it.
  3. 03 Open a file outside the globs in a new chat and ask the same question. Pass: the agent cannot quote the rule. Evidence: the reply.
  4. 04 On a throwaway branch, ask the agent for the forbidden change on purpose, such as removing the webhook signature check. Record whether it refuses, warns or makes the change.
  5. 05 Push that branch with the forbidden change in it and confirm CI fails on it. Evidence: the link to the failed run. Close the branch without merging.

Checks 1 to 4 show that the rule loads and what the agent does with it; only check 5 shows that something other than the agent’s judgment stops the change, and it blocks a merge only when the branch requires that check to pass. In the Production Hardening Sprint, deliverable 10.8 is verified the same way: review the guidance and demonstrate CI catching a representative forbidden regression.

When check 2 or 3 gives the wrong answer, the cause is usually one of these four:

  • The file ends in .md instead of .mdc, so the rules system ignores it.
  • alwaysApply is false and there are no globs and no description, so the rule loads only on an @-mention.
  • The globs match nothing in context, for example src/payments/** when the code lives in app/billing/.
  • A Team Rule says the opposite, and Team Rules take precedence over Project Rules.

One more limit to know before blaming the rule: rules apply to Agent (Chat) only, not to Tab completion, Inline Edit or Bugbot PR reviews. The CI side is its own piece of work, set out in a CI check that blocks a forbidden pattern, and if your team also uses Cline, here are the same checks for Cline rules.

Where the sprint does this

The decision usually comes when the app is about to go to the client or start taking payments, and the repository has no rules a reviewer can read and no check behind them: you can write and enforce them yourself with the steps above, or start with a free audit, a video call where we go over your rules and the paths they should guard with you and your team. The Production Hardening Sprint provides CLAUDE.md, AGENTS.md, Cursor rules, or equivalents describing conventions and protected patterns, and adds CI checks for enforceable rules. The handover includes guidance and automated checks for future AI-assisted changes. The app’s current framework and hosting setup are the starting point .

Common questions about writing Cursor rules

How can I add rules to the cursor?

Type /create-rule in the Agent chat and describe the rule you want, and the agent writes the .mdc file with its frontmatter and saves it to .cursor/rules. You can also open Customize in the sidebar and use Add Rule under Rules, or run “New Cursor Rule” from the command palette, then pick the type from the dropdown.

Where can I find cursor rules?

You can find Cursor rules in shared collections such as the awesome-cursorrules repository on GitHub, which groups .mdc files by framework and topic, and in the examples on Cursor’s own rules page. Read every file before you commit it, in an editor that shows hidden Unicode characters, since invisible characters can carry instructions a reviewer never sees.

What are the best practices for using Cursor?

Beyond rules, plan large changes before the agent edits anything, point it at the exact files, review every diff, keep commits small, and run the tests before you merge. Cursor’s Plan Mode, which Shift+Tab in the chat input rotates to, produces a plan you can edit before any code is written, and its checkpoints undo Agent changes, though Cursor’s docs say to use Git for permanent version control. The diff review, small commits and tests before merging are our habits rather than Cursor’s wording.

What are some good skills for Cursor?

Good skills for Cursor package a task your team repeats, such as a release checklist or a migration routine, in a SKILL.md file the agent can pick up when the task matches or you call with /. Those two examples are ours. Cursor also ships built-in skills, including /create-rule, which creates rules with the appropriate scope and instructions, and /review-security, which reviews code for security vulnerabilities.