packages/kilo-docs/pages/customize/custom-rules.md
Custom rules provide a powerful way to define project-specific and global behaviors and constraints for the Kilo Code AI agent. With custom rules, you can ensure consistent formatting, restrict access to sensitive files, enforce coding standards, and customize the AI's behavior for your specific project needs or across all projects.
Custom rules allow you to create text-based instructions that all AI models will follow when interacting with your project. These rules act as guardrails and conventions that are consistently respected across all interactions with your codebase. Rules can be managed through both the file system and the built-in UI interface.
Custom rules can be written in plain text, but Markdown format is recommended for better structure and comprehension by the AI models. The structured nature of Markdown helps the models parse and understand your rules more effectively.
#, ##, etc.) to define rule categories-, *) to enumerate specific items or constraints ) to include code examples when neededKilo Code supports two types of custom rules:
{% tabs %} {% tab label="VSCode" %}
Project rules are configured via the instructions key in your project's kilo.jsonc file. You can edit this file directly or use the Settings webview to manage the instructions configuration. Each entry points to a file path or glob pattern:
// kilo.jsonc
{
"instructions": [".kilo/rules/formatting.md", ".kilo/rules/*.md"],
}
You can also place rule files in the .kilo/ directory structure:
project/
├── .kilo/
│ ├── rules/
│ │ ├── formatting.md
│ │ ├── restricted_files.md
│ │ └── naming_conventions.md
├── kilo.json
├── src/
└── ...
Global rules are configured via the instructions key in your global kilo.jsonc config file (typically at ~/.config/kilo/kilo.jsonc).
{% callout type="note" title="Migration" %}
The extension is backward compatible with .kilocode/rules/ directories. Existing rules will continue to work, but migrating to kilo.jsonc is recommended.
{% /callout %}
{% /tab %} {% tab label="CLI" %}
Project rules are configured via the instructions key in your project's kilo.jsonc file. Each entry points to a file path or glob pattern:
// kilo.jsonc
{
"instructions": [".kilo/rules/formatting.md", ".kilo/rules/*.md"],
}
You can also place rule files in the .kilo/ directory structure:
project/
├── .kilo/
│ ├── rules/
│ │ ├── formatting.md
│ │ ├── restricted_files.md
│ │ └── naming_conventions.md
├── kilo.json
├── src/
└── ...
Global rules are configured via the instructions key in your global kilo.jsonc config file (typically at ~/.config/kilo/kilo.jsonc).
{% callout type="note" title="Migration" %}
The CLI is backward compatible with .kilocode/rules/ directories. Existing rules will continue to work, but migrating to kilo.jsonc is recommended.
{% /callout %}
{% /tab %} {% tab label="VSCode (Legacy)" %}
Custom rules are primarily loaded from the .kilocode/rules/ directory. This is the recommended approach for organizing your project-specific rules. Each rule is typically placed in its own Markdown file with a descriptive name:
project/
├── .kilocode/
│ ├── rules/
│ │ ├── formatting.md
│ │ ├── restricted_files.md
│ │ └── naming_conventions.md
├── src/
└── ...
Global rules are stored in your home directory and apply to all projects:
~/.kilocode/
├── rules/
│ ├── coding_standards.md
│ ├── security_guidelines.md
│ └── documentation_style.md
{% /tab %} {% /tabs %}
{% tabs %} {% tab label="VSCode" %}
Rules are managed by editing the instructions array in your kilo.jsonc config file. You can also use the Settings webview in VS Code to edit the configuration.
instructions arraykilo.jsonc (JSONC supports // comments)// kilo.jsonc
{
"instructions": [
".kilo/rules/formatting.md",
// ".kilo/rules/experimental.md" -- temporarily disabled
".kilo/rules/naming_conventions.md",
],
}
{% /tab %} {% tab label="CLI" %}
Rules are managed by editing the instructions array in your kilo.jsonc config file directly.
instructions arraykilo.jsonc (JSONC supports // comments)// kilo.jsonc
{
"instructions": [
".kilo/rules/formatting.md",
// ".kilo/rules/experimental.md" -- temporarily disabled
".kilo/rules/naming_conventions.md",
],
}
{% /tab %} {% tab label="VSCode (Legacy)" %}
Kilo Code provides a built-in interface for managing your custom rules without manually editing files in the .kilocode/rules/ directories. To access the UI, click on the <Codicon name="law" /> icon in the bottom right corner of the Kilo Code window.
You can access the rules management UI to:
{% callout type="note" title="UI Support" %} The built-in rules management UI is available for general rules only. Mode-specific rules must be managed through the file system. {% /callout %}
{% /tab %} {% /tabs %}
{% tabs %} {% tab label="VSCode" %}
Rules are loaded in the order they appear in the instructions array in kilo.jsonc:
kilo.jsonc configkilo.jsoncFiles matched by glob patterns are loaded in filesystem order. Project-level instructions take precedence over global instructions for conflicting directives.
{% callout type="note" title="Backward Compatibility" %}
If .kilocode/rules/ directories exist in your project, their contents are automatically included for backward compatibility. To fully migrate, move your rule files and reference them in kilo.jsonc.
{% /callout %}
{% /tab %} {% tab label="CLI" %}
Rules are loaded in the order they appear in the instructions array in kilo.jsonc:
kilo.jsonc configkilo.jsoncFiles matched by glob patterns are loaded in filesystem order. Project-level instructions take precedence over global instructions for conflicting directives.
{% callout type="note" title="Backward Compatibility" %}
If .kilocode/rules/ directories exist in your project, their contents are automatically included for backward compatibility. To fully migrate, move your rule files and reference them in kilo.jsonc.
{% /callout %}
{% /tab %} {% tab label="VSCode (Legacy)" %}
Rules are loaded in the following priority order:
~/.kilocode/rules/ directory.kilocode/rules/ directory.roorules.clinerules.kilocoderules (deprecated)When both global and project rules exist, they are combined with project rules taking precedence over global rules for conflicting directives.
{% callout type="note" %}
We strongly recommend keeping your rules in the .kilocode/rules/ folder as it provides better organization and is the preferred approach for future versions. The legacy file-based approach is maintained for backward compatibility but may be subject to change in future releases.
{% /callout %}
The system also supports mode-specific rules with their own priority order:
.kilocode/rules-${mode}/ directory.kilocoderules-${mode} file (deprecated)Mode-specific rules are only supported at the project level. When both generic and mode-specific rules exist, mode-specific rules take priority.
{% /tab %} {% /tabs %}
{% tabs %} {% tab label="VSCode" %}
kilo.jsonc file in your project root (if it doesn't exist).kilo/rules/ directory (or any directory you prefer)instructions array in kilo.jsonc// kilo.jsonc
{
"instructions": [".kilo/rules/my-new-rule.md"],
}
Rules are applied on the next interaction. You can also edit kilo.jsonc through the Settings webview in VS Code.
{% /tab %} {% tab label="CLI" %}
kilo.jsonc file in your project root (if it doesn't exist).kilo/rules/ directory (or any directory you prefer)instructions array in kilo.jsonc// kilo.jsonc
{
"instructions": [".kilo/rules/my-new-rule.md"],
}
Rules are applied on the next interaction.
{% /tab %} {% tab label="VSCode (Legacy)" %}
{% image src="/docs/img/custom-rules/rules-ui.png" alt="Rules tab in Kilo Code" width="400" /%}
The easiest way to create and manage rules is through the built-in UI:
To create rules manually:
For Project Rules:
.kilocode/rules/ directory if it doesn't already existFor Global Rules:
~/.kilocode/rules/ directory if it doesn't already existRules will be automatically applied to all future Kilo Code interactions. Any new changes will be applied immediately.
{% /tab %} {% /tabs %}
# Tables
When printing tables, always add an exclamation mark to each column header
This simple rule instructs the AI to add exclamation marks to all table column headers when generating tables in your project.
# Restricted files
Files in the list contain sensitive data, they MUST NOT be read
- supersecrets.txt
- credentials.json
- .env
This rule prevents the AI from reading or accessing sensitive files, even if explicitly requested to do so.
{% image src="/docs/img/custom-rules/custom-rules.png" alt="Kilo Code ignores request to read sensitive file" width="600" /%}
Custom rules can be applied to a wide variety of scenarios:
{% tabs %} {% tab label="VSCode" %}
If your rules aren't being followed:
instructions array in your config to ensure the file path is correct.{% /tab %} {% tab label="CLI" %}
If your rules aren't being followed:
instructions array in your config to ensure the file path is correct.{% /tab %} {% tab label="VSCode (Legacy)" %}
If your custom rules aren't being properly followed:
~/.kilocode/rules/ directory.kilocode/rules/ directory.kilocoderules, .roorules, or .clinerules{% /tab %} {% /tabs %}