Scan the project structure and generate a hierarchical CLAUDE.md document index.
Usage
/my-init [项目简述] [--modules]
Parameter description:
项目简述: optional, a brief description of the project--modules: optional, when this parameter is added, generate module-level CLAUDE.md files
Execution workflow
Step 1: Get timestamp + scan project
Execute in parallel:
// 1. 获取时间戳
Bash({ command: "powershell -Command \"Get-Date -Format 'yyyy-MM-dd HH:mm'\"" })
// Unix: date "+%Y-%m-%d %H:%M"
// 2. 扫描项目结构(只读,返回结构信息)
Task({
subagent_type: "Explore",
prompt: `分析项目结构并返回 JSON 格式报告:
{
"name": "项目名称(从 package.json/pyproject.toml 或目录名推断)",
"tech": { "language": "", "framework": "", "build": "" },
"entry": ["入口文件路径"],
"modules": [
{ "path": "模块路径", "name": "模块名", "role": "职责", "files": ["关键文件"] }
],
"commands": { "install": "", "dev": "", "test": "" }
}
跳过:node_modules、dist、build、.git、__pycache__`,
description: "扫描项目结构"
})
Step 2: Generate root-level CLAUDE.md
Use the Write toolCreate in the project root directory CLAUDE.md:
# {项目名称}
> 生成时间:{TIMESTAMP}
## 概述
{根据扫描结果写 1-2 句项目简述}
## 技术栈
- 语言:{language}
- 框架:{framework}
- 构建:{build}
## 项目结构
```mermaid
graph TD
ROOT[{项目名}]
ROOT --> M1[{模块1}]
ROOT --> M2[{模块2}]
Module index
| Module | Path | Responsibility |
|---|---|---|
| {name} | {path} |
{role} |
Entry file
{entry}- {description}
Quick commands
{commands.install}
{commands.dev}
{commands.test}
### 步骤 3:生成模块级 CLAUDE.md(仅当指定 `--modules` 参数时)
**跳过条件**:如果用户未指定 `--modules` 参数,跳过此步骤。
**对每个模块**,用 Write 工具在其目录下创建 `CLAUDE.md`:
```markdown
# {模块名}
> [← 返回根目录](../CLAUDE.md) | 更新:{TIMESTAMP}
## 职责
{role}
## 关键文件
| 文件 | 职责 |
|------|------|
| `{file}` | {描述} |
## 依赖关系
- 依赖:{分析 import 语句}
- 被依赖:{分析其他模块的 import}
Step 4: Output summary
## 初始化完成
### 生成文档
- ✅ `./CLAUDE.md`
- ✅ 模块级:{N} 个(仅当使用 `--modules` 参数时显示)
### 识别模块
1. `{path}` - {role}
### 推荐下一步
- [ ] 检查文档准确性
- [ ] 补充业务逻辑
- [ ] 如需模块级文档,使用 `/my-init --modules` 重新生成
Rules
- Explore is read-only - subagents only return analysis results, do not write files
- Main process writes files - you (the Claude executing the skill) generate documents with the Write tool
- Only write documentation - do not modify source code
- Skip generated artifacts -
node_modules、dist、build、__pycache__、.git - Module identification - directories containing
__init__.py(Python) orindex.*(JS/TS)
Mermaid conventions
- Root level:
graph TD(top-down) - Module level:
graph LR(left-to-right) - Node IDs use camelCase naming