Cursor Rules

Set up Cursor rules with the right files and attachment modes, plus three short TypeScript examples for style, tests and security.

Published

Cursor Rules

Stop spending every Cursor session correcting the same imports, missing tests and improvised authentication code. Give your repository a small set of standing instructions: shared project conventions, a clear trigger for each rule, and examples that match the code you actually ship. Start with the three short TypeScript rules below, then change them only when a recurring mistake earns its place.

The payoff is less review cleanup. As an illustrative budget, four developers making three five-minute corrections each week spend 60 minutes repeating conventions. That is not a promised saving. Count which corrections disappear after setup, and subtract the time you spend maintaining the rules. Your subscription bill is a separate question, covered in Cursor pricing.

Where Cursor Rules Go

Put shared coding decisions beside the code. Keep personal reply preferences personal.

KindLocationUse it for
Project Rules.cursor/rules/*.mdcThis repository's conventions
User RulesCustomize → RulesYour preferences across projects
Team RulesCursor dashboard, Team or Enterprise planOrganization guidance
AGENTS.mdProject root or subdirectoriesA plain Markdown brief

Nested AGENTS.md instructions apply to their directory and its children, combining with parent guidance; more specific instructions take precedence. For Team, Project and User Rules, the documented conflict order is Team → Project → User. Cursor's rules reference

My default for a small team is project rules. An instruction such as “use our existing form components” belongs to the repository. “Keep your final reply short” belongs to you. Separating those decisions prevents a personal preference from becoming accidental team policy.

Four architectural rooms show project rules in .cursor/rules/*.mdc, personal rules in Customize, organization rules in the dashboard and a simple brief in AGENTS.md.
Choose the home by who owns the instruction: repository, person or organization. AGENTS.md provides the plain Markdown option.

Choose When Each Rule Attaches

The frontmatter, the small settings block above a rule's text, controls attachment.

Your intentCurrent UI labelFrontmatter
AlwaysAlways ApplyalwaysApply: true; other fields ignored
Auto-attached by file patternApply to Specific FilesalwaysApply: false plus globs; matching file in context
Agent-requestedApply IntelligentlyalwaysApply: false plus description; omit globs
ManualApply ManuallyalwaysApply: false; omit both other fields; use @rule-name

“Agent-requested” means the agent selects the rule from its description. A glob is a file path pattern. Attachment behavior and syntax

Think of attachment as delivering a work order to the right bench. A beautifully written instruction is useless on a task that never receives it. Make the security baseline universal, send style guidance to the relevant files, and reserve discretionary selection for guidance whose relevance depends on the task.

Four parallel architectural lanes show rules reaching Agent context through every chat, a matching file, a description-based choice or a manual @mention.
These are alternative triggers. Choose the trigger before polishing the instruction.

Three Copy-Paste Rules for a TypeScript Web App

Create the following files in your repository. These are suggested house conventions, using the frontmatter fields and pattern syntax in Cursor's reference. The instructions inside are starting points to adapt, not Cursor's prescribed coding standards.

Style: Attach to TypeScript Files

Save as .cursor/rules/style.mdc:

Markdown
---
globs: src/**/*.ts, src/**/*.tsx
alwaysApply: false
---

- Follow the nearest existing module's naming and import conventions.
- Prefer named exports unless the framework requires a default export.
- Reuse existing UI components and utilities before adding alternatives.
- Keep formatting in the repository's formatter and linter configuration.

This example assumes application code lives under src/; adjust the paths to match your repository. It is deliberately about choices a formatter cannot settle, such as whether the app already has a suitable button or date helper. Adjust the export preference if your team has made a different decision. A rule should describe your repository, not quietly redesign it.

Tests: Describe the Tasks That Need Them

Save as .cursor/rules/tests.mdc:

Markdown
---
description: Testing requirements when adding features, fixing bugs, or changing TypeScript behavior
alwaysApply: false
---

- Cover changed behavior with a focused regression test.
- Use the existing test runner, fixtures, and file naming conventions.
- Read package.json for the relevant test script; do not invent a command.
- Report the command and actual result, or explain why tests were not run.

The intended outcome is a useful test and an honest result. A bug fix should leave evidence that the original failure is covered. A refactor should preserve the relevant behavior. Neither needs a second testing framework or a report that confuses “test written” with “test passed.”

For work where you want this checklist explicitly, include @tests in your request. If your team wants it on every task, change its attachment to Always Apply. Treat that as a deliberate policy choice; the description alone leaves selection to the agent.

Security: Keep the Baseline Short

Save as .cursor/rules/security.mdc:

Markdown
---
alwaysApply: true
---

- Never put secrets in source code, test fixtures, or application logs.
- Use existing server-side authentication and authorization helpers.
- Validate untrusted input at server boundaries with the existing schemas.
- Do not remove permission checks to make a feature or test pass.

Replace “existing helpers” with your repository's actual module paths when you know them. Keep the baseline understandable during an ordinary feature task. “Make it secure” gives a reviewer little to inspect; “preserve the authorization check” identifies a concrete requirement.

This file is an instruction, not a security boundary. Continue enforcing access checks in code and reviewing sensitive changes. Cursor itself cautions against relying on AI guidance as the only security control. Team Rules guidance

Verify the Setup on a Real Change

Use a small task that previously caused repeated corrections. A form validation change is a useful candidate: it touches a component, changes behavior and accepts user input.

  1. Write down the expected outcome. Name the existing component to reuse, the behavior to test and the validation boundary to preserve.
  2. Save the three files and inspect their status. Cursor exposes rules under Customize → Rules; /create-rule is also available in Agent. Creating a rule
  3. Ask for the change with the relevant files in context. Keep the request realistic. A task that restates every rule cannot tell you whether the setup helped.
  4. Review the diff and reported checks. Look for the actual convention, not an assurance that the rules were followed. If the test checklist matters for this trial, explicitly request @tests.
  5. Commit the useful rules with the change. Give the team a reviewable starting point. Amend a vague sentence before adding another file.

If a convention is missed, separate two failures: the rule did not reach the task, or the instruction reached it but was ineffective. The first calls for an attachment fix. The second calls for a clearer instruction, an example, or an automated check.

The Few Conventions Worth Keeping

Start where repeated mistakes cost your team the most. These are practical uses to consider, ranked by the review burden they could remove.

Team situationInstruction worth capturingIntended payoff
A small product team repeatedly fixes bugs without regression coverageRequire a focused test and its actual resultFewer review rounds asking for evidence
A frontend developer keeps receiving duplicate UI componentsPoint to the approved component and import conventionLess cleanup and fewer competing abstractions
A SaaS team adds routes with inconsistent permission checksIdentify the existing authorization helperMake sensitive changes easier to review
A developer moves between frontend and backend packagesWrite down each package's real architectural boundaryLess accidental mixing of responsibilities
A maintainer handles occasional database migrationsKeep a manually requested migration checklistPreserve rare, consequential knowledge without growing the daily brief

Do not turn these into a mandate to create five more files. If a problem has not occurred, leave it out. If a machine can check the requirement precisely, prefer that check. A useful rule fills a gap between the task request and the repository's existing tooling.

What About the Old .cursorrules File?

Use .cursor/rules/*.mdc for the current documented project setup. As of October 11, 2026, the rules page does not mention .cursorrules, so it does not confirm whether the legacy file still works. Current reference

For a repository that still carries the old file, my recommendation is to move its useful instructions into focused project rules, using the three files above as a starting point. Choose their triggers, and verify a real task before retiring the old copy. Do not preserve obsolete conventions simply because they were already written down.

How This Maps to CLAUDE.md and AGENTS.md

The shared idea is a standing project brief: Claude Code has CLAUDE.md, and Codex reads AGENTS.md working agreements. Cursor's plain Markdown option serves that same simple use case, while its .mdc files expose attachment choices. Keep the underlying conventions consistent, but configure each tool's loading behavior deliberately; copying prose is not the same as copying settings. For teams using several agents, nominate one owner for the shared conventions so the files do not become competing sources of truth.

Two Small Tools Worth Building After Setup

A repository rule checker is the stronger opportunity for an engineering lead: check file extensions, recognized frontmatter fields and patterns that match no tracked files. Its smallest useful version is a local report run during review. The demand signal is modest: DataForSEO returned 140 estimated monthly searches for “cursor rules examples” in this article's research. That is adjacent interest, not evidence people will pay. The catch is clear: a structurally valid rule can still be poor guidance. Metric definition

A team convention review packet could help a lead maintaining several repositories. Turn recurring review comments and approved examples into a proposed rules diff, with a named reviewer for each change. DataForSEO returned 70 estimated monthly searches for “cursor team rules”. Start as an internal utility; native Team Rules already handle distribution, so another storage dashboard is a weak product. The useful work is deciding what deserves to become a standing instruction. Metric definition

Questions That Come Up During Setup

Why does Cursor still ignore my rule?

First check the file and attachment settings against the tables above. Then try a small task with an explicit rule mention. If that helps, investigate attachment; if it does not, inspect the instruction for ambiguity or conflict and judge the resulting diff. One successful trial is useful evidence, not a guarantee for future tasks.

Can I save a project rule as a normal .md file?

Not inside .cursor/rules: that requires .mdc. Use AGENTS.md for plain Markdown. File formats

Will these rules change Cursor Tab suggestions?

No. Rules do not govern Cursor Tab. User Rules also do not apply to Inline Edit. Feature scope

Should I paste the whole team style guide into a rule?

Start with the decisions that keep causing corrections. Leave mechanical formatting to your tools, and turn an ambiguous convention into a short instruction with an identifiable example. A long document that nobody maintains will make the next review harder.

Next week, pick one recurring correction, make the corresponding rule precise, and try it on the next ordinary pull request. For the broader product decision, read the Cursor review or best Cursor alternatives.

If you want this wired into a team's development workflow, AI production systems is where that work fits.

Published
Category
Build
Related Articles
OpenAI Codex CLI: First Task and Team Settings

OpenAI Codex CLI: First Task and Team Settings

Install Codex CLI, sign in, complete a useful first task, then set up models, approvals, AGENTS.md, MCP servers and worktrees for your team.Oct 11, 2026Build
Claude Code Best Practices

Claude Code Best Practices

Claude Code habits in adoption order: verification, planning, CLAUDE.md, context, costs, permissions, hooks, subagents, and worktrees.Oct 11, 2026Build
Codex Plugin

Codex Plugin

Install a Codex plugin, build a three-file team package, and share it through a repo marketplace with clear authentication and admin controls.Oct 11, 2026Build
CLAUDE.md: Write It Once, Start Every Session Right

CLAUDE.md: Write It Once, Start Every Session Right

Write a useful CLAUDE.md, scope project rules, and manage Claude Code auto memory with a 35-line starter and a monthly cleanup routine.Oct 11, 2026Build
Jev Alternatives in 2026: OpenAI, Microsoft, Clef, d1, Perplexity and Strands (Compared)

Jev Alternatives in 2026: OpenAI, Microsoft, Clef, d1, Perplexity and Strands (Compared)

Compare Jev alternatives by job, maker-verified input pricing, licences and deployment: OpenAI, Microsoft, Clef, Liquid d1, Perplexity and Strands.Oct 11, 2026Build
OpenAI Decisions API

OpenAI Decisions API

Use OpenAI Decisions API for ticket routing, labels, and action gates. Three guide requests, refusal handling, pricing, limits, and when to keep your LLM.Oct 11, 2026Build
Claude Code Remote Control

Claude Code Remote Control

Set up Claude Code Remote Control from CLI, VS Code or Desktop, connect your phone or browser, and fix documented login and connection failures.Oct 9, 2026Build
Cursor Remote Control

Cursor Remote Control

Set up Cursor Remote Control on iPhone, pair your laptop, keep local agents reachable, and compare cloud agents, Claude Code and Codex.Oct 9, 2026Build
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.