跳到主要内容

claude-md 精选

按最佳实践创建或更新 CLAUDE.md 文件,以便为 AI agent 提供最优的项目入门上下文

在 GitHub 打开

安装方式

cp -r zh/03-skills/claude-md ~/.claude/skills/claude-md-4

把该 skill 目录放进客户端 skills 目录。不同客户端的目录可能不同,Claude Code 默认是 ~/.claude/skills/

整仓一次性获取:git clone --depth 1 https://github.com/luongnv89/claude-howto.git

依赖与权限

  • 无需 API Key
  • 无需联网
  • 依赖外部命令:node bun pip uv cargo
  • 以上为按正文与 frontmatter 自动推断的信号,仅供参考;安装前建议先阅读原文。

SKILL.md 正文

来源 luongnv89/claude-howto@065ab37 · 许可 MIT · 内容未修改

用户输入

$ARGUMENTS

在继续之前,你必须先考虑用户输入(如果不为空)。用户可能会指定:

  • create - 从零创建新的 CLAUDE.md
  • update - 改进已有的 CLAUDE.md
  • audit - 分析并报告当前 CLAUDE.md 的质量
  • 一个具体路径,用于创建或更新(例如 src/api/CLAUDE.md 代表目录级说明)

核心原则

LLM 是无状态的:CLAUDE.md 是每次对话中唯一会自动包含的文件。它是让 AI agent 了解代码库的主要入门文档。

黄金法则

  1. 少即是多:前沿 LLM 大约能遵循 150-200 条指令。Claude Code 的系统提示词本身已经占了大约 50 条,因此 CLAUDE.md 必须聚焦且简洁。
  1. 只放通用信息:只包含每次会话都适用的内容。任务特定的说明应该放在单独文件里。
  1. 不要把 Claude 当成 lint 工具:风格指南会膨胀上下文并降低指令遵循效果。应改用确定性工具(如 prettier、eslint 等)。
  1. 绝不自动生成:CLAUDE.md 是 AI harness 中杠杆最高的位置。应该经过认真思考后手工编写。

执行流程

1. 项目分析

首先分析当前项目状态:

  1. 检查是否存在已有的 CLAUDE.md 文件:
  • 根目录:./CLAUDE.md 或 .claude/CLAUDE.md
  • 目录级:**/CLAUDE.md
  • 全局用户配置:~/.claude/CLAUDE.md
  1. 识别项目结构:
  • 技术栈(语言、框架)
  • 项目类型(monorepo、单体应用、库)
  • 开发工具(包管理器、构建系统、测试运行器)
  1. 查看已有文档:
  • README.md
  • CONTRIBUTING.md
  • package.json、pyproject.toml、Cargo.toml 等

2. 内容策略(WHAT, WHY, HOW)

围绕三个维度组织 CLAUDE.md:

WHAT - 技术与结构

  • 技术栈概览
  • 项目组织方式(对 monorepo 尤其重要)
  • 关键目录及其用途

WHY - 目的与背景

  • 项目是做什么的
  • 为什么做出这些架构决策
  • 每个主要组件负责什么

HOW - 工作流与约定

  • 开发流程(bun vs node、pip vs uv 等)
  • 测试流程和命令
  • 验证与构建方法
  • 关键“坑点”或非显而易见的要求

3. 渐进式披露策略

对于较大的项目,建议创建 agent_docs/ 文件夹:

agent_docs/
  |- building_the_project.md
  |- running_tests.md
  |- code_conventions.md
  |- architecture_decisions.md

在 CLAUDE.md 中引用这些文件,并写明:

关于详细的构建说明,请参考 `agent_docs/building_the_project.md`

重要:使用 file:line 引用,而不是代码片段,以避免上下文过时。

4. 质量约束

创建或更新 CLAUDE.md 时:

  1. 目标长度:少于 300 行,理想情况下少于 100 行
  2. 不要写风格规则:移除任何 lint/format 相关说明
  3. 不要写任务特定说明:移到单独文件中
  4. 不要写代码片段:改用文件引用
  5. 不要重复信息:不要重复 package.json 或 README 中已有内容

5. 必备章节

一个结构良好的 CLAUDE.md 应包含:

# 项目名称

一句简短的项目描述。

## 技术栈
- 主语言和版本
- 关键框架/库
- 数据库/存储(如有)

## 项目结构
[仅适用于 monorepo 或复杂结构]
- `apps/` - 应用入口
- `packages/` - 共享库

## 开发命令
- 安装:`command`
- 测试:`command`
- 构建:`command`

## 关键约定
[只保留非显而易见、高影响的约定]
- 约定 1,简要说明
- 约定 2,简要说明

## 已知问题 / 坑点
[经常让开发者踩坑的内容]
- 问题 1
- 问题 2

6. 需要避免的反模式

不要包含:

  • 代码风格指南(交给 lint 工具)
  • 如何使用 Claude 的说明
  • 对显而易见模式的冗长解释
  • 复制粘贴的代码示例
  • 泛泛而谈的最佳实践(例如“写干净的代码”)
  • 特定任务的说明
  • 自动生成内容
  • 大量 TODO 列表

7. 验证清单

在最终确定前,检查:

  • [ ] 少于 300 行(最好少于 100 行)
  • [ ] 每一行都适用于所有会话
  • [ ] 没有风格/格式规则
  • [ ] 没有代码片段(使用文件引用)
  • [ ] 命令已经验证可用
  • [ ] 对复杂项目使用了渐进式披露
  • [ ] 已记录关键坑点
  • [ ] 没有与 README.md 重复

输出格式

对于 create 或默认模式:

  1. 分析项目
  2. 按上述结构起草 CLAUDE.md
  3. 向用户展示草稿以供审阅
  4. 在获得批准后写入相应位置

对于 update:

  1. 读取现有 CLAUDE.md
  2. 按最佳实践进行审计
  3. 识别:
  • 需要删除的内容(风格规则、代码片段、任务特定内容)
  • 需要压缩的内容
  • 缺失的重要信息
  1. 向用户展示修改建议
  2. 在获得批准后应用修改

对于 audit:

  1. 读取现有 CLAUDE.md
  2. 生成报告,包括:
  • 当前行数与目标的对比
  • 可通用于所有会话内容的百分比
  • 发现的反模式列表
  • 改进建议
  1. 不要修改文件,只做报告

AGENTS.md 处理

如果用户请求创建或更新 AGENTS.md:

从 v2.1.277 起,Claude Code 会直接把 AGENTS.md 作为项目指令读取。 但前提是工作目录以及它上面的每一级目录都没有 CLAUDE.md、.claude/CLAUDE.md 或 CLAUDE.local.md。~/.claude/CLAUDE.md、受管理的 CLAUDE.md 和 .claude/rules/ 不计入这项检查,它们仍会一并加载。该行为由 /config 中的 Project instructions 控制:claude-md-or-agents-md(默认)、claude-md-and-agents-md、claude-md、managed-only。在无法直接读取的环境中 — v2.1.277 之前的版本(在 Bedrock/Vertex/Foundry、LLM 网关或关闭遥测的情况下为 v2.1.281 之前),或升级后的第一个会话 — 退回到在 CLAUDE.md 中用 @AGENTS.md 导入,或者把 CLAUDE.md 软链接到它。

AGENTS.md 是一个跨工具的项目上下文文件 — 和 CLAUDE.md 属于同一类文档,而不是 agent 定义格式。它的存在是为了让多个编码 agent 共用同一套项目约定:

  • 构建、测试和 lint 命令
  • 代码风格与架构约定
  • 仓库结构以及各部分所在位置

Subagents 是单独定义的,放在 .claude/agents/*.md 里 — 不在 AGENTS.md 中。

同样适用以下原则:

  • 保持聚焦和简洁
  • 使用渐进式披露
  • 用外部文档引用代替内联内容

备注

  • 在写入前始终验证命令是否可用
  • 不确定时就不要写,少即是多
  • 系统提醒会告诉 Claude,CLAUDE.md “可能相关,也可能不相关” - 噪音越多,越容易被忽略
  • monorepo 最需要清晰的 WHAT/WHY/HOW 结构
  • 目录级 CLAUDE.md 应该更聚焦

质量与来源

所属仓库
luongnv89/claude-howto
仓库星标
4.2 万
最近更新
昨天
采集时间
今天
commit
065ab3734f64
内容指纹
sha256:e12190230b6a89a
文件路径
zh/03-skills/claude-md/SKILL.md

同仓库其它 Skill

查看全部 25 个
lesson-quiz
Test a learner on a single Claude Code tutorial lesson (01-10) with 10 questions, scoring answers and flagging weak spots. Use before, during, or after a lesson. Don't use for whole-tutorial assessment or explaining a topic instead of testing it.
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端
self-assessment
Comprehensive Claude Code self-assessment and learning path advisor. Runs a multi-category quiz covering 10 feature areas, produces a detailed skill profile with per-topic scores, identifies specific gaps, and generates a personalized learning path with prioritized next steps. Use when asked to "assess my level", "take the quiz", "find my level", "where should I start", "what should I learn next", "check my skills", "skill check", or "level up".
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端
blog-draft
Draft a blog post from ideas and resources. Use when users want to write a blog post, create content from research, or draft articles. Guides through research, brainstorming, outlining, and iterative drafting with version control.
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端
brand-voice
Ensure all communication matches brand voice and tone guidelines. Use when creating marketing copy, customer communications, public-facing content, or when users mention brand voice, tone, or writing style.
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端
claude-md
Create or update CLAUDE.md files following best practices for optimal AI agent onboarding
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端
code-review-specialist
Comprehensive code review with security, performance, and quality analysis. Use when users ask to review code, analyze code quality, evaluate pull requests, or mention code review, security analysis, or performance optimization.
精选 luongnv89/claude-howto 4.2 万 原文
Claude CodeMCP 客户端

相似 Skill

更多「写作」
interview-prep
Prepares the user for a specific interview from their real experience. Builds a story bank in Situation/Task/Action/Result/Reflection form mapped to the competencies the role and company test (such as Amazon's Leadership Principles), writes a cited company and role brief from public sources, predicts questions per round, drafts opener, why-us, weakness and salary answers, prepares questions to ask and a logistics checklist, and runs a post-interview debrief. Use when the user says "help me prepare for my interview", "I have an interview tomorrow" or "in 2 hours", "build my story bank", "STAR stories", "interviewing as a career changer", "what will they ask me", "how do I answer tell me about yourself", "questions to ask the interviewer", "research the company" or "debrief my interview". Uses Reactive Resume MCP tools when connected. For scored role-play practice, mock-interview; for thank-you notes and tracking, job-application-manager; for a salary number, offers or negotiation, offer-negotiation.
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI
job-application-manager
Runs the job-search pipeline. Adds jobs from a link or pasted posting, keeps stages and dates accurate, sets follow-ups, runs a weekly review (stale applications, next actions, funnel stats), records the exact resume version sent, and drafts networking, LinkedIn, referral, recruiter-reply, follow-up, thank-you, status-check, expedite and withdrawal messages without sending them. Use when the user says "add this job to my tracker", "I applied", "log my interview", "I got rejected", "I was ghosted", "log my offer", "track my applications", "do my weekly review", "what should I follow up on", "write a thank-you note", "message this recruiter", "ask for a referral", "withdraw my application", or wants a job-search spreadsheet. Works with a Markdown/CSV tracker or Reactive Resume MCP tools. Not for resume work (resume-tailor, resume-bullet-writer, resume-content-guide), interview prep or practice (interview-prep, mock-interview), or judging, negotiating, accepting or declining an offer (offer-negotiation).
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI
mock-interview
Runs a mock interview for a specific job description. Plays the interviewer in a chosen round (recruiter screen, hiring manager, behavioral, coding, system design, case, product sense, panel), persona and difficulty; asks one question at a time, probes vague answers, and gives quote-backed rubric scores after each answer (coach mode) or at the end (realistic). Model answers use only the user's real experience. Use when the user says "mock interview me", "interview me for this job", "practice interview", "pretend you're the interviewer", "grill me for this role", "run a behavioral round", "quick recruiter screen", "hiring-manager mock", "system design mock" or "case interview practice". With Reactive Resume MCP it reads the application and stories and logs the session. For a story bank, company brief, questions to ask or a real-interview debrief, interview-prep; for scheduling or thank-you notes, job-application-manager; for fixing the resume, resume-tailor; for negotiation practice, offer-negotiation.
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI
offer-negotiation
Evaluates and negotiates job offers. Decodes base, bonus, equity, sign-on, level and terms with unknowns kept unknown and each offer in its own currency, benchmarks against checkable pay data, finds true leverage, drafts one counter as email and call script, role-plays the recruiter, and handles the salary-expectations number, deadlines and extensions, "best and final", competing offers, counteroffers and written acceptance or decline. Country-aware (India CTC, 13th-month pay, public-sector scales). Use when the user says "I got an offer of...", "is this offer good", "should I negotiate", "how do I counter", "compare my offers", "what is my equity worth", "they asked my salary expectations", "they want an answer by Friday", "can I ask for more time", "should I accept" or "practice the negotiation call". Uses Reactive Resume MCP tools when connected. For logging the offer, its deadline and withdrawal notes, job-application-manager; for other interview answers, interview-prep.
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI
resume-builder
Builds a complete resume from scratch as Reactive Resume JSON that conforms to the schema and imports at https://rxresu.me. Asks for each missing detail instead of inventing it, then produces valid JSON (UUIDs, HTML descriptions, template and layout). Use when the user wants to create, build or generate a new resume, turn their work history into Reactive Resume JSON, or asks about the Reactive Resume schema, sections, templates or layout. For what belongs on a resume or a resume audit use resume-content-guide; for rewriting bullets, resume-bullet-writer; for fitting one job posting, resume-tailor; for tracking applications, job-application-manager; for interviews, interview-prep or mock-interview.
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI
resume-bullet-writer
Turns resume duties into truthful impact bullets. Questions the user role by role to dig out achievements, asks for real numbers or honest ranges (never invents them), and writes concise bullets in XYZ, CAR, scope or qualitative form. Use when the user says "rewrite my bullets", "make this bullet stronger", "quantify my resume", "turn my duties into achievements", "improve my experience section", "my resume sounds boring", "I don't have any numbers", pastes resume lines for feedback, or works in a low-number job (nursing, teaching, care, trades, admin, creative). With the Reactive Resume MCP server connected, it edits experience, project, volunteer and education descriptions with apply_resume_patch after the user approves. Use resume-content-guide instead for which sections or details belong and for summaries or headlines, resume-tailor to fit one job posting, interview-prep or mock-interview for interview stories and practice, and resume-builder to build a resume from scratch.
精选 reactive-resume/reactive-resume 4.4 万 原文
Claude CodeCodex CLIGemini CLI