How to create Cursor rules?
Ok, now that we know what rules are for and what effect they have, let's create some.
We'll start with user rules, as they are the easiest to set up and are perfect for defining your personal, global preferences.
Creating User Rules
Here’s a step-by-step guide to creating your first user rule:
- Press
Ctrl + Shift + P(orCmd + Shift + Pon Mac) to open the Command Palette. - Search for
Cursor Settingsand select it. - In the settings, look for the
Rules and Memoriessection. - Under User Rules, click the Add Rule button.
- Type your instructions for the AI in the text box that appears.
- Press
Done.
That's it! Your new user rule is now saved and will be applied automatically in every project you work on.
Showcase video:
Creating Project Rules
Project rules are a bit more involved, but they're essential for ensuring consistent AI behavior across your entire team.
Here's how to create them:
- Press
Ctrl + Shift + P(orCmd + Shift + Pon Mac) to open the Command Palette. - Search for
Cursor Settingsand select it. - In the settings, navigate to the
Rules and Memoriessection. - Under Project Rules, click the Add Rule button.
- A pop-up will appear at the top of your screen asking for the name of the rule. Type in a descriptive name (e.g.,
react-best-practices). - Fill out the frontmatter:
- description: Briefly describe what the rule does. This helps you and your teammates understand its purpose at a glance.
- globs: Define which file types or paths the rule should apply to. You can use wildcards (e.g.,
'**/*.ts, **/*.tsx, **/*.js, **/*.jsx'). - alwaysApply: Set this to
trueif you want the rule to be applied to every AI prompt in this project. Set it tofalseif you want to apply the rule manually by using@in the AI chat (e.g.,@react-best-practiceswill apply your new rule to that specific prompt).
- Type your rule: Below the
--line, write the detailed instructions and context for the AI. This is where you specify things like coding standards, library usage, and architectural patterns. - Save and restart: Save the file and restart your Cursor editor to ensure the new rule is loaded.
This action will automatically create a file at .cursor/rules/{name-of-your-rule}.mdc and open it for you. You will see the following template:
---
description:
globs:
alwaysApply: true
---
There you go! Your project rule is now in place and will provide the AI with the necessary context for your project.
Showcase video:
What's Next?
You now know how to set up both personal and project-wide rules to give the AI context about what you're building. This is a massive step, but to truly get the most out of Cursor, you need to master how you communicate with the AI.
On the next page, we'll dive into prompt engineering, teaching you how to craft prompts that get the precise results you need, every time.
Member discussion