cline-rules.mdx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. Cline Rules allow you to provide Cline with system-level guidance. Think of them as a persistent way to include context and preferences for your projects or globally for every conversation.
  2. ## Creating a Rule
  3. You can create a rule by clicking the `+` button in the Rules tab. This will open a new file in your IDE which you can use to write your rule.
  4. <Frame>
  5. <img src="https://storage.googleapis.com/cline_public_images/docs/assets/cline-rules.png" alt="Create a Rule" />
  6. </Frame>
  7. Once you save the file:
  8. - Your rule will be stored in the `.clinerules/` directory in your project (if it's a Workspace Rule)
  9. - Or in the Global Rules directory (if it's a Global Rule):
  10. ### Global Rules Directory Location
  11. The location of your Global Rules directory depends on your operating system:
  12. | Operating System | Default Location | Notes |
  13. |------------------|------------------|-------|
  14. | **Windows** | `Documents\Cline\Rules` | Uses system Documents folder |
  15. | **macOS** | `~/Documents/Cline/Rules` | Uses user Documents folder |
  16. | **Linux/WSL** | `~/Documents/Cline/Rules` | May fall back to `~/Cline/Rules` on some systems |
  17. > **Note for Linux/WSL users**: If you don't find your global rules in `~/Documents/Cline/Rules`, check `~/Cline/Rules` as the location may vary depending on your system configuration and whether the Documents directory exists.
  18. You can also have Cline create a rule for you by using the [`/newrule` slash command](/features/slash-commands/new-rule) in the chat.
  19. ```markdown Example Cline Rule Structure [expandable]
  20. # Project Guidelines
  21. ## Documentation Requirements
  22. - Update relevant documentation in /docs when modifying features
  23. - Keep README.md in sync with new capabilities
  24. - Maintain changelog entries in CHANGELOG.md
  25. ## Architecture Decision Records
  26. Create ADRs in /docs/adr for:
  27. - Major dependency changes
  28. - Architectural pattern changes
  29. - New integration patterns
  30. - Database schema changes
  31. Follow template in /docs/adr/template.md
  32. ## Code Style & Patterns
  33. - Generate API clients using OpenAPI Generator
  34. - Use TypeScript axios template
  35. - Place generated code in /src/generated
  36. - Prefer composition over inheritance
  37. - Use repository pattern for data access
  38. - Follow error handling pattern in /src/utils/errors.ts
  39. ## Testing Standards
  40. - Unit tests required for business logic
  41. - Integration tests for API endpoints
  42. - E2E tests for critical user flows
  43. ```
  44. ### Key Benefits
  45. 1. **Version Controlled**: The `.clinerules` file becomes part of your project's source code
  46. 2. **Team Consistency**: Ensures consistent behavior across all team members
  47. 3. **Project-Specific**: Rules and standards tailored to each project's needs
  48. 4. **Institutional Knowledge**: Maintains project standards and practices in code
  49. Place the `.clinerules` file in your project's root directory:
  50. ```
  51. your-project/
  52. ├── .clinerules
  53. ├── src/
  54. ├── docs/
  55. └── ...
  56. ```
  57. Cline's system prompt, on the other hand, is not user-editable ([here's where you can find it](https://github.com/cline/cline/blob/main/src/core/prompts/system.ts)). For a broader look at prompt engineering best practices, check out [this resource](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview).
  58. ### AGENTS.md Standard Support
  59. Cline also supports the [AGENTS.md](https://agents.md/) standard as a fallback
  60. (in addition to Cline Rules) by automatically detecting `AGENTS.md` files in
  61. your workspace root. This allows you to use the same rules file across different AI
  62. coding tools.
  63. ```
  64. your-project/
  65. ├── AGENTS.md
  66. ├── src/
  67. └── ...
  68. ```
  69. ### Tips for Writing Effective Cline Rules
  70. - Be Clear and Concise: Use simple language and avoid ambiguity.
  71. - Focus on Desired Outcomes: Describe the results you want, not the specific steps.
  72. - Test and Iterate: Experiment to find what works best for your workflow.
  73. ### .clinerules/ Folder System
  74. ```
  75. your-project/
  76. ├── .clinerules/ # Folder containing active rules
  77. │ ├── 01-coding.md # Core coding standards
  78. │ ├── 02-documentation.md # Documentation requirements
  79. │ └── current-sprint.md # Rules specific to current work
  80. ├── src/
  81. └── ...
  82. ```
  83. Cline automatically processes **all Markdown files** inside the `.clinerules/` directory, combining them into a unified set of rules. The numeric prefixes (optional) help organize files in a logical sequence.
  84. #### Using a Rules Bank
  85. For projects with multiple contexts or teams, maintain a rules bank directory:
  86. ```
  87. your-project/
  88. ├── .clinerules/ # Active rules - automatically applied
  89. │ ├── 01-coding.md
  90. │ └── client-a.md
  91. ├── clinerules-bank/ # Repository of available but inactive rules
  92. │ ├── clients/ # Client-specific rule sets
  93. │ │ ├── client-a.md
  94. │ │ └── client-b.md
  95. │ ├── frameworks/ # Framework-specific rules
  96. │ │ ├── react.md
  97. │ │ └── vue.md
  98. │ └── project-types/ # Project type standards
  99. │ ├── api-service.md
  100. │ └── frontend-app.md
  101. └── ...
  102. ```
  103. #### Benefits of the Folder Approach
  104. 1. **Contextual Activation**: Copy only relevant rules from the bank to the active folder
  105. 2. **Easier Maintenance**: Update individual rule files without affecting others
  106. 3. **Team Flexibility**: Different team members can activate rules specific to their current task
  107. 4. **Reduced Noise**: Keep the active ruleset focused and relevant
  108. #### Usage Examples
  109. Switch between client projects:
  110. ```bash
  111. # Switch to Client B project
  112. rm .clinerules/client-a.md
  113. cp clinerules-bank/clients/client-b.md .clinerules/
  114. ```
  115. Adapt to different tech stacks:
  116. ```bash
  117. # Frontend React project
  118. cp clinerules-bank/frameworks/react.md .clinerules/
  119. ```
  120. #### Implementation Tips
  121. - Keep individual rule files focused on specific concerns
  122. - Use descriptive filenames that clearly indicate the rule's purpose
  123. - Consider git-ignoring the active `.clinerules/` folder while tracking the `clinerules-bank/`
  124. - Create team scripts to quickly activate common rule combinations
  125. The folder system transforms your Cline rules from a static document into a dynamic knowledge system that adapts to your team's changing contexts and requirements.
  126. ### Managing Rules with the Toggleable Popover
  127. To make managing both single `.clinerules` files and the folder system even easier, Cline v3.13 introduces a dedicated popover UI directly accessible from the chat interface.
  128. Located conveniently under the chat input field, this popover allows you to:
  129. - **Instantly See Active Rules:** View which global rules (from your user settings) and workspace rules (`.clinerules` file or folder contents) are currently active.
  130. - **Quickly Toggle Rules:** Enable or disable specific rule files within your workspace `.clinerules/` folder with a single click. This is perfect for activating context-specific rules (like `react-rules.md` or `memory-bank.md`) only when needed.
  131. - **Easily Add/Manage Rules:** Quickly create a workspace `.clinerules` file or folder if one doesn't exist, or add new rule files to an existing folder.
  132. This UI significantly simplifies switching contexts and managing different sets of instructions without needing to manually edit files or configurations during a conversation.
  133. <Frame>
  134. <img src="https://storage.googleapis.com/cline_public_images/docs/assets/image%20(1).png" alt="Cline Logo" />
  135. </Frame>