Claude Code Project Initialization
Claude Code project initialization can be done by entering the following in Claude Code's interactive interface:
/init
We can initialize in an existing project directory, or create a new one.
We can first create a directory:
mkdir claude-runoob-test
Enter that directory:
cd claude-runoob-test
Create a test file test.py with the following code:
print("Hello, Runoob!")
Enter Claude Code's interactive interface:
claude
Use the /init command to initialize the project:
/init

If using VS Code, you can also type /init in the Claude Code interface in VS Code:

Claude automatically scans your codebase—reading package.json, existing documentation, configuration files, and code structure—then generates a CLAUDE.md file specific to your project.
The entire process requires no manual operation; Claude analyzes and outputs the initial configuration on its own.

CLAUDE.md files
CLAUDE.md is a Markdown file placed in the project root directory that Claude Code automatically reads at the start of each session.
CLAUDE.md becomes part of Claude's system prompt, allowing each conversation to preload project context without repeatedly explaining basic information.
A good CLAUDE.md should cover three dimensions:
- WHAT: tech stack and project structure, providing Claude with a global map of the codebase
- WHY: the project's purpose, and the function and positioning of each module
- HOW: development approach, e.g., using bun instead of node, and how Claude verifies changes are correct Humanlayer
The following is an example of a typical CLAUDE.md structure:
# Project Name
## Project Overview
简述这个项目的目的和功能。
## 技术栈
- Frontend: React + TypeScript
- Backend: Node.js + Express
- Database: PostgreSQL
## Directory Structure
- `src/components/` - React 组件
- `src/api/` - API 层
- `tests/` - 测试文件
## Common Commands
- 启动开发服务器:`pnpm dev`
- 运行测试:`pnpm test`
- 代码检查:`pnpm lint`
## Development Guidelines
- 使用 TypeScript strict 模式
- 优先使用 interface 而非 type
- 禁止使用 any,使用 unknown 替代
File locations and hierarchy
The project's core file structure is as follows:
your-project/
├── CLAUDE.md # 项目主记忆文件(团队共享)
├── .claude/
│ ├── settings.json # Hooks、权限、环境配置
│ ├── settings.local.json # 个人配置(建议加入 .gitignore)
│ └── commands/ # 自定义斜杠命令
│ └── my-command.md
└── .mcp.json # MCP 服务配置
---
## Best practices after initialization
> 迭代优化,而非一次写死。
`/init` 命令适合快速入门,但真正的价值来自于随时间不断迭代,可以补充 Claude 无法自动推断的内容,例如分支命名规范、部署流程、Code Review 要求;同时删去不适用的通用建议。
- 提交到版本控制:将 CLAUDE.md 提交到 Git,这样整个团队都能从中受益,新成员可以通过让 Claude 解释代码库来快速上手。
- 保持精简:内容要简洁且普遍适用。采用"渐进式披露"原则——不要把所有你想让 Claude 知道的内容都塞进去,而是告诉它如何查找重要信息,让它按需获取,避免撑爆上下文窗口。
- 不要让 CLAUDE.md 替代 linter:在文件中写代码风格规范是最常见的误区之一。永远不要用 LLM 来做 linter 的工作——linter 更快、更便宜,而且是确定性的。代码风格约束只会让上下文窗口膨胀,降低 Claude 的指令遵从质量。
---
## Continuous update using the # shortcut key
In the conversation, anytime send memory instructions to Claude with the # prefix:
We always use pnpm, not npm
All components must include unit tests
这些补充会逐渐积累,形成一份真正反映团队实际工作方式的 `CLAUDE.md`。
---
## Verify initialization effect
After initialization, you can confirm whether Claude correctly understood the project through the following conversation:
- 这个项目是做什么的?
- 解释一下目录结构。
- 项目用了哪些技术?
- 运行测试的命令是什么?