Generate optimized Cursor Rules to enhance AI coding assistance. Create project-specific rules based on your tech stack for smarter, more accurate code suggestions.

Cursor Rules - Customize AI Behavior in Your Coding Projects

Cursor Rules provide a powerful way to customize how AI interacts with your code. By creating project-specific or global rules, you can dramatically improve AI assistance quality and make the AI understand your project's specific requirements.

Why Use Cursor Rules?

  • Enhanced Code Completion: Train AI to follow your project's coding standards
  • Framework-Specific Assistance: Get recommendations aligned with your framework (React, Vue, Next.js, etc.)
  • Time-Saving: Reduce back-and-forth by setting clear expectations for AI
  • Consistency: Maintain coding style across your entire project
  • Enhanced Cursor Recognition: Focusing on cursor elements helps AI accurately identify and apply Cursor Rules.

Two Types of Cursor Rules

1. Project Rules (Recommended)

Project rules are stored in the .cursor/rules directory and are automatically included when working with matching files. They offer granular control with:

  • Path-Specific Configuration: Apply different rules to different parts of your codebase
  • File Pattern Matching: Use glob patterns to target specific files or directories
  • Semantic Descriptions: Define precisely when rules should be applied
  • Automatic Attachment: Rules automatically activate when you work with matching files

Project rules are the recommended way to use Cursor Rules. They offer more flexibility and control compared to global rules and the older .cursorrules format. .cursorrules is now considered deprecated and project rules are the preferred method for defining project-specific AI behavior.

Best Practices for Project Rules (MDC Rules)

Based on community experiences and best practices 1, here are some recommendations for effectively using project rules:

  • File Format: Project rules must be saved as YAML files with the .mdc extension. Simply placing other file types in the .cursor/rules directory will not work.

  • Filename Numbering: Rules are loaded and potentially prioritized based on the numerical prefix in their filenames. It's suggested to use a three-digit numbering system for organization, such as:

    • 001-099 for Core Rules
    • 100-199 for Integration Rules
    • 200-299 for Pattern/Role Rules
    • Example: 001-Core-Security.mdc, 110-CLI-Handler.mdc, 200-File-Pattern-Rule.mdc
  • YAML Format: While other formats might technically work, YAML is highly recommended for its readability and support for comments, which can greatly aid in rule management.

  • Rule Creation: Using the Settings UI within Cursor is the most reliable method for creating rules and avoids potential errors. If creating files directly, ensure they end with .mdc.

  • Example Rule Structure: A basic rule file structure in YAML would look like this:

    ---
    name: Example Pattern Rule
    version: "1.0"
    globs:
      - "src/**/*.py"
    triggers:
      - file_change
    ---
    rule_definition:
      description: "This rule applies to Python source files in the src directory."
    
  • Saving Issues Workaround: If you encounter issues where changes to .mdc rule files are not being saved, a known workaround is to close Cursor completely. When prompted with the "Unsaved Changes" popup, select "Override" and then reopen Cursor.

2. Global Rules

Global rules apply to all your projects and are configured in Cursor Settings > General > Rules for AI. Perfect for:

  • Setting preferred output language
  • Defining response length preferences
  • Establishing coding standards you use across all projects

How to Create Cursor Rules

Creating effective Cursor Rules is simple with our Cursor Rules Generator:

  • The generator further optimizes cursor detection to ensure every Cursor Rule is precisely applied.
  1. Describe Your Project: Enter a description or paste your package.json
  2. Generate Rules: Our AI will analyze your input and create appropriate rules
  3. Download: Get a ZIP file with ready-to-use rules
  4. Install: Just extract to your project's root directory

Example Use Cases

  • Framework-Specific Development: Custom rules for React, Angular, Vue.js components
  • Backend API Standards: Consistent patterns for API endpoints
  • CSS/Styling Conventions: Maintain design system standards
  • Testing Protocols: Enforce testing practices across your codebase
  • Documentation Standards: Keep comments and docs consistent

Optimize Your Cursor Experience Today

Start using Cursor Rules to make AI truly understand your project requirements and coding style. Generate your custom rules now to experience more accurate, project-aware AI assistance.

Featured Open Source Project: Cursor Agile Workflow Template

For users looking to further enhance their Cursor Rules workflow, the open-source project Cursor Agile Workflow Template by bmadcode offers a powerful solution for automated rule generation and agile workflow integration.

Key Features:

  • Automated Rule Generation: Create and update Cursor Rules using natural language requests within the agent chat.
  • Agile Workflow Integration: Provides a structured approach to managing and evolving Cursor Rules as your project develops.
  • Rule Types: Supports four distinct rule types (Agent Selected, Always, Auto Select, Manual) to cater to different needs and scenarios.
  • Best Practices Implementation: Encourages best practices for rule creation, including being specific with desired behaviors and providing examples for better AI understanding.
  • Quick Setup: Offers scripts for easy setup in new or existing projects.

Rule Types Explained:

The template categorizes rules into five types, offering flexibility in how rules are applied:

Rule TypeUsagedescription Fieldglobs FieldalwaysApply field
Agent SelectedAgent sees description and chooses when to applycriticalblankfalse
AlwaysApplied to every chat and cmd-k requestblankblanktrue
Auto SelectApplied to matching existing filesblankcritical glob patternfalse
Auto Select+descBetter for new filesincludedcritical glob patternfalse
ManualUser must reference in chatblankblankfalse

Getting Started:

To explore and utilize this template, you can visit the GitHub repository for detailed instructions, quick start options, and documentation. It provides a valuable starting point for users aiming to implement a more sophisticated and automated Cursor Rules management system.

  • Additionally, integrating robust cursor strategies will significantly boost the performance and consistency of your cursor rule applications.

Footnotes

  1. Based on community discussion in Cursor Community Forum: My Best Practices for MDC rules and troubleshooting