cline:rules - chunhualiao/public-docs GitHub Wiki

cline

How Cline Uses .clinerules Files

The .clinerules file serves as a configuration and guidance system for Cline throughout its interaction with your project. Here's how Cline processes and applies this file from beginning to end:

1. Initialization and Loading

When you open Cline in a workspace:

  • Cline automatically searches for a .clinerules file in your workspace root directory
  • The file is loaded into Cline's context as part of its initialization
  • If no .clinerules file exists, Cline uses default behaviors based on detected project type

2. Context Building

The .clinerules content becomes part of Cline's understanding of your project:

  • Project structure information helps Cline navigate your files
  • Guidelines shape how Cline interprets your requests
  • Best practices inform Cline's suggestions and code generation
  • File patterns guide what files Cline pays attention to

3. Request Processing

When you make a request to Cline:

  • Cline analyzes your request in the context of the .clinerules guidelines
  • The rules act as specialized instructions that influence how Cline responds
  • Domain-specific terminology and practices from the rules help Cline provide more relevant assistance

4. Response Generation

As Cline formulates responses:

  • Writing style guidelines influence the tone and format of responses
  • Content quality standards guide the depth and structure of information
  • Document structure recommendations shape how Cline organizes content
  • Best practices from the rules are incorporated into suggestions

5. Action Execution

When Cline performs actions (editing files, suggesting changes):

  • File organization guidelines help Cline place content appropriately
  • Quality standards from the rules are applied to generated content
  • Review process guidelines may prompt Cline to suggest reviews or checks
  • Project structure information guides where new files should be created

6. Continuous Application

Throughout your session:

  • The .clinerules file remains active in Cline's context
  • Rules are consistently applied across all interactions
  • Cline maintains awareness of the specialized domain (proposal writing, code development, academic writing) based on the rules
  • The guidelines help maintain consistency across multiple requests

7. Cross-Project References

If your .clinerules references other projects:

  • Cline can understand relationships between different workspaces
  • Terminology consistency can be maintained across related projects
  • References to external resources are understood in proper context

The .clinerules file essentially acts as a specialized instruction set that tailors Cline's capabilities to your specific project type and needs, ensuring that its assistance is contextually appropriate and aligned with your project's requirements.

How to check if they are used?

You're asking how to verify that Cline actually loads and uses your .clinerules file. Based on the codebase, there are several ways to confirm this.

Direct Verification Methods

1. Check the Rules Toggle UI

The most straightforward way is through Cline's built-in rules management interface. 1 When you open this modal, it refreshes all rules and displays their current toggle states. If your .clinerules file is being detected, it will appear in the local rules list.

2. Look for Console Output

Cline logs errors when it fails to read rules files. 2 If you don't see error messages like "Failed to read .clinerules file", that's a good sign the file is being processed.

3. Check the AI Context

When rules are successfully loaded, they get formatted and included in the AI model's context. 3 The system adds a header like "# .clinerules" followed by your rule content to the AI's instructions.

How Rules Flow Through the System

The loading process follows this path:

  1. Context Loading: During task execution, loadContext is called 4

  2. Rule Processing: The getLocalClineRules function reads your file 5

  3. Toggle Check: The system verifies the rule file is enabled in toggles 6

  4. Content Formatting: If enabled, the content gets formatted for the AI 7

  5. AI Integration: The formatted rules are added to the system prompt 8

Practical Testing Steps

  1. Open the Rules Modal: Click the law icon in Cline's interface to open the rules management modal
  2. Verify File Detection: Your .clinerules file should appear in the "Local Rules" section
  3. Check Toggle State: Ensure the toggle next to your file is enabled (not grayed out)
  4. Test Rule Behavior: Ask Cline to do something that should trigger your specific rules and observe if it follows them

Troubleshooting

If your rules aren't appearing:

  • Ensure the file is named exactly .clinerules (not .clinerules.txt or similar)
  • Verify it's in your project root directory
  • Check that the file isn't empty after trimming whitespace
  • Try refreshing the rules by reopening the rules modal

The toggle system 9 automatically synchronizes with your file system, so any changes should be reflected when you refresh the interface.

Notes

The rules system supports both file and directory formats for .clinerules, but most users should use a simple text file. The system also maintains separate toggles for global vs local rules, stored in VS Code's workspace state for persistence across sessions.

Wiki pages you might want to explore: