How to use Kody Rules
You can use Kody Rules in two ways:Create Custom Rules
Define rules based on your team’s exact needs. Kody Rules can be applied at two different levels: File-Level and Pull Request-Level. Both levels support variables, file references, and MCP functions to build powerful, context-aware rules.Variables, File References & MCP Functions
Rules can access rich context through variables, file references, and MCP functions. Here’s what’s available: Variables: Variables represent the context data available during rule execution. Understanding what’s available helps you compose better rules by combining variables with MCP functions and file references.- File-Level:
fileDiff- The specific changes made to the individual file being analyzed
- PR-Level:
pr_title- The title of the Pull Requestpr_description- The description/body of the Pull Requestpr_total_additions- Total number of lines addedpr_total_deletions- Total number of lines deletedpr_total_files- Total number of files changedpr_total_lines_changed- Total number of lines modifiedpr_files_diff- Complete diff of all changes across the entire Pull Requestpr_tags- Tags associated with the Pull Requestpr_author- Author of the Pull Requestpr_number- Pull Request number
@file:path/to/file.ts- Reference files in the same repository where you’re editing the rule- Use when referencing templates, examples, or configuration files within your current repository
- Example:
@file:src/services/userService.ts
@repo:org/project- Reference files in another repository or when configuring rules outside a repo context- Use when enforcing consistency across multiple repositories or referencing shared standards
- Example:
@repo:team/api-standards
- Kody identifies file references automatically when you save a rule
- References are resolved in the background—watch the status indicator next to the editor to confirm completion
- Use accurate blob-style paths (e.g.,
src/utils/helpers.ts) instead of placeholders - File contents are injected into the rule context, allowing Kody to compare, validate, or enforce patterns
- Works in both File-Level and Pull Request-Level rules
@MCP dropdown in the rule editor to fetch additional data and context. You can use any MCP tool or server connected in your workspace’s Plugins page.
Available functions include:
- Repository operations: List repositories, get repository files, content, and languages
- PR analysis: Get pull request details, list commits, analyze PR file content
- File content retrieval: Fetch file contents and diffs
- Cross-file validation: Perform advanced analysis across multiple files
- Custom integrations: Any MCP server you’ve connected as a plugin (Jira, custom tools, etc.)
- Use specific file paths rather than generic placeholders
- Reference stable files that represent your team’s standards
- Test file references exist before saving rules to avoid resolution errors
- Combine variables, file references, and MCP functions for comprehensive validation
File-Level Rules
Analyze individual files to catch issues within specific code files. Available Context: See the Variables, File References & MCP Functions section above for details. Available at this level:fileDiff variable, file references (@file, @repo), and MCP functions.
What You Can Do:
- Compare against reference files using
@fileor@repo - Fetch related files or repository data using MCP functions
- Combine variables, file references, and MCP functions to validate patterns, check consistency, or enforce architectural rules
- Rule name: Clearly define the rule purpose
- File Paths: Limit rules to specific files or directories using glob patterns
- Severity: Set to Critical, High, Medium, or Low
- Detailed Instructions: Use
fileDiff, reference files with@file/@repo, and call MCP functions to compose powerful rules with rich context
src/**/*.ts
⚠️ Severity: Critical
📝 Instructions: “Using equality operators (== or !=) can cause infinite loops if exact values aren’t matched.”
❌ Bad Example:
Pull Request-Level Rules
Analyze the entire Pull Request for cross-file validation and PR-specific requirements. Available Context: See the Variables, File References & MCP Functions section above for details. Available at this level: PR variables (pr_title, pr_description, pr_files_diff, etc.), file references (@file, @repo), and MCP functions.
What You Can Do:
- Validate PR metadata using variables like
pr_title,pr_description,pr_author - Reference configuration files or templates using
@fileor@repo - Fetch additional context using MCP functions (e.g., check if related files exist, validate against repository structure)
- Combine PR variables, file references, and MCP functions to create comprehensive validation rules
- Every service file must have a corresponding test file
- PR description must be complete, clearly stating what was added or removed
- When a new route is created in a controller, it must be registered in routes.json
- Use
pr_total_lines_changedto flag PRs exceeding size limits - Combine
pr_files_diffwith MCP functions to validate cross-file dependencies - Reference
@file:routes.jsonto ensure new routes are registered - Use MCP functions to check if test files exist for modified service files
Composing Powerful Rules
Combine variables, MCP functions, and file references to create sophisticated rules with rich context. Here’s what’s available at each level: File-Level Composition:- Use
fileDiffto analyze the specific changes in a file - Reference related files with
@file:path/to/template.tsto compare against patterns - Call MCP functions to fetch repository data or check if related files exist
- Example: “Analyze
fileDiffand ensure it follows the pattern in@file:src/utils/example.ts. Use MCP to verify related test files exist.”
- Use PR variables (
pr_title,pr_description,pr_files_diff, etc.) to validate PR metadata and size - Reference configuration files with
@file:config.jsonor@repo:org/shared-configto enforce consistency - Call MCP functions to perform cross-file validation, check repository structure, or fetch commit history
- Example: “If
pr_files_diffcontains new routes, verify they’re registered in@file:routes.json. Use MCP to check if corresponding test files exist for all modified service files.”
- Reference files from other repositories with
@repo:org/projectto maintain consistency across projects - Combine with MCP functions to validate against shared standards or templates
- Example: “Ensure API endpoints follow the pattern defined in
@repo:org/api-standards. Use MCP to fetch the latest standards document.”
- MCP functions execute during rule evaluation, enabling rules that adapt to current repository state
- Fetch real-time data about files, commits, or repository structure
- Example: “Use MCP to check the current repository structure and ensure new files follow the existing directory patterns.”
Import from Rules Library
Leverage proven best practices instantly:- Navigate to Discovery Rules in your Kodus dashboard.
- Filter rules by severity, language, or tags.
- Import and activate rules with a single click.
- Security: “Disallow use of insecure MD5 hashing.”
- Maintainability: “Limit React components to less than 150 lines.”