Cursor 101

Cursor Rules

Learn how to use Cursor Rules to streamline your coding process and boost productivity.

View Official Documentation

Understanding Cursor Rules

Cursor Rules help you customize AI behavior to match your coding style and project requirements. There are two types of rules available.

Global Rules

Set in Cursor Settings under "General" > "Rules for AI". These rules apply across all your projects, perfect for personal coding preferences and consistent AI behavior.

Project Rules

Project-specific rules stored as .mdc files in the .cursor/rules directory. These rules help the AI understand your codebase and follow your project's conventions. Add them via Cursor Settings > General > Project Rules. They are synced with your codebase and can be automatically included when needed.

Cursor Project Rules interface showing the rules management panel

Rule Examples

Global Rule

# In Cursor Settings > Rules for AI

- Use TypeScript for all new code
- Follow clean code principles
- Prefer async/await over callbacks
- Write comprehensive error handling
.mdc

Project Rule (example.mdc)

# File patterns: *.tsx, *.ts

## React Guidelines
- Use functional components
- Implement proper prop types
- Follow React best practices

## Style
- Use Tailwind CSS
- Follow team's style guide

@file ../tsconfig.json
@file ../tailwind.config.js
.mdc

Key Benefits of Implementing Cursor Rules

Increased Productivity

Cursor Rules automate repetitive tasks, allowing you to focus on writing quality code.

Consistent Code Style

Enforce coding standards across your team, ensuring a uniform and readable codebase.

Reduced Errors

Catch common mistakes early in the development process, saving time on debugging.

Faster Onboarding

New team members can quickly adapt to your project's coding style and best practices.

How It Works

Semantic Descriptions

Each rule can include a description of when it should be applied, making it easy to understand and maintain.

File Pattern Matching

Use glob patterns to specify which files or folders the rule applies to, ensuring precise control over rule application.

Automatic Attachment

Rules can be automatically included when matching files are referenced, streamlining your workflow.

Reference Files

Use @file in your project rules to include them as context when the rule is applied, enhancing AI understanding.

How to Create Cursor Rules

  1. Configure Global Rules

    Go to Cursor Settings > General > Rules for AI to set up rules that apply across all your projects.

  2. Configure Project Rules

    Go to Cursor Settings > General > Project Rules to manage project-specific rules.

    1. Create New Rule

      Click 'Add Rule' to create a new .mdc file. Edit Description (helps the agent choose rules) and Globs (e.g. *.tsx for automatic rule inclusion).

    2. Write Rule Content

      Write your rules in the .mdc file. Cursor will automatically sync and apply them based on your Description and Globs settings.

Cursor Project Rules interface showing how to add and configure rules

Project Rules interface in Cursor Settings

  • • Description: The agent will choose rules to use based on description
  • • Globs: When you specify file patterns here (e.g. *.tsx), this rule will automatically be included in AI responses for files matching those patterns

How to Create Effective Cursor Rules

What Makes a Good Rule

  • Easy to understand - avoid complex jargon
  • Specific to your project or coding style
  • Matches your team's agreed-upon practices
  • Works for different parts of your code
  • Simple to update as your project grows

Tips for Writing Better Rules

  • Begin with basic rules, then add more as needed
  • Write as if you're explaining to a colleague
  • Include examples from your own code
  • Think about how the rule applies to your project
  • Check and update your rules regularly

Making Your Rules Work Better

  • Use words and terms you use in your daily coding
  • Briefly describe your project or feature
  • Show short code examples when it helps
  • Mention any specific requirements or limitations
  • Ask for explanations when you need them

Inspiring Cursor Rules Examples

Explore these Cursor Rules examples to inspire your own custom AI rules. Remember, the most effective Cursor Rules are tailored to your specific project needs and coding requirements.

typescript
javascript

TypeScript Expert

typescript
javascript

You are a TypeScript expert with deep knowledge of the language's features and best practices. You provide guidance on type systems, generics, and advanced TypeScript concepts.

For more Cursor Rules examples and inspiration, visit theCursor Rules Directory

Frequently Asked Questions About Cursor Rules

For more detailed information on Cursor Rules, refer to theofficial Cursor Rules for AI documentation

Ready to Supercharge Your Coding?

Discover how Cursor can revolutionize your development workflow. Watch our video tutorials to see all of Cursor's powerful features in action.

Don't miss out on the power of Cursor Rules. Start optimizing your workflow today!

Explore Video Tutorials