A Cursor rule to create new Cursor rules

This rule explains how to create new .mdc project rule files for the Cursor agent.
Back to rules
Type
Integration
Stats
1,006 views
144 copies
47 downloads
Author
Elie Steinbock
Elie Steinbock
create-rules.mdc
---
description: This rule explains how to create new .mdc project rule files for the Cursor agent.
globs: 
alwaysApply: true
---

# Cursor Rules Location

How to add new cursor rules to the project

1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
    ```
    .cursor/rules/
    ├── your-rule-name.mdc
    ├── another-rule.mdc
    └── ...
    ```

2. Follow the naming convention:
    - Use kebab-case for filenames
    - Always use .mdc extension
    - Make names descriptive of the rule's purpose

3. Directory structure:
    ```
    PROJECT_ROOT/
    ├── .cursor/
    │   └── rules/
    │       ├── your-rule-name.mdc
    │       └── ...
    └── ...
    ```

4. Never place rule files:
    - In the project root
    - In subdirectories outside .cursor/rules
    - In any other location

5. Cursor rules have the following structure:

```
---
description: Short description of the rule's purpose
globs: optional/path/pattern/**/* 
alwaysApply: false
---
# Rule Title

Main content explaining the rule with markdown formatting.

1. Step-by-step instructions
2. Code examples
3. Guidelines

Example:
```typescript
// Good example
function goodExample() {
  // Implementation following guidelines
}

// Bad example
function badExample() {
  // Implementation not following guidelines
}
```

Creating rules in Cursor allows you to define consistent guidance for the AI assistant in your project. This rule specifically explains how to properly add new .mdc rule files to your project structure, ensuring they're placed in the correct location and follow the appropriate formatting conventions.

What this rule does

The "Create Rules" rule serves as a guide for setting up new rule files in your Cursor projects. It outlines the proper directory structure, naming conventions, and file format for Cursor rules. Following these guidelines ensures that your custom rules are properly recognized and applied by the Cursor AI assistant.

Rule file organization

When adding rules to your project, proper organization is critical:

Location requirements

All rule files must be placed in the .cursor/rules/ directory at the root of your project. This specific location ensures Cursor can find and apply your rules automatically. The rule defines a clear structure:

PROJECT_ROOT/
├── .cursor/
   └── rules/
       ├── your-rule-name.mdc
       └── ...
└── ...

Rules should never be placed in the project root, subdirectories outside .cursor/rules, or any other location.

Naming conventions

For rule files to be properly recognized, they must follow these naming guidelines:

  • Use kebab-case for filenames (e.g., code-style-guide.mdc, git-commit-format.mdc)
  • Always include the .mdc extension
  • Choose descriptive names that clearly indicate the rule's purpose

Rule file structure

Each rule file follows a specific format with three main components:

  1. YAML frontmatter - Contains metadata about the rule:

    • description: A concise explanation of the rule's purpose
    • globs: Optional path patterns to automatically apply the rule to matching files
    • alwaysApply: Boolean flag determining if the rule should always be active
  2. Rule title - A clear heading identifying the rule

  3. Main content - The detailed instructions, formatted with markdown, which may include:

    • Step-by-step guidelines
    • Code examples (good and bad)
    • Specific implementation instructions

A simplified example structure:

---
description: Short description of the rule's purpose
globs: optional/path/pattern/**/* 
alwaysApply: false
---
# Rule Title

Main rule content with instructions...

Using create rules in Cursor

The "Create Rules" rule itself is defined in a file named create-rules.mdc and serves as a meta-guide for creating other rules. Since this rule doesn't appear to have a glob pattern, it's likely intended to be manually invoked when you need guidance on creating new rules.

To use this rule:

  1. Open your Cursor editor
  2. When you need to create a new rule, type @create-rules in the Cmd-K prompt or chat interface
  3. The AI will respond with guidance on how to properly structure and place your new rule file

This rule is particularly useful when setting up project-specific guidelines or when you're new to creating Cursor rules and need a reference for the proper structure and location.

Tips for effective rule creation

When creating new rules for your project:

  • Consider organizing related rules with similar prefixes (e.g., code-style-javascript.mdc, code-style-python.mdc)
  • Make rule titles and descriptions clear and specific
  • For rules that should apply to specific file types, use appropriate glob patterns
  • Test your rules after creation to ensure they're being applied as expected
  • Consider including both positive and negative examples in your rules to clearly illustrate preferred practices

By following the guidelines in the Create Rules rule, you'll ensure consistent rule implementation across your project, making it easier for team members to understand and follow your project's standards.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later