How to Override or Customize Guidelines for Specific Files in Cursor
Disable the global alwaysApply setting in .cursor/rules/karpathy-guidelines.mdc and add an applyTo glob pattern to limit the Karpathy Guidelines to specific file paths.
The multica-ai/andrej-karpathy-skills repository distributes a set of LLM-assisted coding principles known as the Karpathy Guidelines. By default, these rules apply unconditionally to every file in your project through the Cursor rule system, but you can override or customize guidelines for specific files using path-based selectors and complementary rule files.
Understanding the Global Rule Configuration
The default behavior is controlled by .cursor/rules/karpathy-guidelines.mdc, which contains the following YAML frontmatter:
---
description: Karpathy Guidelines
alwaysApply: true
---
Because alwaysApply is set to true, the rule is unconditional. Every LLM-assisted editing session in Cursor will invoke these guidelines regardless of which file you are editing. To gain granular control, you must first disable this global enforcement.
Step-by-Step: Override Guidelines for Specific Files
1. Disable the Global alwaysApply Setting
Remove or set alwaysApply: false in the original rule file. This stops the guidelines from being forced on every file. Alternatively, you can retire the original file and create new targeted rules in the same .cursor/rules/ directory.
2. Add an applyTo Selector
The applyTo field accepts a glob pattern that limits the rule’s scope to matching paths. When applyTo is present, Cursor evaluates the rule only when the edited file matches the pattern.
To apply the Karpathy Guidelines only to source files under src/, create a new rule file:
---
description: Karpathy guidelines limited to source files
applyTo: "src/**/*.js"
---
# (the rest of the guideline markdown)
You can use different glob patterns for different file types:
"src/**/*.py"— Python source files only"**/*.{ts,tsx}"— TypeScript and TSX files"!**/*.test.js"— Exclude test files (using negation)
3. Create Complementary Rules for Remaining Files
You can add a second rule file that targets the rest of the repository. This complementary rule can either:
- Re-introduce the original guidelines without
alwaysApply, or - Supply a lighter version (e.g., only the "Goal-Driven Execution" principle)
Place both rule files in .cursor/rules/. Cursor automatically loads all .mdc files found in this directory.
Syncing Customizations with CLAUDE.md
The CLAUDE.md file serves as the entry point for Claude Code plugins. To ensure your per-file customizations work when the repository is used as a Claude Code plugin, add an applyTo frontmatter block at the top of the file:
---
applyTo: "src/**/*.ts"
---
# Karpathy Guidelines
This mirrors the Cursor behavior for Claude Code, ensuring that the plugin respects the same file-level boundaries.
Keeping Rule Files in Synchronized
Whenever you modify the core guideline text, update all rule files that embed that text to avoid divergence. The relevant files include:
.cursor/rules/karpathy-guidelines.mdc— The default global ruleCLAUDE.md— The Claude Code plugin entry pointskills/karpathy-guidelines/SKILL.md— Reusable skill definition for personal Cursor skill directories
Refer to the "For contributors" section of CURSOR.md for detailed synchronization instructions.
Summary
- Disable
alwaysApplyin.cursor/rules/karpathy-guidelines.mdcto stop global enforcement of the Karpathy Guidelines. - Add
applyTowith a glob pattern to limit guidelines to specific directories or file types. - Create multiple rule files in
.cursor/rules/to apply different guideline sets to different parts of your codebase. - Update
CLAUDE.mdwith matchingapplyTofrontmatter to ensure Claude Code plugins respect the same boundaries. - Synchronize changes across all rule files when updating the core guideline content.
Frequently Asked Questions
Can I apply different guideline sets to different directories?
Yes. Create separate .mdc rule files in .cursor/rules/, each with a specific applyTo glob pattern. For example, one rule can target "src/**/*.py" with the full Karpathy Guidelines, while another targets "generated/**/*" with a relaxed version that disables the "Surgical Changes" principle.
What happens if multiple rules match the same file?
Cursor merges the applicable rules when multiple applyTo patterns match a single file. If the rules contain conflicting instructions, Cursor typically concatenates them or follows the most specific match. To avoid conflicts, ensure your glob patterns are mutually exclusive or design complementary rules that reinforce rather than contradict each other.
Do I need to modify the original karpathy-guidelines.mdc file?
No, you can leave the original file untouched and simply create new rule files with higher specificity. However, you must set alwaysApply: false in the original file (or remove it entirely) to prevent it from overriding your targeted rules. If you keep the original with alwaysApply: true, it will apply to every file regardless of other rules you create.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →