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 constraintsKilo Code supports two types of custom rules:
:::note UI Support The built-in rules management UI is available for general rules only. Mode-specific rules must be managed through the file system. :::
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
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 icon in the bottom right corner of the Kilo Code window.
You can access the rules management UI to:
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.
:::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 folder-based structure allows for more granular rule organization and clearer separation of concerns. The legacy file-based approach is maintained for backward compatibility but may be subject to change in future releases.
:::
Additionally, the system supports mode-specific rules, which are loaded separately and have their own priority order:
.kilocode/rules-${mode}/ directory.kilocoderules-${mode} file (deprecated)Currently, mode-specific rules are only supported at the project level. When both generic rules and mode-specific rules exist, the mode-specific rules are given priority in the final output.

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.
# 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.

Custom rules can be applied to a wide variety of scenarios:
:::tip Pro Tip: File-Based Team Standards
When working in team environments, placing .kilocode/rules/codestyle.md files under version control allows you to standardize Kilo's behavior across your entire development team. This ensures consistent code style, documentation practices, and development workflows for everyone on the project.
:::
If your custom rules aren't being properly followed:
~/.kilocode/rules/ directory.kilocode/rules/ directory.kilocoderules, .roorules, or .clinerules