Skip to main content
All guides

AI Context

The definitive guide to CLAUDE.md

CLAUDE.md is how Claude Code learns your codebase's conventions, build commands, and house rules. Here is how to configure it, structure it, and keep it from drifting out of date.

Definition: CLAUDE.md is Claude Code's native project-memory file: a Markdown file, usually at the repository root, that Claude Code reads at the start of every session to learn build/test commands, code conventions, and project-specific rules. It supports scoped files (user, project, local) and @-imports, and unlike AGENTS.md, it is read only by Claude Code, with no automatic fallback to other agent instruction files.

Last reviewed: August 2026

What is CLAUDE.md?

CLAUDE.md is Claude Code's native memory and instruction file. At the start of every session, Claude Code reads this file to boot up its context—learning your project's commands, conventions, architecture patterns, and gotchas.

Unlike general readme files, CLAUDE.md is designed specifically for an AI coding agent. It holds standing instructions that tell Claude Code what style to write, what linters to run, and what commands to execute when building or testing.

Understanding the Scopes of CLAUDE.md

Claude Code checks for instructions at multiple levels, allowing you to separate personal, project, and team preferences:

  1. Global/User Scope: Stored in your home directory (e.g., ~/.claude.json or ~/.claude.md). This holds your personal editor preferences and system-wide styles.

  2. Project/Repo Scope: Stored at your repository root (e.g., repo/CLAUDE.md). This holds project-specific build/test commands and team coding guidelines. This file is committed to git.

  3. Local Scope: Stored in the local workspace (.git/info/exclude or local-only configurations) for workspace-specific parameters you don't commit.

Wiring CLAUDE.md to AGENTS.md

If your team uses multiple AI coding agents (such as Cursor, Codex, and Claude Code), maintaining duplicate rules files like AGENTS.md and CLAUDE.md is a recipe for documentation drift.

The recommended pattern is to keep your core conventions and build commands in AGENTS.md (which is read by Cursor and other open tools), and make your CLAUDE.md import it using an @AGENTS.md directive or a symlink. You can then add Claude-specific command configurations below the import, maintaining a single source of truth for the core rules.

Keeping CLAUDE.md from Drifting

Like any documentation, CLAUDE.md can go stale. If a developer changes the test runner command or refactors the folder layout but forgets to update CLAUDE.md, Claude Code will confidently execute the wrong commands.

Tying CLAUDE.md updates to your CI/CD pipeline or pull request reviews is the best way to prevent drift. You can run automated checks that verify if the documented build and test commands still match what is defined in your package.json or config files.

A minimal example CLAUDE.md

There is no fixed schema, but most working files converge on the same shape: commands, conventions, and hard guardrails. A short, accurate file beats a long, stale one.

MARKDOWN
# Project: Acme API

## Commands
- Install: `npm install`
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`

## Conventions
- TypeScript strict mode; no `any`
- Errors: return `Result<T, E>`, never throw across module boundaries
- Tests live next to source as `*.test.ts`

## Do not
- Do not edit generated files in `src/generated/`
- Do not commit directly to `main`

@AGENTS.md

How-to

How to set up CLAUDE.md

  1. 1

    Create CLAUDE.md at your repo root

    Add a Markdown file named CLAUDE.md at the top of your repository and commit it so the whole team gets the same context.

  2. 2

    Import AGENTS.md if you have one

    If your repo already has an AGENTS.md, add an @AGENTS.md import (or symlink) at the top of CLAUDE.md so both files share one source of truth, then add Claude-specific notes below it.

  3. 3

    Document commands and conventions

    List the exact install, build, lint, and test commands, plus code style and any hard guardrails - the same high-value content AGENTS.md needs.

  4. 4

    Keep it current as code changes

    Review CLAUDE.md whenever commands or structure change, ideally at merge time, so Claude Code never runs a stale command with confidence.

Let Moxie Docs manage the drift

Moxie Docs connects to your repository, monitors code merges, and automatically updates your codebase guides. If your build commands or directory structures change, Moxie will automatically detect the drift and propose updates to your CLAUDE.md and AGENTS.md files via reviewable docs PRs—so you never have to worry about stale AI context.

FAQ

Frequently asked questions

Quick answers to the questions developers ask about CLAUDE.md guide.

Get started

Give your agents real codebase context.

Connect a repository and Moxie Docs generates living documentation and serves it to your agents over MCP. 14-day free trial, no charge today.