StepGleam logoStepGleam
Coding guide

Write Cursor project rules that actually load when you need them

Put rules in .cursor/rules as .mdc files, set alwaysApply, globs and the description on purpose, and test that the agent picks each rule up.

~25 minIntermediate 74/100 5 steps Updated Oct 26, 2026
CursorGit
Write Cursor project rules that actually load when you need them — illustration for this Coding guide

Tools used

  • CursorLoads project rules into the agent context
  • GitShares rules with the team
Step navigator0/5 done
0 of 5 steps done
What you'll get

A small set of committed .mdc rules, each with a trigger you chose and checked.

Who this is for

Cursor users whose rules seem to be ignored.

Read this first

Before you start

A widely read r/cursor deep dive found that rules in .cursor/rules don't all switch on just by being there: whether a rule is added to the context and whether it is used depend on alwaysApply, globs and the description. Cursor's docs describe the same rule types.

Step-by-step instructions

Step 1 of 5 · Coding

Put project rules in .cursor/rules as .mdc files

Cursor's docs: project rules "live in .cursor/rules as .mdc files and are version-controlled." The deep dive's reason to commit them: "Teams can collaborate using shared rules."

Write Cursor project rules that actually load when you need them — guide thumbnail
Step 2 of 5 · Coding

Set the trigger deliberately

Each rule's front matter has description, globs and alwaysApply. Per the deep dive, alwaysApply and globs decide whether a rule is injected into the context, and the description decides whether the agent fetches and uses it. Asked whether rules in the folder activate automatically, the author's answer is: "No."

Copy-ready promptCursor
---
description: Backend API conventions. Use when editing files in src/api.
globs: src/api/**
alwaysApply: false
---
- Validate inputs at service boundaries
- Return { code, message } on errors
Why this works

A vague description means the agent may never fetch the rule.

Step 3 of 5 · Coding

Edit .mdc files in a plain editor if the UI misbehaves

The deep dive found Cursor's built-in editor for .mdc files buggy and recommends "Editing these files with external tools like VSCode."

Step 4 of 5 · Coding

Test that a rule loads

The author's test: put a line in the rule like "When this rule loads, input: 'Rule loaded: global.mdc.'" and see whether the agent prints it in a new chat.

Step 5 of 5 · Coding

Use AGENTS.md if you want something simpler

Cursor also reads AGENTS.md, which its docs call a "Simple alternative to .cursor/rules."

End of guide · Reviewed Oct 26, 2026

Pro tips2
  • Remove the test line once you have confirmed the rule loads.
  • Keep one topic per rule file.
Common mistakes2
  • Assuming every file in .cursor/rules applies to every chat.
  • A description that does not say when the rule is relevant.
FAQ2
User rules vs project rules?
User rules follow you across projects; project rules belong to one repo and are committed.
Do rules apply the same in every mode?
The deep dive found they do not apply equally across ask, edit and agent modes.