Pattern 16: Ruler Context Creation

Building Detailed Preference Documents for Consistent AI Output

Overview

Ruler context creation builds preference documents that teach AI your exact coding style for consistent output.

Why do this?

  • AI output matches your team’s standards
  • Eliminate repetitive corrections
  • Create portable knowledge across tools
  • Invest once, benefit forever

Powerful for teams with specific conventions. Teach preferences upfront, not repeatedly.

Find Ruler at: https://github.com/intellectronica/ruler

Key Principles

  1. Be specific - Code examples, not descriptions
  2. Show contrasts - Good vs bad examples
  3. Cover edges - Document tricky situations
  4. Iterate - Refine based on AI output

Exercise: Build Your Ruler

Create a ruler context for your project.

Steps:

  1. Gather examples: Collect code exemplifying your style. Include good and bad. Cover scenarios.

  2. Structure: Organize sections - naming, structure, errors, testing, docs, architecture.

  3. Test: Use with AI. Note mismatches. Add rules to fix gaps.

Your Turn

Pick your own project!

Examples:

  • Team ruler: linting rules, component structure, API conventions
  • Personal ruler: your language flavor (“Functional TypeScript, no classes” or “Python with strict types”)