|
| 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 | + |
| 3 | +## Creating a Rule |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +<Frame> |
| 8 | + <img src="https://storage.googleapis.com/cline_public_images/docs/assets/cline-rules.png" alt="Create a Rule" /> |
| 9 | +</Frame> |
| 10 | + |
| 11 | +Once you save the file: |
| 12 | + |
| 13 | +- Your rule will be stored in the `.clinerules/` directory in your project (if it's a Workspace Rule) |
| 14 | +- Or in the `Documents/Cline/Rules` directory (if it's a Global Rule). |
| 15 | + |
| 16 | +You can also have Cline create a rule for you by using the [`/newrule` slash command](/features/slash-commands/new-rule) in the chat. |
| 17 | + |
| 18 | +```markdown Example Cline Rule Structure [expandable] |
| 19 | +# Project Guidelines |
| 20 | + |
| 21 | +## Documentation Requirements |
| 22 | + |
| 23 | +- Update relevant documentation in /docs when modifying features |
| 24 | +- Keep README.md in sync with new capabilities |
| 25 | +- Maintain changelog entries in CHANGELOG.md |
| 26 | + |
| 27 | +## Architecture Decision Records |
| 28 | + |
| 29 | +Create ADRs in /docs/adr for: |
| 30 | + |
| 31 | +- Major dependency changes |
| 32 | +- Architectural pattern changes |
| 33 | +- New integration patterns |
| 34 | +- Database schema changes |
| 35 | + Follow template in /docs/adr/template.md |
| 36 | + |
| 37 | +## Code Style & Patterns |
| 38 | + |
| 39 | +- Generate API clients using OpenAPI Generator |
| 40 | +- Use TypeScript axios template |
| 41 | +- Place generated code in /src/generated |
| 42 | +- Prefer composition over inheritance |
| 43 | +- Use repository pattern for data access |
| 44 | +- Follow error handling pattern in /src/utils/errors.ts |
| 45 | + |
| 46 | +## Testing Standards |
| 47 | + |
| 48 | +- Unit tests required for business logic |
| 49 | +- Integration tests for API endpoints |
| 50 | +- E2E tests for critical user flows |
| 51 | +``` |
| 52 | + |
| 53 | +### Key Benefits |
| 54 | + |
| 55 | +1. **Version Controlled**: The `.clinerules` file becomes part of your project's source code |
| 56 | +2. **Team Consistency**: Ensures consistent behavior across all team members |
| 57 | +3. **Project-Specific**: Rules and standards tailored to each project's needs |
| 58 | +4. **Institutional Knowledge**: Maintains project standards and practices in code |
| 59 | + |
| 60 | +Place the `.clinerules` file in your project's root directory: |
| 61 | + |
| 62 | +``` |
| 63 | +your-project/ |
| 64 | +├── .clinerules |
| 65 | +├── src/ |
| 66 | +├── docs/ |
| 67 | +└── ... |
| 68 | +``` |
| 69 | + |
| 70 | +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). |
| 71 | + |
| 72 | +### Tips for Writing Effective Cline Rules |
| 73 | + |
| 74 | +- Be Clear and Concise: Use simple language and avoid ambiguity. |
| 75 | +- Focus on Desired Outcomes: Describe the results you want, not the specific steps. |
| 76 | +- Test and Iterate: Experiment to find what works best for your workflow. |
| 77 | + |
| 78 | +### .clinerules/ Folder System |
| 79 | + |
| 80 | +``` |
| 81 | +your-project/ |
| 82 | +├── .clinerules/ # Folder containing active rules |
| 83 | +│ ├── 01-coding.md # Core coding standards |
| 84 | +│ ├── 02-documentation.md # Documentation requirements |
| 85 | +│ └── current-sprint.md # Rules specific to current work |
| 86 | +├── src/ |
| 87 | +└── ... |
| 88 | +``` |
| 89 | + |
| 90 | +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. |
| 91 | + |
| 92 | +#### Using a Rules Bank |
| 93 | + |
| 94 | +For projects with multiple contexts or teams, maintain a rules bank directory: |
| 95 | + |
| 96 | +``` |
| 97 | +your-project/ |
| 98 | +├── .clinerules/ # Active rules - automatically applied |
| 99 | +│ ├── 01-coding.md |
| 100 | +│ └── client-a.md |
| 101 | +│ |
| 102 | +├── clinerules-bank/ # Repository of available but inactive rules |
| 103 | +│ ├── clients/ # Client-specific rule sets |
| 104 | +│ │ ├── client-a.md |
| 105 | +│ │ └── client-b.md |
| 106 | +│ ├── frameworks/ # Framework-specific rules |
| 107 | +│ │ ├── react.md |
| 108 | +│ │ └── vue.md |
| 109 | +│ └── project-types/ # Project type standards |
| 110 | +│ ├── api-service.md |
| 111 | +│ └── frontend-app.md |
| 112 | +└── ... |
| 113 | +``` |
| 114 | + |
| 115 | +#### Benefits of the Folder Approach |
| 116 | + |
| 117 | +1. **Contextual Activation**: Copy only relevant rules from the bank to the active folder |
| 118 | +2. **Easier Maintenance**: Update individual rule files without affecting others |
| 119 | +3. **Team Flexibility**: Different team members can activate rules specific to their current task |
| 120 | +4. **Reduced Noise**: Keep the active ruleset focused and relevant |
| 121 | + |
| 122 | +#### Usage Examples |
| 123 | + |
| 124 | +Switch between client projects: |
| 125 | + |
| 126 | +```bash |
| 127 | +# Switch to Client B project |
| 128 | +rm .clinerules/client-a.md |
| 129 | +cp clinerules-bank/clients/client-b.md .clinerules/ |
| 130 | +``` |
| 131 | + |
| 132 | +Adapt to different tech stacks: |
| 133 | + |
| 134 | +```bash |
| 135 | +# Frontend React project |
| 136 | +cp clinerules-bank/frameworks/react.md .clinerules/ |
| 137 | +``` |
| 138 | + |
| 139 | +#### Implementation Tips |
| 140 | + |
| 141 | +- Keep individual rule files focused on specific concerns |
| 142 | +- Use descriptive filenames that clearly indicate the rule's purpose |
| 143 | +- Consider git-ignoring the active `.clinerules/` folder while tracking the `clinerules-bank/` |
| 144 | +- Create team scripts to quickly activate common rule combinations |
| 145 | + |
| 146 | +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. |
| 147 | + |
| 148 | +### Managing Rules with the Toggleable Popover |
| 149 | + |
| 150 | +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. |
| 151 | + |
| 152 | +Located conveniently under the chat input field, this popover allows you to: |
| 153 | + |
| 154 | +- **Instantly See Active Rules:** View which global rules (from your user settings) and workspace rules (`.clinerules` file or folder contents) are currently active. |
| 155 | +- **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. |
| 156 | +- **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. |
| 157 | + |
| 158 | +This UI significantly simplifies switching contexts and managing different sets of instructions without needing to manually edit files or configurations during a conversation. |
| 159 | + |
| 160 | +<Frame> |
| 161 | + <img src="https://storage.googleapis.com/cline_public_images/docs/assets/image%20(1).png" alt="Cline Logo" /> |
| 162 | +</Frame> |
0 commit comments