文章

定制CLAUDE.md

CLAUDE.md

放置在用户配置目录:~/.claude/CLAUDE.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 任何项目都务必遵守的规则(极其重要!!!)

## First Plan

1. First think through the problem, read the codebase for relevant files, and write a plan to tasks/todo.md.  
2. The plan should have a list of todo items that you can check off as you complete them  
3. Before you begin working, check in with me and I will verify the plan.  
4. Then, begin working on the todo items, marking them as complete as you go.  
5. Please every step of the way just give me a high level explanation of what changes you made  
6. Make every task and code change you do as simple as possible. We want to avoid making any massive or complex changes. Every change should impact as little code as possible. Everything is about simplicity.  
7. Finally, add a review section to the todo.md file with a summary of the changes you made and any other relevant information.

## Code Architecture

- 编写代码的硬性指标,包括以下原则:
  (1)对于 Python、JavaScript、TypeScript 等动态语言,尽可能确保每个代码文件不要超过 300 行
  (2)对于 Java、Go、Rust 等静态语言,尽可能确保每个代码文件不要超过 400 行;Android项目用Kotlin语言
  (3)每层文件夹中的文件,尽可能不超过 8 个。如有超过,需要规划为多层子文件夹
- 除了硬性指标以外,还需要时刻关注优雅的架构设计,避免出现以下可能侵蚀我们代码质量的「坏味道」:
  (1)僵化 (Rigidity): 系统难以变更,任何微小的改动都会引发一连串的连锁修改。
  (2)冗余 (Redundancy): 同样的代码逻辑在多处重复出现,导致维护困难且容易产生不一致。
  (3)循环依赖 (Circular Dependency): 两个或多个模块互相纠缠,形成无法解耦的“死结”,导致难以测试与复用。
  (4)脆弱性 (Fragility): 对代码一处的修改,导致了系统中其他看似无关部分功能的意外损坏。
  (5)晦涩性 (Obscurity): 代码意图不明,结构混乱,导致阅读者难以理解其功能和设计。
  (6)数据泥团 (Data Clump): 多个数据项总是一起出现在不同方法的参数中,暗示着它们应该被组合成一个独立的对象。
  (7)不必要的复杂性 (Needless Complexity): 用“杀牛刀”去解决“杀鸡”的问题,过度设计使系统变得臃肿且难以理解。
- 【非常重要!!】无论是你自己编写代码,还是阅读或审核他人代码时,都要严格遵守上述硬性指标,以及时刻关注优雅的架构设计。
- 【非常重要!!】无论何时,一旦你识别出那些可能侵蚀我们代码质量的「坏味道」,都应当立即询问用户是否需要优化,并给出合理的优化建议。

## Communication

- 永远使用简体中文进行思考和对话
- 行业的专业术语使用英文来对话,特别是计算机科学相关
  - 特别是Android开发领域的,如系统的类名,关键字
  - Gradle开发相关
  - Kotlin开发相关
  - Java开发相关
  - Python开发相关
  - HTML/CSS/JavaScript(JS)相关
  - AI相关

## Documentation

- 编写 .md 文档时,也要用中文,专业术语保留用英文
- 正式文档写到项目的 docs/ 目录下,文档名用英文
- 用于讨论和评审的计划、方案等文档,写到项目的 discuss/ 目录下
本文由作者按照 CC BY 4.0 进行授权