Custom rules
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
- This feature uses GitLab Credits.
You can use custom rules in the GitLab Duo Agent Platform to ensure that generated output (for example, code or documentation) aligns with your specific instructions, or any other requirements such as development style guides.
The following Agent Platform features support custom rules:
Create custom rules
You can create custom rules at two levels:
- User-level rules: Apply to all of your projects and workspaces.
- Workspace-level rules: Apply only to a specific project or workspace.
If both user-level and workspace-level rules exist, GitLab Duo Chat applies both to conversations.
Prerequisites:
- Meet the Agent Platform prerequisites.
- For VS Code, install and configure the GitLab Workflow extension for VS Code version 6.32.2 or later.
- For a JetBrains IDE, install and configure the GitLab plugin for JetBrains version 3.12.2 or later.
- For Visual Studio, install and configure the GitLab extension for Visual Studio version 0.60.0 or later.
Conversations that existed before you created any custom rules do not follow those rules.
Create user-level custom rules
User-level custom rules apply to all of your projects and workspaces in your local environment (IDE).
Create a custom rules file in your home directory:
- On Linux or macOS, create the file at
~/.gitlab/duo/chat-rules.md. - On Windows, create the file at
%APPDATA%\GitLab\duo\chat-rules.md.
- On Linux or macOS, create the file at
Add custom rules to the file. For example:
- Don't put comments in the generated code - Be brief in your explanations - Always use single quotes for JavaScript stringsSave the file.
To apply the new custom rules, do any of the following as appropriate:
- Start a new GitLab Duo Chat conversation.
- Use an agent in a Chat conversation, discussion, issue, or merge request.
- Trigger a flow.
If you have set a specific environment variable, then you create the custom rules file in a different location:
- If you have set the
GLAB_CONFIG_DIRenvironment variable, create the file at$GLAB_CONFIG_DIR/chat-rules.md. - If you have set the
XDG_CONFIG_HOMEenvironment variable, create the file at$XDG_CONFIG_HOME/gitlab/duo/chat-rules.md.
Create workspace-level custom rules
Workspace-level custom rules apply only to a specific project or workspace. You can use this method to apply a set of custom rules to the project for your team. For example, you can apply a set of development style guides that your team uses.
In your IDE workspace, create a custom rules file:
.gitlab/duo/chat-rules.md.Add custom rules to the file. For example:
- Don't put comments in the generated code - Be brief in your explanations - Always use single quotes for JavaScript stringsSave the file.
For a project: Add the
.gitlab/duo/chat-rules.mdfile to the Git repository. Agentic Chat, agents, and flows then automatically read the custom rules from the repository into context.To apply the new custom rules, start a new GitLab Duo conversation.
You must do this every time you change the custom rules.
For more information, see the Custom rules in GitLab Duo Agentic Chat tutorial blog.
Update custom rules
To update your custom rules, edit and save the custom rules file. Then, start a new GitLab Duo conversation to apply the updated rules.
You cannot use Chat to edit your custom rules file directly.
To manage who must approve any changes to custom rules, use Code Owners.