NAME
CLAUDE.md — instruction file for Claude Code
SYNOPSIS
~/.claude/CLAUDE.md
./CLAUDE.md
./.claude/CLAUDE.md
./<subdir>/CLAUDE.md
METADATA
DESCRIPTION
CLAUDE.md is the primary instruction file for Claude Code, Anthropic's agentic coding CLI. When Claude Code starts a session, it reads and concatenates all CLAUDE.md files from the user's home directory down through the project root to the current working directory. This creates a layered configuration system where global preferences provide defaults, project-level instructions set team standards, and subdirectory files add context-specific guidance.
CLAUDE.md files above the working directory are loaded in full at launch. Subdirectory CLAUDE.md files load on-demand when Claude reads files in those directories. More specific instructions always take precedence over broader ones.
The file uses standard Markdown with no special schema — headings, lists, code blocks, and prose all work naturally. The one special syntax is the @-include directive, which inlines another file's content. For modular organization, .claude/rules/ provides auto-loaded rule files that don't need explicit @-includes.
CLAUDE.md is designed to be committed to version control and shared with the entire team. It should describe the project's conventions, architecture, and development workflow — the same things you'd tell a new team member on their first day. Target under 200 lines for best adherence; beyond that, signal-to-noise ratio decreases and context window consumption increases.
Related files: .claude/settings.json (permissions), .claude/rules/*.md (modular rules), .claude/skills/*/SKILL.md (reusable tasks), .mcp.json (MCP servers), .claudeignore (file exclusions).
Lower numbers load first. Higher-priority files override lower ones.
STRUCTURE
ANNOTATED EXAMPLE
1# Acme API Server
2
3> TypeScript + Express REST API with PostgreSQL.
4> Deployed on AWS ECS. Monorepo managed with Turborepo.
5
6## Code Style
7
8- TypeScript strict mode — no `any`, no `ts-ignore`
9- Named exports only (no default exports)
10- Prefer functional patterns: map/filter/reduce over for-loops
11- Error handling: use Result<T, E> type from `src/lib/result.ts`
12- Use `import type` for type-only imports
13
14## Architecture
15
16- `src/routes/` — Express route handlers (thin layer, delegates to services)
17- `src/services/` — Business logic, one file per domain entity
18- `src/db/` — Drizzle ORM schema and query helpers
19- `src/lib/` — Shared utilities (logger, result type, validation)
20- `src/middleware/` — Express middleware (auth, rate-limiting, error handler)
21
22## Commands
23
24```bash
25pnpm install # Install dependencies
26pnpm dev # Start dev server (port 3000)
27pnpm test # Run Vitest suite
28pnpm test:e2e # Run Playwright API tests
29pnpm lint # ESLint + Prettier check
30pnpm db:migrate # Run pending Drizzle migrations
31pnpm db:seed # Seed dev database
32```
33
34## Git Conventions
35
36- Conventional Commits: `feat:`, `fix:`, `chore:`, `docs:`
37- Branch naming: `feat/short-description`, `fix/issue-number`
38- Squash merge to main; delete branches after merge
39- Run `pnpm lint && pnpm test` before committing
40
41## Notes
42
43- The `src/legacy/` directory is being migrated to the new service pattern.
44 Do not add new code there. If you need to modify legacy code, migrate
45 the relevant module to `src/services/` first.
46- All dates are stored as UTC in the database. Never use local time.
47- The auth middleware at `src/middleware/auth.ts` uses JWT tokens.
48 Never bypass auth checks — always use the `requireAuth` middleware.
49
50@docs/api-patterns.md
51@docs/database-conventions.md
SPECIAL DIRECTIVES
@filename.mdInclude directive. Inlines the content of the referenced file at that point. Paths are relative to the CLAUDE.md that contains the directive. Use this to keep the main file short and split concerns into separate docs (e.g. @docs/architecture.md, @docs/style-guide.md).
COMMON MISTAKES
The filename is case-sensitive on all platforms, including macOS (which has a case-insensitive filesystem by default — the file will be found but Claude Code checks the exact name). It must be uppercase CLAUDE with a lowercase .md extension.
CLAUDE.md is a versioned file intended to be shared with your team. Treat it like any other source file. Use environment variables or .env files for secrets.
Claude reads your codebase and its config files. If your project already uses Prettier with a config, you don't need to restate every Prettier rule. Over-constraining wastes tokens and can conflict with tool configs.
A 50KB CLAUDE.md is expensive to process on every request. Split into @docs/architecture.md, @docs/testing.md, etc. Or use .claude/rules/ where each .md file is auto-loaded. Target under 200 lines per file for best adherence.
All CLAUDE.md files from the root to the current working directory are concatenated in order. Subdirectory files should contain only the delta: additional rules, overrides, or context specific to that subtree.
CLAUDE.md is an instruction file, not a security boundary. Permissions for shell commands, MCP tools, and file access are managed in .claude/settings.json with allow/deny arrays using tool-scoped patterns like Bash(npm run *) or Read(./.env).
Files in .claude/rules/ are always loaded into context automatically — no @-reference needed. They can also be path-scoped with glob patterns to only load when working on matching files. @includes in CLAUDE.md inline content at a specific point in the file.