When we build AI agents or use tools like Claude Code to develop applications, we often want them to follow specific instructions.
For example, we may want the coding agent to follow a particular architecture, use specific libraries, adhere to coding standards and follow certain testing practices.
Rather than repeating these instructions in every prompt, we can maintain them in Markdown files that the coding agent automatically discovers and loads into its context.
In Claude Code, this is primarily achieved using a file called CLAUDE.md.
1. What is CLAUDE.md?
CLAUDE.md is a Markdown file used to provide persistent instructions and context to Claude Code.
Consider the following example for an Order Management application.
Order Management Application Technology Stack Java 21 Spring Boot PostgreSQL Coding Standards Follow layered architecture. Use constructor-based dependency injection. Keep business logic in the service layer. Testing Use JUnit 5 and Mockito. Run unit tests after code changes.
When a user provides a prompt such as “Build an Order Management application,” Claude Code uses both the user prompt and the instructions defined in CLAUDE.md to generate the application.
Without this file, we would have to explicitly provide these instructions in our prompts whenever we wanted Claude to follow the same engineering practices.
2. Scope of Instructions
Not all instructions need to apply to every project or developer. Some may be organization-wide, while others may be specific to a project, developer or application component.
| Scope | File Location | Purpose | Example |
|---|---|---|---|
| Organization | Managed CLAUDE.md | Organization-wide standards | Use approved libraries and follow enterprise security standards. |
| User | ~/.claude/CLAUDE.md | Personal preferences across projects | Always explain significant code changes. |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Shared project-specific instructions | Use Spring Boot and layered architecture. |
| Local | ./CLAUDE.local.md | Personal preferences for a specific project | Use a local sandbox for API testing. |
| Directory | subdirectory/CLAUDE.md | Component-specific instructions | Use functional components for React development. |
Consider an application with separate frontend and backend components.
order-management/├── CLAUDE.md├── CLAUDE.local.md├── frontend/│ └── CLAUDE.md└── backend/ └── CLAUDE.md

The root CLAUDE.md contains common project instructions, while the frontend and backend directories contain their respective technical conventions.
3. How Does Claude Code Discover These Files?
Claude Code has a built-in mechanism for discovering instruction files. We do not need to explicitly reference them in our prompts.
- At session startup: Claude Code loads applicable organization, user and project instructions, including instruction files in the current directory and its parent directories.
- During execution: Additional
CLAUDE.mdfiles in subdirectories are loaded on demand when Claude reads files within those directories.
For example, when Claude starts working on the backend component, the backend/CLAUDE.md instructions are loaded into its context.
Instruction Precedence
Unlike traditional configuration files, CLAUDE.md instructions do not have a guaranteed override mechanism.
If the project-level instructions specify Maven and the directory-level instructions specify Gradle for the same component, Claude receives conflicting instructions.
Loading order does not guarantee precedence.
It is therefore important to ensure that instructions across different scopes are consistent and complementary.
4. Modularizing Instructions
As an application grows, maintaining all its instructions in a single CLAUDE.md file can become difficult.
Claude Code provides two approaches to modularizing instructions.
Using File Imports
We can organize instructions into separate Markdown files and explicitly reference them in CLAUDE.md using the @ syntax.
Project Instructions@./standards/coding.md@./standards/testing.md@./standards/security.md
The standards/ directory is simply a custom directory. This approach is particularly useful for reusing existing documentation and shared engineering instructions.
Using .claude/rules/
Claude Code provides a dedicated directory for organizing project instructions.
order-management/├── CLAUDE.md└── .claude/ └── rules/ ├── coding.md ├── testing.md └── security.md
Unlike file imports, Markdown files in .claude/rules/ are automatically discovered and do not need to be referenced in CLAUDE.md.
Rules can also be scoped to specific file paths.
For example, testing.md:
---paths: "src/test/**/*.java"--- Use JUnit 5 and Mockito. Mock external dependencies. Cover positive and negative scenarios.
These instructions are loaded when Claude works with matching files. Rules without path conditions are loaded unconditionally.
Modularization vs. Context Optimization
Splitting instructions into multiple files improves maintainability, but it does not necessarily reduce context consumption.
| Approach | Modularization | Conditional Loading |
|---|---|---|
| File imports | Yes | No |
| Rules without path conditions | Yes | No |
| Path-specific rules | Yes | Yes |
Path-specific rules help avoid loading unnecessary instructions into the context window.
Modularization is about organizing instructions. Context optimization is about loading the right instructions at the right time.
5. Instructions vs. Enforcement
Consider adding the following instructions to CLAUDE.md:
- Never read the
.envfile. - Never modify production configuration.
- Always run tests after code changes.
Does this guarantee that Claude will always follow these instructions?
No. These instructions are interpreted by the language model and are not deterministic controls.
For requirements that must be enforced, Claude Code provides additional mechanisms:
- Permissions: Control which tool operations are allowed, denied or require approval.
- Hooks: Execute predefined actions at specific lifecycle events, such as blocking a prohibited operation or running automated validation.
Instructions guide behavior; properly configured permissions and hooks enforce behavior.
This distinction is particularly important when adopting AI coding agents in enterprise environments.
6. What is AGENTS.md?
The concept of Markdown-based instruction files is not limited to Claude Code.
AGENTS.md is an open format for providing instructions to AI coding agents across tools such as OpenAI Codex, GitHub Copilot and Cursor.
While README.md helps humans understand a project, AGENTS.md helps AI coding agents understand how to work on it.
Different coding agents have their own instruction discovery mechanisms. In Claude Code, shared AGENTS.md instructions can also be referenced from CLAUDE.md using file imports.
As engineering teams adopt multiple AI coding tools, a common instruction format can help reduce duplication and maintain consistency.
Final Thoughts
As AI coding agents become part of our software engineering workflows, managing instructions becomes an important engineering practice.
It is not just about writing better prompts, but also about providing consistent context, organizing instructions efficiently and establishing boundaries for autonomous execution.


