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
Claude CodeContext ManagementDocumentationDomain Driven DesignLintingMemory SystemsProgressive DisclosureSoftware Architecture

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 Computer Use Kills the Config Tax, Not the Trust Tax

Computer Use Kills the Config Tax, Not the Trust Tax

My sister hates job applications because they make her re-submit information she already has. That is the same pain as API app review, and the same agent that lives in my codebase can dissolve both. This feels insane, and it is the new default shape of the work.

James Phoenix
James Phoenix
Cover Image for Sentry Errors Should Spawn Agents on Your Own Machine

Sentry Errors Should Spawn Agents on Your Own Machine

A new production error is an event. Events should trigger work, not sit in a dashboard. So I wired Sentry to spawn a coding agent on my own hardware, point it at my exact stack, and open a draft PR with a fix.

James Phoenix
James Phoenix