Direct answer
Think of CLAUDE.md as a project contract maintained by the team, rather than cramming the entire knowledge base into each session.
What this guide helps you solve
Help teams write concise, actionable, and verifiable persistent instructions for Claude Code.
Distinguish between CLAUDE.md and automatic memory
CLAUDE.md stores human-written rules that should apply to every relevant session; Claude Code builds automatic memory from prior work, and users can review it. Neither replaces source code or formal documentation.
Good candidates include test commands, repository conventions, architectural constraints, and environment pitfalls the tool cannot reliably infer. General programming knowledge, complete API documentation, and file-by-file explanations only consume context.
Use /init for a starting point, then have maintainers refine it
Run /init after starting Claude Code in the project root directory, and the tool will generate a first draft based on the build system, test framework, and project structure. Generated content must be reviewed by project maintainers.
The first draft contains candidate rules. Remove content Claude can derive from package.json, Makefile, or the code itself, leaving only constraints that materially affect execution correctness.
/init
/contextWrite rules into short, specific, executable instructions
Each rule should answer "what to do, when" and "how to verify it." "Write high-quality code" has no operational value; "run pnpm typecheck after modifying TypeScript" is directly actionable.
If removing a line would not make Claude more likely to err, remove it. Long rule sets dilute the user's current prompt and the constraints that matter most.
# Workflow
- 修改 TypeScript 后运行 `pnpm typecheck`。
- 默认运行受影响测试,不要无故重写快照。
# Repository boundaries
- 不修改 `vendor/` 和生成文件。
- 保留用户已有的未提交改动。Layer instructions by user, repository, and directory
~/.claude/CLAUDE.md suits personal preferences that span projects, the project-root CLAUDE.md holds team rules, and CLAUDE.local.md holds unshared project notes. Subdirectory rules load on demand when Claude accesses the corresponding directory.
In a monorepo, do not pile every package command into the root file. Keep only repository-wide rules at the root, and maintain package-specific test, build, and architecture constraints in each package directory.
Split conditional rules with imports and .claude/rules
CLAUDE.md can import additional files with @path. Rules in .claude/rules/ that have paths frontmatter load on demand for matching files; rules without paths enter the context unconditionally at startup.
Imports should point to stable, short documents. Do not recursively import large README trees, and do not import personal files that may contain keys.
See @README.md for the project overview.
# Additional instructions
- Git workflow: @docs/git-instructions.md
- API conventions: @docs/api-conventions.md---
paths:
- "frontend/**/*.{ts,tsx}"
---
# Frontend rules
- Run pnpm typecheck after editing TypeScript.Verify loading results and delete regularly
Use /context to see which CLAUDE.md files and rules entered the current context. If a rule does not take effect, check the launch directory, file location, conflicting instructions, and file length first.
Maintain CLAUDE.md like code: add the smallest necessary rule when behavior deviates, and remove redundant rules when default behavior is already correct. Move deterministic enforcement to Hooks instead of making the wording increasingly forceful.
/context
/memoryOfficial sources and verification scope
This guide is based on public official documentation. Commands and configuration may change between client versions, so verify the linked sources before use.
Read the verification methodology