AI Rules
What Are AI Rules?
When you add an AI coding tool such as Claude or Copilot to your project, you need a way of defining the rules and guidelines that the AI should follow when working within your codebase. These rules help ensure that the AI produces code that aligns with your project's standards and requirements.
The rules you define are typically the standards and best practices that your team already follows: coding conventions, architectural patterns, testing requirements, and documentation standards.
Each tool calls the rules something slightly different:
- In Claude, they are called rules and are typically stored in the
.claude/rulesfolder of your repository. - In GitHub Copilot, they are called instructions and are typically stored in files such as
.copilot/copilot-instructions.mdor in the.github/instructionsfolder.
Claude Rules
When defining Claude rules files, you use YAML frontmatter to specify metadata about the rules. Here is an example of a Claude rules file:
---
applyTo: "**/*.css,**/*.tsx,**/*.jsx"
---
This will make sure that the rules defined in this file are only applied to CSS, TSX, and JSX files in your repository.
Copilot Instructions
GitHub Copilot instructions files use a similar YAML frontmatter approach. Here is an example:
---
paths:
- "**/*.css"
- "**/*.tsx"
- "**/*.jsx"
---
This will make sure that the instructions defined in this file are only applied to CSS, TSX, and JSX files in your repository.
What To Include In Your AI Rules
When creating your AI rules or instructions files, consider including the following types of information:
- Coding Standards: Define the coding conventions and best practices that the AI should follow.
- Architectural Guidelines: Specify the architectural patterns and design principles that should be adhered to.
- Testing Requirements: Outline the testing frameworks and coverage requirements for the code.
- Documentation Standards: Provide guidelines for documenting code, including comments and README files.
- Performance Considerations: Highlight any performance-related guidelines that should be taken into account.
- Security Practices: Include any security best practices that should be followed when writing code.