| 1 | --- |
| 2 | title: "Rules" |
| 3 | description: Rules are used to provide instructions to the model for Agent, Chat, and Edit requests. |
| 4 | keywords: [rules, .continuerules, system, prompt, message] |
| 5 | --- |
| 6 | |
| 7 | Rules provide instructions to the model for [Agent](../../features/agent/quick-start), [Chat](../../features/chat/quick-start), and [Edit](../../features/edit/quick-start) requests. |
| 8 | |
| 9 | <Info> Rules are not included in [autocomplete](./autocomplete.mdx) or [apply](../model-roles/apply.mdx). |
| 10 | </Info> |
| 11 | |
| 12 | ## How it works |
| 13 | |
| 14 | You can view the current rules by clicking the pen icon above the main toolbar: |
| 15 | |
| 16 |  |
| 17 | |
| 18 | To form the system message, rules are joined with new lines, in the order they appear in the toolbar. This includes the base chat system message ([see below](#chat-system-message)). |
| 19 | |
| 20 | ## Quick Start |
| 21 | |
| 22 | Below is a quick example of setting up a new rule file: |
| 23 | |
| 24 | 1. Create a folder called `.continue/rules` at the top level of your workspace |
| 25 | 2. Add a file called `pirates-rule.md` to this folder. |
| 26 | 3. Write the following contents to `pirates-rule.md` and save. |
| 27 | |
| 28 | ```md title=".continue/rules/pirates-rule.md" |
| 29 | --- |
| 30 | name: Pirate rule |
| 31 | --- |
| 32 | |
| 33 | - Talk like a pirate. |
| 34 | ``` |
| 35 | |
| 36 | Now test your rules by asking a question about a file in chat. |
| 37 | |
| 38 |  |
| 39 | |
| 40 | ## Creating `rules` blocks |
| 41 | |
| 42 | Rules can be added locally using the "Add Rules" button while viewing the Local Agent's rules. |
| 43 | |
| 44 |  |
| 45 | |
| 46 | <Info> |
| 47 | Automatically create local rule blocks: When in Agent mode, you can prompt the agent to create a rule for you using the `create_rule_block` tool if enabled. |
| 48 | |
| 49 | For example, you can say "Create a rule for this", and a rule will be created for you in `.continue/rules` based on your conversation. |
| 50 | </Info> |
| 51 | |
| 52 | Rules can also be added to an Agent on the Continue Hub. |
| 53 | |
| 54 | Explore available rules [here](https://hub.continue.dev), or [create your own](https://hub.continue.dev/new?type=block&blockType=rules) in the Hub. |
| 55 | |
| 56 | ### Syntax |
| 57 | |
| 58 | <Info> |
| 59 | |
| 60 | Rules were originally defined in YAML format (demonstrated below), but we introduced Markdown for easier editing. While both are still supported, we recommend Markdown. |
| 61 | |
| 62 | </Info> |
| 63 | |
| 64 | Rules blocks can be simple text, written in YAML configuration files, or as Markdown (`.md`) files. They can have the following properties: |
| 65 | |
| 66 | - `name` (**required** for YAML): A display name/title for the rule |
| 67 | - `globs` (optional): When files are provided as context that match this glob pattern, the rule will be included. This can be either a single pattern (e.g., `"**/*.{ts,tsx}"`) or an array of patterns (e.g., `["src/**/*.ts", "tests/**/*.ts"]`). |
| 68 | - `regex` (optional): When files are provided as context and their content matches this regex pattern, the rule will be included. This can be either a single pattern (e.g., `"^import .* from '.*';$"`) or an array of patterns (e.g., `["^import .* from '.*';$", "^export .* from '.*';$"]`). |
| 69 | - `description` (optional): A description for the rule. Agents may read this description when `alwaysApply` is false to determine whether the rule should be pulled into context. |
| 70 | - `alwaysApply`: Determines whether the rule is always included. Behavior is described below: |
| 71 | - `true`: Always included, regardless of file context |
| 72 | - `false`: Included if globs exist AND match file context, or the agent decides to pull the rule into context based on it's description |
| 73 | - `undefined` (default behavior): Included if no globs exist OR globs exist and match |
| 74 | |
| 75 | <Tabs> |
| 76 | <Tab title="Markdown"> |
| 77 | ```md title="doc-standards.md" |
| 78 | --- |
| 79 | name: Documentation Standards |
| 80 | globs: docs/**/*.{md,mdx} |
| 81 | alwaysApply: false |
| 82 | description: Standards for writing and maintaining Continue Docs |
| 83 | --- |
| 84 | |
| 85 | # Continue Docs Standards |
| 86 | |
| 87 | - Follow Mintlify documentation standards |
| 88 | - Include YAML frontmatter with title, description, and keywords |
| 89 | - Use consistent heading hierarchy starting with h2 (##) |
| 90 | - Include relevant Admonition components for tips, warnings, and info |
| 91 | - Use descriptive alt text for images |
| 92 | - Include cross-references to related documentation |
| 93 | - Reference other docs with relative paths |
| 94 | - Keep paragraphs concise and scannable |
| 95 | - Use code blocks with appropriate language tags |
| 96 | ``` |
| 97 | </Tab> |
| 98 | <Tab title="YAML"> |
| 99 | |
| 100 | ```yaml title="doc-standards.yaml" |
| 101 | name: Documentation Standards |
| 102 | version: 1.0.0 |
| 103 | schema: v1 |
| 104 | |
| 105 | rules: |
| 106 | - name: Documentation Standards |
| 107 | globs: docs/**/*.{md,mdx} |
| 108 | alwaysApply: false |
| 109 | rule: > |
| 110 | - Follow Mintlify documentation standards |
| 111 | - Include YAML frontmatter with title, description, and keywords |
| 112 | - Use consistent heading hierarchy starting with h2 (##) |
| 113 | - Include relevant Admonition components for tips, warnings, and info |
| 114 | - Use descriptive alt text for images |
| 115 | - Include cross-references to related documentation |
| 116 | - Reference other docs with relative paths |
| 117 | - Keep paragraphs concise and scannable |
| 118 | - Use code blocks with appropriate language tags |
| 119 | ``` |
| 120 | </Tab> |
| 121 | |
| 122 | </Tabs> |
| 123 | |
| 124 | ### `.continue/rules` folder |
| 125 | |
| 126 | You can create project-specific rules by adding a `.continue/rules` folder to the root of your project and adding new rule files. |
| 127 | |
| 128 | ```md title=".continue/rules/new-rule.md" |
| 129 | --- |
| 130 | name: New rule |
| 131 | --- |
| 132 | |
| 133 | Always give concise responses |
| 134 | ``` |
| 135 | |
| 136 | This is also done when selecting "Add Rule" in the Agent settings. This will create a new folder in `.continue/rules` with a default file named `new-rule.md`. |
| 137 | |
| 138 | ### Examples |
| 139 | |
| 140 | If you want concise answers: |
| 141 | |
| 142 | ```md title=".continue/rules/concise-rule.md" |
| 143 | --- |
| 144 | name: Always give concise answers |
| 145 | --- |
| 146 | |
| 147 | Please provide concise answers. Don't explain obvious concepts. |
| 148 | You can assume that I am knowledgable about most programming topics. |
| 149 | ``` |
| 150 | |
| 151 | If you want to ensure certain practices are followed, for example in React: |
| 152 | |
| 153 | ```md title=".continue/rules/functional-rule.md" |
| 154 | --- |
| 155 | name: Always use functional components |
| 156 | --- |
| 157 | |
| 158 | Whenever you are writing React code, make sure to |
| 159 | |
| 160 | - use functional components instead of class components |
| 161 | - use hooks for state management |
| 162 | - define an interface for your component props |
| 163 | - use Tailwind CSS for styling |
| 164 | - modularize components into smaller, reusable pieces |
| 165 | ``` |
| 166 | |
| 167 | ### Chat System Message |
| 168 | |
| 169 | Continue includes a simple default system message for [Agent](../../features/agent/quick-start) and [Chat](../../features/chat/quick-start) requests, to help the model provide reliable codeblock formats in its output. |
| 170 | |
| 171 | This can be viewed in the rules section of the toolbar (see above), or in the source code [here](https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts#L4). |
| 172 | |
| 173 | Advanced users can override this system message for a specific model if needed by using `chatOptions.baseSystemMessage`. See the [`config.yaml` reference](/reference#models). |
| 174 | |
| 175 | ### `.continuerules` |
| 176 | |
| 177 | <Warning> |
| 178 | `.continuerules` will be deprecated in a future release. Please use the `.continue/rules` folder instead. |
| 179 | </Warning> |
| 180 | |
| 181 | You can create project-specific rules by adding a `.continuerules` file to the root of your project. This file is raw text and its full contents will be used as rules. |