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 %} {% /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 %} {% /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 %} {% /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 %} {% /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 %} {% /tabs %}