@haram

Mastering Cursor .mdc: How to Save Tokens and Apply Folder-Specific Rules
Many developers use rule files to avoid the hassle of typing the same instructions every time they code with Cursor. However, dumping all your rules into a single file can lead to pointless waste of precious AI context tokens every time you ask a question.
The standard is now to use .mdc files to break down and manage rules by folder and function. Let's look at how to create a smooth development environment where custom rules are applied automatically based on your working directory, all while saving tokens.
Don't Apply Always — The '2-4-2 Rule' to Prevent Token Waste
When automating your workflow with Cursor rule files (.mdc), it's tempting to fill them with every possible instruction. However, setting alwaysApply: true to true for every file is a trap. Since Cursor reads every rule in the project from start to finish for every single line of code you change, it consumes a massive amount of AI tokens.
To solve this gracefully, a widely used community tip is the '2-4-2 Rule.' It involves splitting and storing files based on the nature of the rules and how often they are used.
First, prepare 2 common rules that always apply to the entire project. The key is to keep them light—under 200 lines each. Only apply the 'always' option to essential guides that must be known throughout development, such as coding style standards or a core framework list.
Next, design 4 conditional rules that react automatically for specific folders or files. Keep them off by default, like rules for backend folders or frontend components, but register path patterns so they are pulled in automatically when those files are opened.
The remaining 2 special rules should be completely disabled and used manually. These include things like rare debugging tips or tricky deployment checklists. They won't take up context space until you call them directly in the chat using the @ symbol.
By intelligently splitting rule roles, Cursor only uses its brain when absolutely necessary, preventing wasteful token usage.
Catching Silent YAML Syntax Errors
Sometimes it feels like Cursor is ignoring your rules no matter how hard you write them. If rules quietly fail without an error message, it's almost certainly due to a minor syntax error in the YAML frontmatter at the top of the file.
.mdc files must have a perfectly written settings section enclosed in triple dashes (---) at the top to function. Here are the key rules to watch out for:
- Lowercase booleans only: The
alwaysApplyvalue must be written in lowercase astrueorfalse. It is case-sensitive, so usingTruewith a capital letter won't be recognized. - No-space path patterns: The
globsfield, which indicates the target, should be tightly connected with commas and no spaces for safety. Mixing in spaces often causes file matching to fail during parsing. - Importance of summaries: The
descriptionshould summarize the essence in one sentence under 120 characters. This is because whenalwaysApplyis disabled, Cursor reads this description to call the rule intelligently.
You can follow the template below for a proper .mdc file frontmatter structure.
---
description: "React 컴포넌트 작성 시 한글 주석 가이드와 코드 스타일 제어"
globs: "src/**/*.tsx,src/**/*.ts"
alwaysApply: false
---
# React 개발 규칙
- 컴포넌트 파일 생성 시 반드시 한글 주석을 활용합니다.
- 공통 유틸리티는 `@/shared/utils` 경로에서만 불러와 사용합니다.By following just this minimum syntax, you can activate custom rules smoothly without them getting tangled or ignored.
The Closest Rule Wins: Folder Overrides and Loading Order
Cursor prioritizes the rule folder closest to the file you are currently working on. For example, if you are modifying a service file in the backend folder, the rule inside that backend folder will trigger before a general rule in the project root.
Because more specific sub-folder rules naturally override and merge with parent folder rules, you can smartly segment and manage your development environment by folder.
If you are worried about conflicts when multiple rules execute simultaneously in the same folder, try refining your file naming convention. Cursor loads rule files alphabetically within the same folder.
The secret to cleanly controlling this load order is to prefix file names with numbers. By explicitly setting the order like 001-base.mdc, 100-frontend.mdc, complex rules will not tangle and will instead load one by one in the order you intended.
Small, clear rules make for smarter AI
Multiple light .mdc files that focus on their own roles are much more powerful than a single heavy rule file packed with every instruction. Try refactoring your project rules smartly using the 2-4-2 rule and directory-specific priorities shared today. You will see a significant reduction in the time and tokens Cursor spends trying to read unnecessary context, allowing for a much more comfortable and intuitive development flow.