Cursor

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.

Setuproll Team7 min read2026-06-15

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.

.cursor/rules/api.mdc
---
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: true applies the rule on every request. Reserve it for a tiny set of global laws.
  • globs attach the rule only when matching files are in play. This is the workhorse.
  • description lets 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.
One giant always-on rule is an anti-pattern
If everything is always applied, nothing is prioritized and your context fills with rules that do not match the current file. Split by glob instead.
Cursor - .cursor/rules
Explorer
.cursor/
rules/
global.mdc
api.mdc
react.mdc
tests.mdc
.cursor/rules/api.mdc
1---
2description: Route handler conventions
3globs: src/routes/**/*.ts
4alwaysApply: false
5---
6
7- Validate input with zod.
8- Return ApiResponse<T>.
9- Throw AppError on failure.
Rules organized by scope, not dumped into one file.

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
zsh - adding a rule
$mkdir -p .cursor/rules
$curl -o .cursor/rules/nextjs.mdc <url-from-directory>
# then trim it to only the rules you actually want
✓ rule added, scoped to app/**/*.tsx
$
Cursor AI Tutorial - My Personal Tips & Tricks28:05
Cursor AI Tutorial - My Personal Tips & Tricks· Volo Builds

0 Comments

Sign in to post

Loading discussion...