Cursor Rules: A Practical Guide
Cursor rules are version-controlled instructions that shape how the Agent edits your code. Here is how to scope them so they help instead of getting in the way.
Cursor rules are .mdc files that live in your repo and steer the Agent's behavior. Unlike a setting buried in the app, they are version-controlled, reviewable, and shared with your whole team. The official Rules docs define the full frontmatter spec.
The four scopes
The thing most people get wrong is scope. A rule that fires on every file when it should fire on three files just burns context and confuses the model. Each rule has frontmatter that controls when it applies.
---
description: Conventions for HTTP route handlers
globs: src/routes/**/*.ts
alwaysApply: false
---
- Every handler validates input with zod before use.
- Return the ApiResponse<T> envelope, never a raw object.
- Errors throw AppError; do not return error shapes by hand.alwaysApply: trueapplies the rule on every request. Reserve it for a tiny set of global laws.globsattach the rule only when matching files are in play. This is the workhorse.descriptionlets the Agent pull the rule in on demand when the task seems relevant.- A manual mode where the rule only loads if you reference it explicitly.
Steal good rules
You do not have to write rules from scratch. The community has curated thousands of them by framework and language. Grab one close to your stack and trim it down.
PatrickJS/awesome-cursorrulesThe most comprehensive collection of rule files, categorized by framework and language.github.com32kCursor DirectoryBrowse the best rules by framework, with an auto-generator that scans your repo.cursor.directory
28:050 Comments
Loading discussion...