Ruler
Transform rules into LLM-ready markdown for AI coding assistants
Ruler transforms your project's conventions and rules into LLM-ready markdown, ensuring AI coding assistants never hallucinate on your codebase's conventions.
Ruler automatically converts your project rules and conventions into markdown files that AI coding assistants (like Cursor, Claude, etc.) can read and follow.
What is Ruler?
Ruler scans your codebase for:
- Rule files (
.cursor/rules/) - Project conventions
- Documentation patterns
It then transforms these into properly formatted markdown that AI assistants can understand and apply.
Configuration
Ruler is configured in .ruler/ruler.toml:
# Ruler Configuration File
# See https://okigu.com/ruler for documentation.
# Default agents to run when --agents is not specified
default_agents = ["amp", "claude", "codex", "cursor", "windsurf", "cline", "gemini-cli", "opencode", "zed", "qwen"]
# --- Global MCP Server Configuration ---
[mcp]
# Enable/disable MCP propagation globally (default: true)
enabled = true
# Global merge strategy: 'merge' or 'overwrite' (default: 'merge')
merge_strategy = "merge"
# --- MCP Server Definitions ---
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
[mcp_servers.convex]
command = "npx"
args = ["-y", "convex@latest", "mcp", "start"]
[mcp_servers.shadcn]
command = "npx"
args = ["shadcn@latest", "mcp"]
[mcp_servers.better-auth]
url = "https://mcp.chonkie.ai/better-auth/better-auth-builder/mcp"
# --- Global .gitignore Configuration ---
[gitignore]
# Enable/disable automatic .gitignore updates (default: true)
enabled = trueRule Files Location
Your project rules are stored in .cursor/rules/:
ultracite.mdc: Ultracite formatting and linting rulesconvex_rules.mdc: Convex-specific best practicestanstack-start.mdc: TanStack Start patternscli-tools.mdc: Modern CLI tool preferencesruler_cursor_instructions.mdc: General coding conventions
Usage
Apply Rules to AI Assistants
Update rules for all configured AI assistants:
bun run ruler:applyThis command:
- Scans
.cursor/rules/for rule files - Converts them to LLM-ready markdown
- Applies them to configured AI assistants (Cursor, Claude, etc.)
Applying to Specific Agents
You can target specific AI assistants:
bunx @intellectronica/ruler@latest apply --agents cursor,claudeAvailable agents:
cursor- Cursor IDEclaude- Claude Desktopwindsurf- Windsurf IDEcodex- Codexamp- Ampcline- Clinegemini-cli- Google Gemini CLIopencode- OpenCodezed- Zed Editorqwen- Qwen
How It Works
- Rule Discovery: Ruler scans
.cursor/rules/for.mdcfiles - Transformation: Converts markdown to LLM-optimized format
- Application: Writes rules to agent-specific locations
- MCP Integration: Optionally propagates rules via MCP servers
Creating Custom Rules
Add new rule files to .cursor/rules/:
---
description: Your rule description
globs: "**/*.{ts,tsx}"
alwaysApply: false
---
Your rules here...
## Rule Category
- Rule 1
- Rule 2Rule File Frontmatter
description: Brief description of the rulesglobs: File patterns these rules apply toalwaysApply: Whether rules should always be active
MCP Server Integration
Ruler can configure MCP (Model Context Protocol) servers for AI assistants:
- Context7: Up-to-date library documentation
- Convex: Convex backend helpers
- Shadcn: Component library helpers
- Better Auth: Authentication helpers
These are configured in .ruler/ruler.toml and automatically propagated to AI assistants.
Benefits
For Developers
- Consistency: All AI assistants follow the same rules
- Automation: Rules are applied automatically
- Maintenance: Update rules in one place
For AI Assistants
- Context: Understands your project conventions
- Accuracy: Generates code matching your style
- Learning: Learns from your documented patterns
Common Workflows
Adding a New Convention
-
Create a rule file in
.cursor/rules/:echo "---\ndescription: My new rules\nglobs: '**/*.ts'\n---\n\n- Use const for immutable values" > .cursor/rules/my-rules.mdc -
Apply rules:
bun run ruler:apply
Updating Existing Rules
- Edit rule files in
.cursor/rules/ - Run
bun run ruler:applyto propagate changes