Tutorials

How to Organize Large Rule Files

When your rule file grows past 50 rules, organization becomes critical. This tutorial covers section hierarchy, progressive disclosure, and the structural patterns that keep large rule files navigable.

5 min read·July 5, 2025

50 rules in a flat list: unreadable. 50 rules in a hierarchy with progressive disclosure: scannable in 3 minutes.

Section hierarchy, priority ordering, progressive disclosure, linked references, and quarterly structural cleanup

When Rule Files Grow Too Large

Rule files grow naturally: you start with 15 rules, add 3 per month based on code review feedback, and after a year: 50+ rules. The problems that emerge: developers stop reading the file (too long to scan), the AI may deprioritize rules at the end of a very long file (context window effects), rules in different sections contradict each other (nobody checked for conflicts when adding to a large file), and maintaining the file becomes a chore (nobody wants to edit a 200-line markdown file).

The organization challenge: 50 rules in a flat list (one rule after another with no grouping) is unreadable. 50 rules in a well-organized hierarchy (grouped by category, prioritized by importance, with clear headings) is navigable. The same content: usable or unusable depending on organization. Good organization: does not change what the rules say. It changes whether anyone (human or AI) can effectively process them.

The target: a rule file that a developer can scan in 3 minutes to understand the major conventions, that the AI processes effectively (most important rules receive the most attention), and that is easy to maintain (adding a rule = finding the right section and adding a bullet point). Organization: achieves all three goals.

Step 1: Section Hierarchy (5 Minutes to Restructure)

The recommended hierarchy: ## Project Context (what the project is, tech stack, architecture — read by the AI for every prompt), ## Critical Rules (security, data handling, authentication — never violate), ## Coding Conventions (naming, patterns, error handling — the most-referenced rules), ## Testing Standards (framework, naming, coverage — referenced when generating tests), ## Framework Patterns (Next.js/NestJS/FastAPI specifics — referenced for framework-specific code), and ## Project-Specific (domain terminology, API patterns, integration details — team-unique conventions).

Priority ordering within sections: put the most important rules first in each section. The AI: processes earlier content with slightly more emphasis (due to context position effects in long files). Security rules: first within Critical Rules. Naming conventions: first within Coding Conventions. The most frequently referenced rule: first in its section. AI rule: 'Within each section: most important first. The AI reads the file top to bottom. Earlier rules: slightly more emphasis in long files.'

Section sizes: no section should have more than 15 rules. If a section exceeds 15: split into subsections. Example: ## Coding Conventions with subsections ### Naming, ### Error Handling, ### Imports, ### Async Patterns. The subsections: make scanning easier and help the developer find the specific rule they want to update. AI rule: 'Max 15 rules per section. Split large sections into subsections. Each subsection: a coherent group of related rules.'

💡 Most Important Rules First — In the File and In Each Section

Context position effects: in very long files, the AI gives slightly more weight to content near the beginning. Security rules (must never be violated): should be the first section after project context. Within each section: the most-referenced rule first. This is not about manipulating the AI — it is about good document design. The most important information: first. The same principle: applies to any reference document, not just AI rules.

Step 2: Progressive Disclosure

Progressive disclosure: the rule file provides increasing detail as the reader goes deeper. Level 1 (headings only): the developer scans the headings in 30 seconds and understands the rule categories. Level 2 (first rule per section): the developer reads the first rule in each section in 2 minutes and understands the key conventions. Level 3 (full file): the developer reads the complete file in 5-10 minutes and understands all rules. The AI: reads all levels automatically.

Implementation: each section starts with the most general, most important rule (the summary rule). Subsequent rules: add detail and specificity. Example: Section header: ## Error Handling. First rule (summary): 'Use the Result<T, E> pattern for all business logic. Never throw in service or repository layers.' Subsequent rules (detail): 'Result type: import from @/lib/result. Success: Result.ok(data). Failure: Result.err(new AppError(code, message)).' The summary rule: sufficient for 80% of situations. The detail rules: needed for the 20% that requires specificity.

The 'Read More' pattern: for rules that need extensive explanation (code examples, edge cases, rationale), keep the rule itself short in the main file. Link to a detailed reference: 'Error handling: use the Result pattern. See: docs/error-handling.md for examples and edge cases.' The AI: reads the short rule in the main file (sufficient for most code generation). The developer: clicks the link when they need more detail. This keeps the main file concise while providing depth when needed. AI rule: 'Short rules in the main file. Long explanations in linked documents. The main file: a concise reference. Linked docs: the detailed guide.'

⚠️ 50 Rules in a Flat List = Nobody Reads It

A rule file with 50 bullet points and no headings: the developer opens it, sees a wall of text, and closes it. They never read the rules. The AI: processes all 50 rules, but with no structural signal about priority or grouping. With sections and subsections: the developer scans the headings in 30 seconds, finds the relevant section in 10 seconds, and reads the specific rule they need. Same content. Dramatically different usability.

Step 3: Maintenance Patterns for Large Files

Table of contents: for files with 5+ sections, add a table of contents at the top. Markdown: links to each section heading. The developer: clicks to jump to the section they need. The AI: uses the TOC to understand the file's structure. Example: '## Table of Contents\n- [Critical Rules](#critical-rules)\n- [Coding Conventions](#coding-conventions)\n- [Testing Standards](#testing-standards)\n...' AI rule: 'Add a TOC when the file exceeds 5 sections. The TOC: navigational aid for humans, structural signal for the AI.'

Rule IDs for tracking: for organizations that track rules formally, assign IDs. Format: SEC-01 (security rule 1), COD-05 (coding convention 5), TST-03 (testing rule 3). The ID: enables referencing specific rules in reviews ('This violates SEC-01'), tracking overrides per rule, and mapping rules to compliance controls. AI rule: 'Rule IDs: optional for small teams. Valuable for organizations with 50+ rules that need to track overrides, compliance, and effectiveness per rule.'

Quarterly cleanup: during the quarterly rule review, also clean up the organization. Questions: are sections balanced (no section has 30 rules while another has 2)? Are rules in the correct sections (a testing rule in the error handling section)? Are deprecated rules removed (not just marked as deprecated)? Is the priority ordering current (the most important rules are still first)? The organizational cleanup: 15 minutes during the quarterly review. Prevents structural decay. AI rule: 'Organizational cleanup during quarterly review. 15 minutes to maintain structure. Without it: the file slowly becomes an unsorted list regardless of how well it was originally organized.'

ℹ️ Short Rules in the Main File, Long Explanations in Linked Docs

Rule in CLAUDE.md: 'Error handling: use Result<T, E> pattern. Never throw in business logic. See docs/error-handling.md for examples.' The main file: concise, scannable, under 3,000 words. The linked doc: detailed, with code examples, edge cases, and rationale. The AI: reads the concise rule (sufficient for 80% of code generation). The developer: clicks the link when they encounter an edge case. This pattern: keeps the main file lean while providing unlimited depth.

Large Rule File Organization Summary

Summary of organizing large AI rule files.

  • Hierarchy: Project Context → Critical Rules → Conventions → Testing → Framework → Project-Specific
  • Priority: most important rules first in each section. Security before naming. Core before edge cases
  • Section size: max 15 rules per section. Split into subsections if larger
  • Progressive disclosure: headings (30 sec) → first rules (2 min) → full file (5-10 min)
  • Summary rules: first rule in each section is the general principle. Details follow
  • Read More: short rules in main file, long explanations in linked docs
  • Table of contents: for 5+ sections. Navigation for humans, structure signal for AI
  • Rule IDs: optional. SEC-01, COD-05 format. Enables tracking, referencing, and compliance mapping