2 min read

How to create Cursor rules?

How to create Cursor rules?
Photo by Volodymyr Dobrovolskyy / Unsplash

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:

  1. Press Ctrl + Shift + P (or Cmd + Shift + P on Mac) to open the Command Palette.
  2. Search for Cursor Settings and select it.
  3. In the settings, look for the Rules and Memories section.
  4. Under User Rules, click the Add Rule button.
  5. Type your instructions for the AI in the text box that appears.
  6. 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:

0:00
/0:27

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:

  1. Press Ctrl + Shift + P (or Cmd + Shift + P on Mac) to open the Command Palette.
  2. Search for Cursor Settings and select it.
  3. In the settings, navigate to the Rules and Memories section.
  4. Under Project Rules, click the Add Rule button.
  5. 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).
  6. 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 true if you want the rule to be applied to every AI prompt in this project. Set it to false if you want to apply the rule manually by using @ in the AI chat (e.g., @react-best-practices will apply your new rule to that specific prompt).
  7. 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.
  8. 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:

0:00
/0:43

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.