When it comes to leveraging AI-powered coding assistants like Cursor, one advanced feature often overlooked by API developers and backend engineers is Cursor Rules. These persistent, project-specific instructions empower you to enforce code standards, automate workflows, and ensure your AI-generated code aligns with your team’s best practices—every single time.
In this comprehensive guide, you’ll learn what Cursor Rules are, how they work, and how to integrate them seamlessly into your development process. Plus, discover how pairing Cursor with Apidog can ensure your APIs perform as expected from code generation to deployment.
What Are Cursor Rules?
Cursor Rules are project- or user-defined instructions that guide how Cursor’s AI generates and edits code. Unlike single-use prompts, these rules form persistent context—automatically injected into the AI’s model for every applicable operation.
Think of Cursor Rules as the AI equivalent of a .eslintrc or .editorconfig file: they provide consistent standards for everything from code style to workflow automation.
Why Cursor Rules Matter for Professional Teams
Without persistent rules, AI assistants rely solely on each prompt and their internal knowledge, which often leads to:
- Inconsistent code styles across files and sessions
- Repetitive manual corrections
- Frequent reminders of project-specific conventions
By defining Cursor Rules, you encode your team’s preferences and standards directly into the development workflow, eliminating ambiguity and reducing manual rework.
Types of Cursor Rules
Cursor offers several rule types, each tailored to different scopes and triggers:
| Rule Type | Description |
|---|---|
| Always | Included in every AI context for all operations |
| Auto Attached | Automatically applied when editing files matching specific patterns (globs) |
| Agent Requested | Available to the AI, attached only when deemed relevant |
| Manual | Invoked explicitly via commands or annotations |
This flexibility allows you to target rules by file type, directory, or user action—streamlining your coding process.
Where to Store Cursor Rules
Cursor supports multiple storage locations for rules:
- Project Rules: Located in
.cursor/rules/within your project tree. These rules are version-controlled and easily shared with your team. - User Rules: Global settings managed via Cursor > Settings. These apply across all your projects.
- Legacy .cursorrules: Supported for backward compatibility, but migrating to
.cursor/rules/is recommended for advanced features and future support.
For monorepos or modular codebases, rules can be nested in subdirectories to target specific areas.
How Cursor Rules Work Behind the Scenes
Because large language models (LLMs) do not retain state between requests, Cursor injects your rule contents at the start of every AI completion, chat, or inline edit. This ensures your preferences always inform the generated code.
Examples:
- Enforce coding style (e.g., always use async/await)
- Define naming conventions or directory structures
- Automate routine workflows and boilerplate
Cursor Rules apply across both Chat and Inline Edit modes, making them versatile for all usage patterns.
From .cursorrules to Project Rules: The Evolution
Cursor’s rule system has matured significantly:
- Global Rules: Set in Cursor > Settings > Rules for preferences that span all projects (e.g., “Always use TypeScript”).
- .cursorrules: Simple, project-root files (now deprecated—will be phased out in 2025).
- Project Rules: The modern, flexible standard—stored as
.mdcfiles under.cursor/rules/. These support file globs, precise targeting, and richer context.

If you’re still using .cursorrules, now is the time to upgrade to the new .mdc format for better flexibility and long-term support.

Step-by-Step: How to Set Up Cursor Rules
Ready to implement Cursor Rules in your workflow? Here’s how:
-
Open the Rules Panel
In Cursor, navigate to Cursor > Settings > Rules > Project Rules > Add New Rule.
Or useCtrl+Shift+P(orCmd+Shift+Pon Mac) and type “File: New Cursor Rule”.
-
Name Your Rule
Choose a descriptive name, such asapi-style-guide.mdc. The file will appear under.cursor/rules/in your project.
-
Define Metadata
At the top of the.mdcfile, fill in:- Description: Brief summary (e.g., “API endpoint naming conventions”)
- Globs: File patterns (e.g.,
src/api/**/*.ts) that activate this rule

-
Write Your Rule
Specify the instruction, guideline, or automation in plain text or markdown.
Your .cursor/rules/ directory may look like this:

Once saved, Cursor will use this rule whenever matching files are generated or edited.
Practical Examples: Cursor Rules in Real Projects
1. Auto-Run Tests on File Changes
Scenario: Automatically run RSpec tests in Docker when editing spec files.
Rule Example:
- File:
rspec-execution.mdc - Description: Auto-run RSpec tests
- Globs:
**/*_spec.rb - Rule:
## Run RSpec Automatically When a spec file changes, execute: --- docker compose exec app bundle exec rspec {{file_path}} --- If RSpec fails and you know the line number, run: --- docker compose exec app bundle exec rspec {{file_path}}:{{line_number}} ---
2. Document Coding Standards for Frontend Teams
Scenario: Ensure AI-generated code follows your project’s directory structure and component conventions.
Rule Example:
- File:
frontend-coding-rule.mdc - Description: Frontend best practices
- Globs:
packages/**/*.* - Rule:
## Frontend Coding Guidelines - Group code by feature (`features/foo/NewFeature/`) - Separate UI (`*.ui.tsx`) and logic (`*.container.tsx`) - Use `zod` for validation with dedicated spec files - Name components descriptively - Follow Atomic Design principles
3. Automate Pull Request Drafting
Scenario: Have the AI prepare draft PRs and prompt for missing details.
Rule Example:
- File:
create-pullrequest.mdc - Description: Auto-draft pull requests
- Globs: (leave blank for manual trigger)
- Rule:
## Pull Request Creation 1. Check for an Issue link; if missing, request it. 2. Assume `main` as the default merge branch. 3. Use `git diff origin/main...HEAD | cat` to review changes. 4. Create a draft PR with: --- git push origin HEAD && \ echo -e "Draft PR for {{changes}}\n\nRelated: {{issue_link}}" | \ gh pr create --draft --title "Update {{feature}}" --body-file - && \ gh pr view --web ---
How Apidog Complements Cursor for Reliable API Development
While Cursor Rules help enforce code consistency and workflow automation, Apidog strengthens your API lifecycle by:
- Automating API testing and contract validation
- Generating test cases for endpoints (including those generated by Cursor)
- Integrating with CI/CD pipelines to catch regressions early
By pairing Cursor’s rule-based AI code generation with Apidog’s robust API quality assurance tools, you ensure your API endpoints are both consistently written and thoroughly validated—streamlining your team’s development and QA process.

Best Practices for Effective Cursor Rules
Follow these guidelines to maximize the impact of your rules:
-
Keep Rules Focused
- Make instructions actionable and scoped to specific file types or domains.
- Avoid ambiguous or overly broad language.
-
Use Version Control
- Add
.cursor/rules/to your Git repository to share standards across your team.
- Add
-
Combine Project and User Rules
- Store global preferences in User Rules.
- Use Project Rules for codebase- or module-specific logic.
-
Reference Example Files
- Enhance rule clarity by linking to real code samples within your rules.
Troubleshooting Cursor Rules
If a rule isn’t being applied:
- Double-check that the description and globs fields are not empty.
- Restart Cursor or refresh your workspace.
- Invoke the rule manually by name if needed.
Cursor may not always display which rule was used, but you’ll notice the effect in the AI’s generated output.
Collaborating with Teams Using Cursor Rules
For distributed teams, storing .cursor/rules/ in your version control system ensures everyone benefits from consistent AI-generated code and shared workflow automations. This is particularly valuable in rapidly evolving or large-scale codebases.
Advanced Techniques: Nested and Generated Rules
- Nested Rules: Place
.cursor/rules/in subdirectories to apply context-specific standards—ideal for monorepos and multi-service architectures. - Rule Generation via Chat: Use
Generate Cursor Rulescommands within Cursor chats to create new rules based on your team’s conversations and decisions.
Frequently Asked Questions
Q1: What are Cursor Rules?
Persistent instructions that influence how Cursor’s AI generates or edits code, ensuring adherence to your project or team standards.
Q2: Where should I store project rules?
In .cursor/rules/ as .mdc files, each with defined scope and instructions.
Q3: How do I trigger an auto rule?
By setting file pattern globs; Cursor attaches relevant rules automatically.
Q4: Can rules reference files?
Yes—include paths to real example files to provide richer AI context.
Q5: Are rules applied to all AI features?
Cursor Rules affect Chat and Inline Edit, but not all UI features (e.g., Cursor Tab).
Conclusion
Cursor Rules give development teams a powerful way to standardize AI-generated code, automate routine tasks, and reduce manual corrections—leading to higher consistency and productivity. By defining clear, targeted rules, you ensure every AI suggestion follows your real-world standards.
To further boost code reliability, integrate Apidog for API testing and validation—so both your code and your APIs work as intended, every time.



