← ContentsClaude Code · intermediate

CLAUDE.md context files

CLAUDE.md is a plain-text markdown file that Claude Code reads automatically at the start of every session to maintain persistent project context. You place it in your project directory (or in a few other locations) and fill it with coding standards, architecture decisions, preferred libraries, build/test commands, and hard constraints. Claude loads the file before any user message, so it behaves like a senior engineer who already knows your project's rules without you having to re-explain them every session. The file system is hierarchical: a global file at ~/.claude/CLAUDE.md applies to all your projects, a file at the project root (./CLAUDE.md) applies to that repository, a file at ./.claude/CLAUDE.md scopes to the project, and ./CLAUDE.local.md holds personal notes that are not committed to version control. Nested subdirectory CLAUDE.md files (e.g., packages/frontend/CLAUDE.md) load lazily — only when Claude interacts with files in that subtree — so large monorepos can have per-package rules without paying token costs upfront for every package. CLAUDE.md files can also import other files using @path/to/file syntax, pulling in READMEs, package.json, or any other reference material at launch. Anthropic's prompt caching applies to the file, so after the first load in a session subsequent requests are billed at the lower cache-read rate rather than full input-token price.

When you’d use it

  • Team Onboarding — Build and Test CommandsA new developer joins the team and pairs with Claude Code. Instead of reading docs to learn how to build, test, and lint, Claude already knows the commands from CLAUDE.md and runs them automatically when validating changes.
  • Enforcing Architecture BoundariesA backend team wants to ensure Claude never writes directly to the database from route handlers. CLAUDE.md mandates that all DB access goes through the service layer, so Claude consistently generates code that respects that boundary without reminders.
  • Consistent Code Style Across SessionsA TypeScript project uses strict null checks, ES modules, and async/await only. CLAUDE.md encodes these rules so Claude never introduces .then() chains, CommonJS require(), or unchecked nulls regardless of how a task is phrased.
  • Security and Compliance GuardrailsA fintech team has rules like 'never log passwords,' 'always hash with bcrypt,' and 'all API routes require auth middleware.' Encoding these in CLAUDE.md means Claude applies them automatically even when a developer forgets to mention them in a prompt.
  • Multi-Session Agentic Research ProjectsA research team runs Claude Code across many sessions on a long-running scientific computing project. CLAUDE.md contains the project deliverables, a link to CHANGELOG.md, and instructions for Claude to update progress notes between sessions, giving each new session full continuity.

What changed recently

  • 2026-04The lean system prompt became the default for all models except Haiku, Sonnet, and Opus 4.7 and earlier. With a leaner system prompt, CLAUDE.md instructions are more reliably followed because there is less competing content in the context window.
  • 2026-01Checkpoints feature stabilized: Claude Code now automatically saves code state before each change, and users can rewind to previous versions. CLAUDE.md files in long-running projects can be paired with checkpoints for more aggressive refactoring with a safety net.
  • 2025-11Claude Opus 4.5 release added Plan Mode, which lets Claude ask clarifying questions upfront and generate a user-editable plan.md before executing. High-level project goals in CLAUDE.md can now inform plan generation.
  • 2025-10Prompt caching fully enabled for CLAUDE.md in Claude Code. After the first load in a session, subsequent requests read from cache at a significantly lower token rate, making larger CLAUDE.md files economically practical.
This is the short version

The full chapter has three worked examples, the common pitfalls, and the workflow that makes it pay — plus the other 84 features, kept current.

Get Claude Master — $97
CLAUDEMASTER
An independent publication.
Independent product. Not affiliated with or endorsed by Anthropic. “Claude” is a trademark of Anthropic, used here only to describe the subject of this manual.
© 2026 Claude Master — All rights reserved.