In this categoryCursor · 26
- How to Install Cursor and Import VS Code Settings (6 Minutes)Start
- Cursor Setup Guide: From Install to Your First AI Edit
- How to Set Up Project Rules in the .cursor/rules Folder
- How to Set Up Codebase Indexing in Cursor
- How to Enforce Project Conventions with Cursor Rules
- How to Write a Team Rule That Applies Only to Certain Files
- How to Migrate a Legacy .cursorrules File to the New Rules Folder
- How to Use Cursor Rules to Guide AI Edits
- How to Set Project Rules in Cursor
- How to Add a .cursorrules File to Steer Cursor
- How to Customize Cursor Keyboard Shortcuts
- How to Edit Multiple Files at Once with Cursor Composer
- How to Use Cursor Tab Completion Effectively
- How to Edit Code Inline with Cmd+K in Cursor
- How to Add Context to Cursor Chat with @ Mentions
- How to Choose and Switch AI Models in Cursor
- How to Add Library Docs as Context with @Docs in Cursor
- How to Generate and Maintain Tests with Cursor Composer
- How to Undo a Composer Change with Checkpoints in Cursor
- How to Use Cursor Agent Mode to Build a Feature End to End
- How to Connect an MCP Server to Cursor
- How to Refactor Across Your Whole Codebase in Cursor
- How to Query Your Database from Cursor with a Postgres MCP Server
- How to Let Cursor Run Commands Automatically (and Keep It Safe)
- How to Build a Full Feature Across Frontend and Backend with Composer
- How to Debug an MCP Server That Will Not Connect in Cursor
How to Write a Team Rule That Applies Only to Certain Files
Use glob patterns in a .mdc rule so a convention attaches to just the files it governs, like tests or API routes.
Not every rule should apply everywhere. A testing convention has no business loading when you edit a CSS file. Glob patterns let a rule attach only when a matching file is in context, which keeps the model focused and your context window lean. This guide writes a scoped rule for React components.
What you need
- A project with a .cursor/rules folder
- A convention that only applies to a subset of files
- Knowledge of where those files live in the tree
Step 1: Decide the pattern
Glob syntax matches paths. A double star spans directories, a single star matches within one segment. Sketch the pattern that captures your files and nothing else before writing the rule.
| Glob | Matches |
|---|---|
| src/components/**/*.tsx | Every component file under components |
| **/*.test.ts | Test files anywhere in the repo |
| app/api/**/route.ts | Route handlers in the app router |
| **/*.{css,scss} | All stylesheets |
Step 2: Write the rule with the glob
Create the file and set the glob in the frontmatter. Leave alwaysApply false so the rule only loads when a matching file is in context, which is the whole point of scoping.
---
description: React component conventions
globs: ["src/components/**/*.tsx"]
alwaysApply: false
---
- One component per file; the file name matches the component.
- Props are a named `type`, not an inline object.
- No default exports.
- Co-locate styles in a sibling `.module.css` file.Step 3: Verify it attaches and detaches
Open a component file and start a chat: the rule should appear in the attached context. Then open a file outside the glob, like a server utility, and confirm the rule no longer loads.
Step 4: Commit it for the team
Because rules live in the repo, committing the file shares the convention with everyone. New teammates get the same guidance with no setup the moment they clone.
Result: your component conventions are enforced automatically while editing components, and stay out of the way everywhere else, shared across the whole team through version control.
Watch related tutorials
19:27
26:00
24:18
1:42:18
28:14
41:09New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.