Hierarchical Rule Files with Collocation: Context at the Point of Need

James Phoenix
James Phoenix

Summary

Global rules can’t capture domain-specific constraints, forcing developers to mentally context-switch and LLMs to hallucinate patterns. The hierarchical rule files pattern collocates documentation and configuration files (CLAUDE.md, ESLint configs, learning files) as close as possible to the code they govern. This creates semantic locality where context lives at the point of need, reducing cognitive load and improving LLM code generation accuracy.

The Problem

Monolithic root-level rule files (CLAUDE.md, .eslintrc) don’t scale to large codebases with multiple domains. Global rules miss domain-specific constraints (API patterns vs database migrations vs UI components), forcing developers to remember context and LLMs to guess patterns. When context is far from code, it becomes stale, unused, and eventually wrong. Teams waste time searching for relevant documentation across scattered files.

The Solution

Apply the collocation principle: ‘Rules should live as close as possible to the code they govern.’ Create a hierarchy of rule files that mirror your codebase structure. Root files contain architecture and global principles. Domain directories contain domain-specific patterns. Module directories contain implementation details. This creates semantic locality where LLMs and developers always have relevant context without searching.

Leanpub Book

Read The Meta-Engineer

A practical book on building autonomous AI systems with Claude Code, context engineering, verification loops, and production harnesses.

Continuously updated
Claude Code + agentic systems
View Book

Related Concepts

References

Topics
Architectural PatternsClaude MdCollocationContext ManagementDocumentation StrategyDomain Specific RulesEslint ConfigHierarchical RulesInstitutional MemoryRule Proximity

Newsletter

Become a better AI engineer

Weekly deep dives on production AI systems, context engineering, and the patterns that compound. No fluff, no tutorials. Just what works.

Join 306K+ developers. No spam. Unsubscribe anytime.


More Insights

Cover Image for The Semantic Triangle: Mock Screens, PoC Backend, and Spec File Beat Any One Alone

The Semantic Triangle: Mock Screens, PoC Backend, and Spec File Beat Any One Alone

Three artefacts. Three reduced ambiguities. One projection task instead of three inventions.

James Phoenix
James Phoenix
Cover Image for Contracts Parallelize Agents

Contracts Parallelize Agents

If you’re waiting for Agent A to finish before starting Agent B, you’re wasting time. Define the contract between them and dispatch both now.

James Phoenix
James Phoenix