返回播客Claude
Claude Code 101
CLAUDE.md 文件
[Music starts]
[Music starts]
One of the most useful parts of Claude Code is the claude.md file.
Claude Code 最有用的功能之一是 CLAUDE.md 文件。
It gives Claude Code persistent memory about your project.
它为 Claude Code 提供了关于你项目的持久记忆。
When you open up Claude Code without a claude.md file, it's like it has to start fresh every single time.
当你打开 Claude Code 而没有 CLAUDE.md 文件时,它就像必须重新开始一样。
It has to re-explore your codebase, understand what dependencies are needed and the features that are already implemented.
它必须重新探索你的代码库,了解需要哪些依赖,
Sometimes it has to make assumptions which makes it harder for us to steer Claude in the right direction.
有时它不得不做出假设,这让我们更难引导 Claude 走向正确的方向。
But that's where claude.md comes in.
但这正是 CLAUDE.md 派上用场的地方。
It's a markdown file that you add to the root of your project and Claude Code reads it automatically every time you start a session.
这是一个你添加到项目根目录的 Markdown 文件,Claude Code 每次都会读取它。
It's like an onboarding script for your codebase.
它就像是你代码库的入职脚本。
Simply put, the contents of claude.md file are appended to your own prompt. You can run the /init command which will make Claude generate one based off of your codebase.
简单来说,CLAUDE.md 文件的内容会附加到你自己的提示词中。你可以把它想成——
So let's have a look at one.
那么我们来看一个示例。
This is a Next.js 15 app using the app router, Tailwind, and Drizzle ORM.
这是一个使用 App Router、Tailwind 和 Drizzle ORM 的 Next.js 15 应用。
Commands: dev server, run tests, lint.
命令:开发服务器、运行测试、Lint。
Code style: use two space indentation, prefer named exports, all API routes go in app/api, use server actions instead of API routes where possible.
代码风格:使用两空格缩进,优先使用命名导出,所有 API 路由放在——
And it's pretty straightforward.
而且非常直观。
Now, if I ask Claude Code to create a React component, it knows how to style it with Tailwind or any other CSS framework that I'm using.
现在,如果我让 Claude Code 创建一个 React 组件,它就知道如何从一开始就正确地进行样式设计。
We can see that Claude does a better job at doing its job right off the bat versus having to understand where everything is at first.
我们可以看到,与之前相比,Claude 从一开始就能更好地完成工作。
And before you ask, the answer is yes.
在你开口之前,答案是肯定的。
You share this in your version control for your team to use.
你可以在版本控制中共享这个文件,供团队使用。
But there's actually a hierarchy of memory files depending on who it's for.
但实际上有一个记忆文件的层次结构,取决于它是为谁服务的。
So first you have your project-level claude.md that lives in the root directory of your project.
首先,你有位于根目录的项目级 CLAUDE.md,
You have a user-level claude.md that lives in your configuration folder.
你有一个位于配置文件夹中的用户级 CLAUDE.md。
This one is just for you and goes across all your projects.
这个只属于你,跨所有项目生效。
So put your personal preferences here, like how you write code comments.
所以把你的个人偏好放在这里,比如你如何写代码注释。
First, if you have to correct Claude to do something, like always use server actions instead of API routes, then explicitly ask Claude to save this to memory so that when you come back to this project, it will know every single time.
第一,如果你需要纠正 Claude 做某件事,比如总是使用 Server Actions——
Second, if you have docs in your project that you want Claude to reference, just use the @ symbol with the file path.
第二,如果你的项目中有想让 Claude 参考的文档,只需——
And third is we recommend you start off a project without a claude.md file so you can see where you have to constantly course correct the model.
第三,我们建议你在没有 CLAUDE.md 文件的情况下开始一个项目,这样你就能——
This keeps your claude.md file compact and contains only the necessary information that Claude can work with.
这样可以保持你的 CLAUDE.md 文件简洁,只包含必要的信息。
[Music transition]
[Music transition]
The difference between a frustrating Claude Code session and a productive one comes down to the context, and the claude.md file's how you provide that context.
令人沮丧的 Claude Code 会话和富有成效的会话之间的差异,往往取决于你的 CLAUDE.md 文件。
Start with your stack, your preferences, and then commands, and just build from there as you go.
从你的技术栈、你的偏好开始,然后是命令,逐步构建。