🧠 [AI Rules] How to actually force inclusion of specific files in context?

Hey team :waving_hand:

I’m working on a project that uses a custom SCSS system with two important files:

  • @var_default.scss: contains a SCSS map of all theme variables.

  • @font-icon.json: contains the full icon catalog (names + unicode mapping).

My goal is to use Cursor AI to help me edit .scss files more safely and intelligently.

We have custom mixins like:


@include icon-set-normal(icon-name);

color: setVariable(global__error__color);

The issue is: these mixins only work with values that exist in the two referenced files above.

So I wrote an AI rule like this (in Markdown):


# Rule: Always check @font-icon.json and @var_default.scss

When editing SCSS files, always consult @font-icon.json for icons and @var_default.scss for valid variables.

If these files are not loaded in the context, ask the user before continuing.

However… Cursor doesn’t really respect that.

Even though it acknowledges the rule (and sometimes mentions the files), it doesn’t truly load them into context.

Looking at the network inspector, I often see things like:


[font-icon.json](mdc:app/font-icon.json)

…which appears to be a reference, not the full inclusion of the file.

:light_bulb: My question:

Is there any way to force Cursor to load certain files in full before answering or suggesting code?

I’d like Cursor to:

  1. Include both files in context before editing SCSS.

  2. Stop and ask me if the files aren’t present (or auto-open them).

  3. Avoid suggesting variables or icons that don’t exist in these files.


Let me know if:

  • There’s a correct syntax for this in Rules (maybe with mustInclude or similar?).

  • You plan to support stronger file context validation in the future.

Thanks so much :folded_hands:

Since the code really requires the 2 files you can directly reference the 2 files with @ method in the prompt.

Are they large by any chance? That would make it harder for AI to fit into context.

Also I didnt see the mention but the rule file is .md or mdc?
If mdc, did you use the correct frontmatter header?

Thanks for the follow-up!

Yes, when I manually mention the files using @ in the prompt, it does work — but the whole point of creating a rule is so I don’t have to do that every single time :sweat_smile:

The files are actually very small, around 200 lines each, with simple key-value pairs like:

__color__global: #fff;

Also, yes — I’m using a .mdc file, and the rule type is set to Always.

So I was hoping Cursor would automatically include those files when editing SCSS files, without me having to prompt it manually every time.

Is there any way to truly enforce that behavior through a rule?

Thanks again :folded_hands:

Ah great, the files should be then not too big for context. Yes it should be auto included.

You can set the description of the mdc file to explain when exactly to use this rule. This can be a detailed description that goes into the description: field in the mdc file.

Alternatively you can try instead of the description the glob for extension *.scss

See:

Also do you use a User Rule In Cursor settings or .cursorrules file? There you could mention which rule to use for scss files if the above two methods dont help.

Just wanted to give an update on my side :backhand_index_pointing_down:

None of the rule-based methods worked as expected, so I tried another approach that finally did the trick:


I created a .mdc file like this:

	---
	description: Include Files For Better Rules Usage
	globs: **/*.scss
	alwaysApply: false
	---
	File :
	```var_tgs.scss```
	Content :
	```
	{
	  "icon": {
			"0001-user" : "\\E001",
			"0002-star" : "\\E002",
			"0003-delviery" : "\\E003",
			"0004-share" : "\\E004"
	  }
	}
	```

That actually worked for me — Cursor finally seemed to include the values and respect them when editing SCSS files.

Also worth noting:
I’m using Cursor behind a proxy compatible with the OpenAI API, and I feel like the behavior was slightly better when not going through the proxy. Could just be a coincidence, but figured it’s worth mentioning.

Thanks again for the help :raising_hands:

Hey there,

It’s extremely clear too me that you’ve put a lot of thought into this, and I appreciate the effort to refine the workflow.

From what you’ve described, Cursor acknowledges ONLY the .mdc rule but doesn’t fully enforce it in practice. The [font-icon.json](mdc:app/font-icon.json) reference suggests that the file is being treated as a link or placeholder rather than being loaded into the context, this is a known issue on Cursor’s end at least on my end.

While the Always rule type is designed to enforce consistent behavior, it seems Cursor isn’t fully ā€œloadingā€ the files into its reasoning process. Instead, it’s referencing them superficially, which leads to incomplete or incorrect suggestions.

You might need to experiment with more explicit syntax in your .mdc rule. For example:

Rule: Always Load @font-icon.json and @var_default.scss

When editing SCSS files:
MustInclude: @font-icon.json (for icons)
MustInclude: @var_default.scss (for variables)
If these files are not present in the context, stop and ask the user before proceeding.


As a temporary workaround, you could prepend a manual prompt to every session unless you enforce the latest rules by calling the .mdc files before proceeding.

Note: I’ve personally changed from .mcd to .md. With enforced rules, it might not follow the proper guidelines of usage, but it works. Check my latest guide.

One shot prompt, use this before starting the project.

When editing SCSS files, you MUST ensure the full content of `@font-icon.json` (containing icon definitions) and `@var_default.scss` (containing design variables) is loaded and actively used as context. Treat these files as the definitive source for available icons and variables. If the content of either file is not fully available or loaded into your context, explicitly state this limitation and explain that accurate suggestions or edits cannot be guaranteed without them. Do not proceed with potentially incorrect assumptions; prioritize referencing the content of these specified files.

This is your new .mdc file:

# Version: 1.1
# Description: Attempts to ensure critical context files are loaded when editing SCSS.
# Note: Cursor's current limitations might prevent full enforcement of file loading.

# --- Global Directives ---
Always:
  # Maintain awareness of standard SCSS practices.
  # Prioritize variables and mixins from specified context files.

# --- SCSS Specific Rules ---
When editing files matching *.scss:
  # Critical Context Requirement:
  # The following files MUST be loaded for accurate SCSS editing:
  # 1. Icon Definitions: @font-icon.json
  # 2. Design Variables: @var_default.scss
  # Placeholder Directive (Illustrative - Adapt if Cursor supports similar):
  MustInclude: @font-icon.json
  MustInclude: @var_default.scss
  # If these files are not loaded, state the limitation before proceeding.```


-----

@kleosr from my experience re-directing to files inside rules works only half time, feel free to try if things have changed from around one month ago, @Mckay your approach is correct but description can be better, description: SCSS map of all theme variables, reference to the file is not needed as file content is already present, you could add instructions like # Critical: use only our theme variables when …
If you want a mdc with syntax highlighting, you can use ln to link an .scss file as .mdc, maintaining the mdc header between (---)
ln -s $(pwd)/ignoredfolder/var_tgs.scss $(pwd)/.cursor/rules/theme-variables.mdc

@normalnormie from what I’ve seen, re-directing to files inside rules does indeed have inconsistent behavior, especially when relying on Cursor to fully load and process those files.

  • Instead of relying solely on .mdc rules, you can manually reference files in the prompt before execution.
  • Try chain of thought prompting.

Based on my newest guide and your help on my first guide, I’ve came up with managing and leveraging Cursor to be more adapted to the user-like environment.

Ultimately, while .mdc rules are designed to streamline workflows, manual intervention (like pre-loading files or chaining prompts) seems to remain the most reliable workaround for now at least for me.

@Mckay normie it’s right about the description, maintain the .mdc header between the dashes.

1 Like

Really need a solution for this. Hate having to manually re-add the same 3 files over and over to the context of new chats.

I’ve noticed that if I simply say ā€˜read ā– ā– ā– .ā– ā– ā–  before doing things,’ the AI will often assume it’s done without actually reading it.

To address this, I’ve implemented rules that strictly force the AI to use list_dir and read_file, and prohibit it from assuming anything is done or exists. This method has worked well for me.

  • (Mandatory KB Consultation Trigger): After completing the ā€˜Mandatory Initial Brainstorming, Validation, & Feasibility Checks’ (Rule 2a), you MUST ALWAYS consult the Knowledge Base as the immediate next step, BEFORE proceeding to detailed strategy selection or implementation. This consultation MUST begin by reading the central index file document/kb_index.md using read_file. This step is required regardless of perceived confidence in the initial strategy, Skipping this mandatory KB search step constitutes a critical violation.
  • Mandatory Search & Verification - NO ASSUMPTIONS: **You MUST perform this search step using appropriate tools (codebase_search, list_dir, read_file). NEVER, under any circumstances, proceed to implementation assuming a KB search was done, assuming the content of potential files based on names, claiming knowledge of KB content without having explicitly performed the search and read actions in the current turn, OR ASSUMING A PREREQUISITE FILE

And yes, the rule file was also generated by the AI itself