While experimenting with agent rules across a few repositories, I noticed something frustrating. The same task could produce different results depending on which rules the agent decided to load. Sometimes it followed the expected conventions. Other times it missed relevant instructions or applied rules that had little to do with the task.
I initially assumed the rules needed clearer instructions. After revisiting the configuration, I started paying more attention to how the agent selected them.
That turned out to be the more useful place to focus.
Why My Initial Rule Setup Was Unpredictable
My first approach seemed reasonable. I created rules for different parts of the codebase, added descriptions, used globs to associate rules with files, and marked a few as global.
The setup covered the conventions I wanted the agent to follow. The behavior was still inconsistent.
Some rules appeared during unrelated tasks. Others were missing when I expected them to apply. Debugging was difficult because I couldn't reliably predict which instructions the agent would have available.
The pattern suggested that rule selection was contributing to the inconsistent behavior. Even a well-written instruction has limited value when the agent fails to load it for the relevant task.
I started treating selection as a separate responsibility that needed its own design.
Separating Rule Selection From Rule Content
Agent rules have two responsibilities:
- Determine when an instruction should be available to the agent.
- Define the behavior the agent should follow once that instruction is loaded.
I had been mixing these responsibilities together. Some descriptions contained implementation details, while individual rules covered several unrelated scenarios. A few rules combined global conventions with instructions that only applied to specific tasks.
Separating these concerns made the configuration easier to reason about.
The rule metadata could focus on identifying relevant tasks, while the body could describe the actual requirements. This also gave me a clearer way to investigate failures: first check whether the expected rule was selected, then look at how the agent followed its instructions.
Choosing How Rules Are Applied
In Cursor, three configuration mechanisms are particularly useful for deciding when rules apply: always-applied rules, file globs, and agent-requested rules selected through descriptions.
Each serves a different purpose.
Always-Applied Rules for Shared Constraints
An always-applied rule makes its instructions available across tasks. I use this for conventions that should remain consistent throughout a repository.
For example:
---
alwaysApply: true
---
All API responses must follow the standard envelope format.
This works well for repository-wide requirements such as response formats, naming conventions, or logging standards.
The tradeoff is context. Every always-applied rule adds instructions regardless of whether they matter for the current task.
My preference is to keep this group small. If a convention only matters when working on a particular feature or type of file, I give it a more specific selection mechanism.
Globs for File-Specific Rules
Globs associate instructions with matching files. They're useful when the conventions are closely tied to a particular part of the repository.
For example:
---
globs: src/api/**/*.ts
alwaysApply: false
---
Controllers should delegate business logic to services.
When working directly with matching files, this approach gave me fairly predictable results.
The limitations became more apparent with broader requests.
Consider a prompt like:
Refactor the authentication flow.
The agent may need to inspect controllers, services, middleware, and shared utilities before deciding how to make the change.
At the beginning of that task, the relevant files may still be unknown. Rules associated with those files may only become available as the agent discovers and works with them.
That creates a timing issue. A file-scoped rule might arrive after the agent has already formed its initial approach.
I still find globs useful for localized changes where the files are known. For cross-cutting tasks, I prefer giving the agent a way to discover relevant instructions from the task itself.
Descriptions for Task-Based Selection
Descriptions made the biggest difference in how I approached rule configuration.
For agent-requested rules, the description helps the agent recognize when an instruction is relevant. That makes the wording important.
My early descriptions looked like this:
- Defines API best practices
- Database rules
- Service layer architecture
These accurately described the contents of the files, but left the agent to infer which tasks required them.
I rewrote them around recognizable activities:
- Use when adding or modifying API endpoints
- Use when changing database schemas or migrations
- Use when implementing business logic in the service layer
These descriptions gave the agent clearer signals about which instructions belonged to a task.
The difference is subtle, but useful. A description that names an activity can be matched against the user's request before the agent knows which files it will edit.
This approach was especially helpful for tasks that crossed multiple parts of the codebase.
Writing Descriptions That Are Easy to Match
The most useful descriptions I ended up with were short and specific. They described the conditions that should cause the agent to select a rule.
A simple pattern worked well:
Use when [task or context]
For example:
- Use when creating or modifying React components
- Use when implementing API request validation
- Use when adding or changing caching behavior
- Use when creating database migrations
I also try to use the same terminology that appears in task requests.
If developers commonly ask the agent to "add an endpoint," that phrase is a useful selection signal. An abstract description such as "API architecture conventions" requires more interpretation.
This is still a heuristic. Descriptions guide model-based selection, so they cannot guarantee that a rule will be loaded every time. They do, however, give the agent a more explicit connection between the task and the available instructions.
Keeping Rule Bodies Focused
Once a rule is selected, its body needs to provide instructions the agent can apply.
I try to keep each rule focused on one responsibility, with concrete constraints and examples where they help.
For example:
---
description: Use when implementing API controllers
alwaysApply: false
---
Controllers should:
- Parse and validate requests
- Call application services
- Format HTTP responses
Controllers must not:
- Implement business logic
- Access the database directly
The description identifies the relevant task. The body defines the controller conventions.
This structure also makes maintenance easier. I can adjust the selection conditions without rewriting the implementation guidance, or update the conventions without changing when the rule applies.
Rules that cover a single responsibility are also easier to review for overlap and conflicting instructions.
Organizing Rules by Responsibility
As the number of rules grew, organizing them became another part of maintaining predictable behavior.
I found it easier to group instructions around distinct areas of responsibility:
.cursor/
rules/
api.mdc
database.mdc
frontend.mdc
global.mdc
Each file covers a recognizable domain.
This structure makes it easier to inspect which rules might apply to a task and identify areas where multiple rules could provide conflicting guidance.
I also try to keep the boundaries reasonably narrow. A single API rule can become difficult to maintain if it contains controller conventions, authentication requirements, caching behavior, and database access patterns.
When those concerns start growing independently, splitting them into more focused rules gives each one a clearer selection condition.
Using Markdown as the Source of Truth
Another approach I found useful was keeping the detailed instructions in ordinary Markdown files and using Cursor rule files as entry points.
For example:
docs/
api.md
database.md
.cursor/
rules/
api.mdc
database.mdc
The Cursor rule can be small:
---
description: Use when adding or modifying API endpoints
alwaysApply: false
---
Read and follow the conventions in docs/api.md.
The Markdown document contains the detailed API conventions, while the Cursor rule tells the agent when to retrieve them.
I like this separation for a few reasons.
First, the actual guidance is easier to maintain as normal project documentation. Second, other tools and agents can reference the same files. Third, the selection configuration stays small enough to inspect without digging through implementation details.
There is a tradeoff here, too. The agent has to read the referenced document for the instructions to become useful. That introduces another dependency into the workflow, and the rule needs to make that requirement explicit.
For instructions that are short and specific to Cursor, keeping everything in the .mdc file may be simpler. Shared Markdown becomes more attractive when several agents need to follow the same conventions.
What I Expected vs. What Happened
What I expected
Adding more rules would give the agent more complete guidance and improve its accuracy.
What happened
As the rule collection grew, selecting the relevant instructions became harder to reason about. I saw rules trigger for unrelated tasks and expected rules fail to appear.
Reducing overlap, narrowing rule responsibilities, and improving descriptions made the behavior more consistent in the repositories I was working with.
These were observations from iterative use, without a controlled benchmark. I haven't isolated the individual contribution of each change, and model-based rule selection still introduces variability.
The experience changed how I think about rule configuration, though. The number of available instructions tells me very little about whether the agent will use the right ones.
Making Rule Selection Easier to Reason About
The configuration I now prefer is fairly simple:
- Keep always-applied rules limited to repository-wide constraints.
- Use globs when instructions depend on specific files.
- Write descriptions around recognizable tasks and activities.
- Give each rule a narrow, clear responsibility.
- Keep shared conventions in Markdown when multiple agents need them.
- Inspect which rules were loaded when debugging unexpected behavior.
The most important change was making rule selection something I could reason about independently from the instructions themselves.
There is still an interesting question about how reliably an agent selects rules based on their descriptions. A useful next experiment would be to run the same set of tasks against different description styles and compare which rules are selected across repeated runs.
For now, I prefer a smaller collection of rules with clear selection conditions. It's easier to maintain, easier to debug, and gives me a better understanding of which instructions the agent is likely to see when it starts working.
