Builder rules
Builder Code
Learn how to improve code output with custom configuration files. These files instruct the AI on how to generate code.
What to know
- Add rule files with an
.mdcextension to a.builder/rules/directory. These files should provide explicit instructions to the AI. - Create and update a single
.builderrulesfile to the root of your project using Settings & Instructions in the settings menu at the bottom of the prompt field.
Builder rules overview
AI doesn't retain memory between sessions. Rules provide persistent and reusable context.
To create a rules file for Builder's AI:
- Create a
.builder/directory within the root of your project. - Within the
.builder/directory, create arules/directory. - Create a
component-structure.mdcfile within therules/directory. Provide the metadata as shown below.
In the rules file above, specific instructions are provided to the AI about the component structure.
The following options are available as keys within the metadata header:
- description: a brief description of what the rules cover. Required for rules where
alwaysApplyis nottrue - globs: glob patterns for the files these rules apply to
- alwaysApply: if set to
true, the AI always applies these rules; otherwise, the AI decides when to apply them based on thedescription, or when a file matchingglobsis read
Builder's AI will not make any changes to your rule files.
.builderrules
Builder currently supports .builderrules files as well.
All instructions can be placed in a .builderrules file and will be read by Builder's AI. Consider adding structured headings to improve the readability of this file.
These files can be placed in any directory, and Builder will recursively search through your project to join each file. Files closer to the current working directory take precedence over files in parent directories.
This allows you to have project-wide rules in the root directory and more specific rules in subdirectories.
For more details, visit Project-level settings.
Custom instructions
Create or update the root .builderrules file within Builder's Visual Editor by doing the following:
- Click the cog icon at the bottom of the prompt field, then choose Settings & Instructions.
- Enter rules you want the AI to follow when generating code.
- Click the Save button.
If you have an existing chat, clear the chat for the changes to take effect.
This button provides easy access to the root .builderrules file. Keep in mind that changing the contents within this panel changes the file.
Builder rules best practices
Rules should be actionable, focused, precise, and scoped.
- Keep rules under 500 lines.
- Split large rules into multiple, composable rules.
- Provide concrete examples or referenced files.
- Avoid vague guidance. Write rules like clear internal docs.
- Ensure rules in one file do not conflict with rules in another file.
Complete Builder rules examples
Full .builderrules examples are included below.
A file like this should be placed in the root directory of your application.
A file like this should be in your components/ directory.
Place a file like this within a directory where you manage your routes or pages.
Place a file like this where you store the styles for your application.
What's next
Learn more about Configuration files in Builder, or read up on AI instruction best practices.