"CLAUDE.md Authoring Guide 2026 — What to Include, What to Avoid, and Five Anti-Patterns"

Four locations, loading rules, the 200-line ceiling, @import syntax, and when to split into .claude/rules/


핵심 요약

  • Audience: You've run /init and have a CLAUDE.md, but you're not sure what else to put in it.
  • What you'll get: Per the official /memory docs, the four locations, load rules, what goes in vs out, three effective-writing rules, @import, .claude/rules/ path-scoped splitting, and five anti-patterns to avoid.
  • Prerequisite: Claude Code installed (install guide), slash commands basics (reference).

1. What CLAUDE.md is

Claude Code has two memory systems that carry knowledge across sessions.

CLAUDE.md Auto Memory
Who writes it You Claude itself
What it contains Instructions, rules Learnings, patterns
Scope Project / user / org Per working tree
Loaded Every session start Every session start (first 200 lines or 25KB)
Best for Coding standards, workflows, architecture Build commands, debug insights, preferences

CLAUDE.md is what you write to guide Claude's behavior. Auto memory is what Claude writes based on your corrections. Both are injected as context, not system prompts — advisory, not enforced. The more specific and concise, the more reliably Claude follows them.

This post focuses on CLAUDE.md.


2. Four places CLAUDE.md can live

Scope Location Purpose Shared with
Managed policy macOS: /Library/Application Support/ClaudeCode/CLAUDE.md
Linux/WSL: /etc/claude-code/CLAUDE.md
Windows: C:\Program Files\ClaudeCode\CLAUDE.md
Org-wide policy (deployed by IT/DevOps) All users in the org
Project ./CLAUDE.md or ./.claude/CLAUDE.md Team-shared project instructions Team via version control
User ~/.claude/CLAUDE.md Personal preferences across all projects You only
Local ./CLAUDE.local.md Per-project personal notes (gitignore required) You only (this project)

Priority: more specific wins — project > user > managed. But note that content is concatenated, not overridden. Within a directory, CLAUDE.local.md is appended after CLAUDE.md, so on conflict, your personal notes come last (and win).


3. Loading rules — how the directory tree is walked

Claude Code walks from your current working directory up the tree, reading CLAUDE.md and CLAUDE.local.md at every level. Example:

/home/me/monorepo/          ← CLAUDE.md (shared)
├── foo/                    ← CLAUDE.md (foo team)
│   └── bar/                ← CLAUDE.md (bar feature)
│       (working directory)

Running Claude here loads all three files concatenated into context.

3.1 Subdirectories are on-demand

Conversely, CLAUDE.md in sub-directories is NOT loaded at launch. It's loaded when Claude actually reads a file in that subdirectory. This keeps unrelated sub-project instructions out of context in monorepos.

3.2 --add-dir does not auto-load CLAUDE.md

--add-dir grants file access but does not load the directory's CLAUDE.md by default. To opt in:

CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 claude --add-dir ../shared-config

3.3 Excluding other teams' CLAUDE.md in a monorepo

If an ancestor CLAUDE.md is irrelevant to you, exclude via .claude/settings.local.json:

{
  "claudeMdExcludes": [
    "**/monorepo/CLAUDE.md",
    "/home/user/monorepo/other-team/.claude/rules/**"
  ]
}

Note: managed policy CLAUDE.md cannot be excluded (by design — organizational policy must always apply).


4. What to include, what to exclude

The official guidance is blunt. CLAUDE.md consumes tokens every session, so noise hurts adherence.

✅ Include ❌ Exclude
Bash commands Claude can't guess (e.g. pnpm dev, make seed-db) Anything Claude can figure out by reading code (e.g. scripts listed in package.json)
Code style rules that differ from language defaults Standard language conventions Claude already knows
Testing commands and preferred test runners Long API documentation (link to external docs)
Repository etiquette (branch naming, PR conventions) Info that changes frequently (versions, contacts)
Architectural decisions specific to the project Long explanations or tutorials
Dev environment quirks (required env vars) File-by-file codebase descriptions
Common gotchas and non-obvious behaviors Self-evident practices like "write clean code"

For every line, ask: "Would removing this cause Claude to make a mistake?" If not, cut it. A bloated CLAUDE.md buries the important rules.


5. Three rules for effective writing

Per the official best practices page.

5.1 Size — under 200 lines

Target under 200 lines per CLAUDE.md. Beyond that, context cost rises and adherence drops. The docs note: "If Claude keeps doing something you don't want despite a rule against it, the file is probably too long and the rule is getting lost."

This ceiling is for CLAUDE.md. Auto memory's MEMORY.md is a separate file — only its first 200 lines or 25KB are loaded, whichever comes first. Anything past that is ignored (Auto Memory splits content into topic files).

5.2 Structure — headers and bullets

- Use ES modules (import/export), not CommonJS (require)
- Destructure imports when possible

- Typecheck after a series of changes
- Prefer running single tests, not the whole suite

A scannable structure beats dense paragraphs.

5.3 Specificity — verifiable

Official examples:

Vague (❌) Specific (✅)
"Format code properly" "Use 2-space indentation"
"Test your changes" "Run npm test before committing"
"Keep files organized" "API handlers live in src/api/handlers/"

For critical rules, adding IMPORTANT: or YOU MUST improves adherence (official recommendation).


6. @import syntax

CLAUDE.md can import other files with @path/to/file.

See @README.md for project overview and @package.json for available npm commands.

- Git workflow: @docs/git-instructions.md
- Personal overrides: @~/.claude/my-project-instructions.md
  • Relative paths resolve from the file that contains the import (not the working directory).
  • Absolute paths allowed.
  • Recursive imports allowed, max 5 hops.
  • Imported files are still loaded at launch, so this is organization, not token savings. For actual context savings, use path-scoped rules in .claude/rules/.
  • First-time imports prompt for approval. If you decline, imports stay disabled and the dialog doesn't return.

7. Coexistence with AGENTS.md (e.g. Codex)

Claude Code does not read AGENTS.md directly. If your repo already uses AGENTS.md, import it from CLAUDE.md:

@AGENTS.md

## Claude Code

Use plan mode for changes under `src/billing/`.

Claude reads AGENTS.md first, then appends the Claude-specific section. One source of truth, no duplication between Claude Code and Codex.


8. .claude/rules/ — splitting for larger projects

When CLAUDE.md grows too large, move topic-specific rules to .claude/rules/.

your-project/
├── .claude/
│   ├── CLAUDE.md
│   └── rules/
│       ├── code-style.md
│       ├── testing.md
│       └── security.md

All .md files in .claude/rules/ are discovered recursively. Subdirectories (frontend/, backend/) are fine.

8.1 Path-scoped rules

Add a paths frontmatter field and the rule loads only when Claude reads a matching file. No context cost otherwise.

---
paths:
  - "src/api/**/*.ts"
---

- All endpoints must include input validation
- Use the standard error response format
- Include OpenAPI documentation comments

Multiple patterns + brace expansion:

paths:
  - "src/**/*.{ts,tsx}"
  - "lib/**/*.ts"
  - "tests/**/*.test.ts"

Rules without paths load unconditionally at the same priority as .claude/CLAUDE.md.

8.2 Share across projects with symlinks

ln -s ~/shared-claude-rules .claude/rules/shared
ln -s ~/company-standards/security.md .claude/rules/security.md

Symlinks are supported; circular links are auto-detected.

8.3 User-level rules

Put rules in ~/.claude/rules/ to apply them across all your projects. Priority: project > user.


9. Five anti-patterns

9.1 Bloated file

CLAUDE.md over 200 lines. Critical rules drown in verbiage and adherence falls off a cliff. - Fix: Prune. Ask "does removing this cause a mistake?" If not, delete. Review periodically to kill dead rules.

9.2 Contradictory rules

Bad example: "Use 2-space indentation" in one file + "Follow the Google style guide" (4-space) elsewhere. Claude picks one arbitrarily. - Fix: Periodically scan all CLAUDE.md files + nested ones + .claude/rules/ together to remove contradictions.

9.3 Generic hedging like "write clean code"

Self-evident platitudes dilute the specific rules. - Fix: Don't write what Claude already does by default. Ask why this rule needs to exist.

9.4 Procedures in CLAUDE.md

Multi-step workflows like "to deploy: 1) test 2) build 3) push…" eat tokens every session. - Fix: Move to a skill (/deploy). CLAUDE.md is for facts and rules, not procedures.

9.5 Assuming nested CLAUDE.md survives /compact

The project-root CLAUDE.md is re-injected automatically after /compact (officially documented). Nested CLAUDE.md in subdirectories is NOT re-injected — it reloads only when Claude reads a file there next. - Fix: If an instruction was only given in conversation, migrate it to CLAUDE.md. Don't design nested CLAUDE.md assuming post-compact availability.


10. Getting started — /init

/init

Claude analyzes your codebase (build system, test framework, code patterns) and produces a starter CLAUDE.md. If one already exists, /init suggests improvements rather than overwriting.

Interactive multi-phase flow via env var:

CLAUDE_CODE_NEW_INIT=1 claude

This mode asks which artifacts to set up (CLAUDE.md, skills, hooks), explores the codebase with a subagent, follows up for gaps, and presents a reviewable proposal before writing anything.

After generation, treat CLAUDE.md like code: review when things go wrong, prune regularly, test by observing whether Claude's behavior actually shifts.


11. Diagnostics — /memory and the InstructionsLoaded hook

11.1 /memory — see what got loaded

Running /memory in-session lists every CLAUDE.md, CLAUDE.local.md, and rules file loaded for the current session. If a file isn't in the list, Claude can't see it — first thing to check is location.

11.2 InstructionsLoaded hook — debug via event log

To trace when path-scoped rules or lazy-loaded subdirectory files actually load, use a hook:

{
  "hooks": {
    "InstructionsLoaded": [
      {"type": "command", "command": "echo $CLAUDE_INSTRUCTIONS_PATH >> /tmp/claude-rules.log"}
    ]
  }
}

Full hooks guide coming in the next post.


12. Counter-scenarios — when this guide doesn't fit

  • Prompt-only workflow → Skip CLAUDE.md. Pass instructions via --append-system-prompt or --append-system-prompt-file. Operates at system-prompt level. Must be passed every invocation, so better for scripts/automation than interactive use.
  • Need enforcement, not advice → CLAUDE.md is advisory. For actual blocking, use managed settings: permissions.deny, sandbox.enabled. CLAUDE.md = "do this", settings = "you cannot do that".
  • Policy goes in CLAUDE.md, enforcement goes in settings — official split:
Concern Where to configure
Block specific tools / paths Managed settings permissions.deny
Enforce sandbox isolation Managed settings sandbox.enabled
Auth method / org lock forceLoginMethod, forceLoginOrgUUID
Code style / quality guidelines Managed CLAUDE.md
Data handling / compliance reminders Managed CLAUDE.md

13. What's next

With CLAUDE.md solid:

  1. Claude Code install complete guide — if you haven't installed yet.
  2. Slash commands complete reference/init, /memory, /compact, and everything else referenced above.
  3. Claude Code hooks complete guide — 4 lifecycle events × real scripts — CLAUDE.md is advisory; hooks are enforced (coming soon).

References


This is post 3/15 in the "AI Coding CLI Entry Guide" series. last verified: 2026-04-25 (per official Claude Code Memory + Best Practices docs).

댓글

이 블로그의 인기 게시물

"ML Foundations (9/9) — PyTorch vs TensorFlow, and the Road to Local LLMs"

Agent Memory Engine (2/10) — Building an AI Agent Memory System with SQLite Alone

"ML Foundations (8/9) — Deep Learning Architectures: CNN, RNN, Attention"

"RAG Core Study (14/26) — Evaluation Sets with RAGAS & DeepEval"

"ML Foundations (7/9) — Deep Learning Training: Optimizers, Regularization, Initialization"

AI Agents I Built (5/7) — Building an Automated Blogger API Publishing System

"ML Foundations (6/9) — Neural Networks: From Perceptron to MLP"