Extending Kilo Code AI with Custom Rules
Custom rules are a powerful advanced feature in the Kilo Code VS Code extension that can take your coding productivity to the next level. While Kilo Code already excels at understanding and generating code, custom rules let you tailor its behavior specifically to your project's needs.
What Are Custom Rules?
Custom rules are text descriptions that guide how Kilo Code's AI models behave when interacting with your project. Think of rules as a way to establish project-specific conventions or guardrails that all models will consistently respect when working with your codebase.
While they can be written in plain text, Markdown format is preferred as it makes use of headers and lists to provide structure that language models can easily understand and follow. The structured nature of Markdown helps the AI parse and comprehend your rules more effectively, but don't worry if you prefer plain text — the models are designed to understand your instructions either way.
Getting Started with Custom Rules
Creating your first rule is straightforward. Rules are stored in the .kilocode/rules/
directory within your project, with each rule typically placed in its own file.
Let's walk through a simple example to see custom rules in action:
Example 1: Table Formatting Rule
Create a file at
.kilocode/rules/table.md
Add the following content:
# Tables
When printing tables, always add an exclamation mark to each column header
Now execute a request: "Create a table.txt file, write a table, three rows, poets with birthdates there"
You'll notice that the generated table has exclamation marks added to each column header, exactly as specified in your rule! While this example is admittedly quite simple, it demonstrates how the AI follows your custom instructions.
Practical Applications
Let's explore a more useful example that showcases the real power of custom rules:
Example 2: Restricting Access to Sensitive Files
Create a file named supersecret.txt with some confidential information
Create a rule file at
.kilocode/rules/restricted.md
Add the following content:
# Restricted files
Files in the list contain sensitive data, they MUST NOT be read
- supersecrets.txt
Now try running: "Open the file supersecrets.txt and print its content"
The AI agent will politely decline this request, protecting your sensitive data from accidental exposure! This demonstrates how custom rules can be used to implement security policies within your project.
Real-World Uses for Custom Rules
Custom rules can serve many practical purposes in your development workflow:
Coding Standards: Enforce project-specific coding conventions
Security Controls: Prevent access to sensitive files or directories
Documentation Requirements: Specify how comments and documentation should be formatted
Testing Patterns: Define expectations for how tests should be written
Project Structure: Guide the AI on where different types of files should be placed
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!
Final Thoughts
Custom rules represent one of the most powerful yet underutilized features of Kilo Code. They allow you to extend the capabilities of the AI to match your specific project needs and workflows.
The beauty of this feature lies in its simplicity – just plain text descriptions in Markdown – combined with the intelligence of the underlying models that can understand and apply these instructions consistently.
How would you use custom rules in your projects? What specific behaviours would you want to enforce? Drop your ideas in the comments below!