- Without conditionals: every rule loads for every request.
- With conditionals, rules activate only when your current files match their defined scope.
How It Works
Conditional rules use YAML frontmatter at the top of your rule files. When Cline processes a request, it gathers context from your current work (open files, visible tabs, mentioned paths, edited files), evaluates each rule’s conditions, and activates matching rules.When a conditional rule activates, you’ll see a notification: “Conditional rules applied: workspace:frontend-rules.md”
Writing Conditional Rules
Add YAML frontmatter to the top of any rule file in your.clinerules/ directory:
--- markers delimit the frontmatter. Everything after the closing --- is your rule content.
The paths Conditional
Currently, paths is the supported conditional. It takes an array of glob patterns:
*matches any characters except/**matches any characters including/(recursive)?matches a single character[abc]matches any character in the brackets{a,b}matches either pattern
| Pattern | Matches |
|---|---|
src/**/*.ts | All TypeScript files under src/ |
*.md | Markdown files in root only |
**/*.test.ts | Test files anywhere in the project |
packages/{web,api}/** | Files in web or api packages |
src/components/*.tsx | TSX files directly in components (not nested) |
Behavior Details
Multiple patterns: A rule activates if any pattern matches any file in your context.paths: [] means the rule never activates. Use this to temporarily disable a rule.
Invalid YAML: If frontmatter can’t be parsed, Cline fails open: the rule activates with raw content visible to help debugging.
What Counts as “Current Context”
Cline evaluates rules based on:- Your message: File paths mentioned in your prompt (e.g., “update
src/App.tsx”) - Open tabs: Files currently open in your editor
- Visible files: Files visible in your active editor panes
- Edited files: Files Cline has created, modified, or deleted during the task
- Pending operations: Files Cline is about to edit
Practical Examples
Copy these patterns and adapt them to your project structure.Frontend vs Backend Rules
Keep frontend and backend rules separate to avoid noise. Frontend rules only load when working with UI code, backend rules only load when working with API or service code.Test File Rules
Enforce testing standards automatically. This rule activates only when you’re writing or modifying tests, so testing guidance appears exactly when you need it.Documentation Rules
Apply documentation standards only when editing docs. Prevents style rules from cluttering your context when you’re writing code.Combining with Rule Toggles
Conditional rules work alongside the rule toggle UI. Toggle off a conditional rule to disable it entirely (it won’t activate even if paths match). Toggle on to let it activate when conditions are met. This provides two levels of control: manual toggles and automatic condition-based activation.Tips for Effective Conditional Rules
Start Broad, Then Narrow
Begin with broader patterns and refine as you learn what works:Use Descriptive Filenames
Name your rule files to indicate their scope:Keep Universal Rules Separate
Put always-on rules (coding standards, project conventions) in files without frontmatter. Reserve conditional rules for context-specific guidance.Test Your Patterns
Not sure if a pattern matches? Create a simple test rule:Troubleshooting
Rule not activating:- Check that file paths in your context match the glob pattern
- Verify the rule is toggled on in the rules panel
- Ensure YAML frontmatter has proper
---delimiters
- Review glob patterns:
**is recursive and may match more than intended - Check for open files that match the pattern
- File paths mentioned in your message also count as context
- YAML couldn’t be parsed
- Check for syntax errors (unquoted special characters, improper indentation)
Related
- Cline Rules Overview - Complete rules system guide
- Skills - Load instructions on demand with
/skillcommand - Workflows - Define explicit task automation
- @ Mentions - Add files to context explicitly
- Understanding Context Management - How Cline manages context window

