name: claude-md-gen
description: Generate project-specific CLAUDE.md with domain instructions, workflows, templates. Analyzes codebase, asks clarifying questions, produces tailored instructions.
argument-hint: [project-path] [--type cli-tool|web-app|python-cli|research|api-service|library|mixed]
allowed-tools: Read, Grep, Glob, Bash, AskUserQuestion, Write
CLAUDE.md Generator Skill
Generate project-specific CLAUDE.md files through codebase analysis, targeted questions, and pattern selection.
Critical Requirements
- Analyze existing code structure before questions
- Ask focused questions (max 5-7 per session)
- Generate concrete, actionable instructions (no generic filler)
- Include templates for common outputs
- Provide extensibility patterns
- No placeholders/TODOs in generated output
- Self-contained instructions (no references to global ~/.claude/CLAUDE.md)
Workflow Overview
Five-phase generation process:
- Project Analysis - Auto-detect type, extract context
- Clarifying Questions - 5-7 targeted questions based on type
- Pattern Selection - Choose 2-4 relevant reusable patterns
- Template Customization - Generate tailored CLAUDE.md
- Verification - Quality checks before output
Phase 1: Project Analysis
Auto-Detection Logic
Analyze codebase to determine project type:
DETECTION RULES:
research-knowledge:
IF content/ OR findings/ exists
IF PARA folders detected (0_Inbox, 1_Projects, 2_Areas, 3_Resources, 4_Archives)
IF .md files > 10 in root/subdirs
→ research-knowledge
python-cli:
IF pyproject.toml exists
IF click OR typer imports in main file
IF [tool.poetry] OR [tool.pdm] section
IF tests/ with pytest
→ python-cli
web-app:
IF package.json + astro.config.* exists
IF package.json + src/components/ + public/
IF package.json + vite.config OR webpack.config
→ web-app
cli-tool:
IF go.mod + cmd/ + main.go
IF Cargo.toml + src/main.rs + clap dependency
IF package.json + #!/usr/bin/env node in files
→ cli-tool
api-service:
IF go.mod + cmd/ + internal/ + (gin|echo|chi imports)
IF package.json + express|fastify|nest imports
IF pyproject.toml + (fastapi|flask) dependency
→ api-service
library:
IF lib/ exists AND no cmd/ or bin/
IF package.json + "main" field but no bin/
IF Cargo.toml with [lib] section
→ library
mixed:
IF multiple indicators (api + frontend, cli + lib)
→ mixed
FALLBACK:
IF ambiguous → ask user to select
```text
### Context Collection
Gather for template customization:
**From package files:**
- Languages and versions
- Frameworks and versions
- Dependencies (testing, linting, etc.)
- Scripts/tasks (build, test, lint)
**From directory structure:**
- Primary directories with purposes
- Test organization
- Documentation location
- Configuration files
**From existing files:**
- README.md (project description, setup)
- Existing CLAUDE.md (preserve custom sections)
- Taskfile.yml / Makefile / mise.toml (commands)
- .pre-commit-config.yaml / husky (hooks)
- Linter configs (eslintrc, ruff.toml, golangci.yml)
**Analysis steps:**
1. Read package file(s): `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`
2. Map directory structure: `ls -la` + glob for key directories
3. Identify test framework: grep for imports, check dependencies
4. Find linters/formatters: look for config files
5. Extract commands: read Taskfile/Makefile/package.json scripts
6. Check for existing conventions: read existing CLAUDE.md, pre-commit config
**Store context:**
```text
project_context = {
"name": from directory or package file,
"type": detected type,
"languages": {lang: version},
"frameworks": {framework: version},
"testing": framework name,
"linting": [linter names],
"dependency_mgmt": tool name,
"directories": {path: purpose},
"commands": {task: command},
"hooks": [hook names],
"existing_claude_md": sections to preserve
}
```text
---
## Phase 2: Clarifying Questions
Load question framework from `questions/{detected-type}-questions.md`.
Ask 5-7 questions via AskUserQuestion tool based on project type.
**Question categories:**
1. Domain workflows (2-3 questions)
2. Output formats (1-2 questions)
3. Tool integrations (1-2 questions)
4. Quality gates (1 question)
5. Common pitfalls (1 question)
**For mixed projects:** Combine questions from component types (max 7 total).
**Store answers:**
```text
user_answers = {
"workflows": [workflow descriptions],
"output_formats": [format descriptions],
"tools": [tool integrations],
"quality_gates": [requirements],
"pitfalls": [common mistakes]
}
```text
---
## Phase 3: Pattern Selection
Based on user answers, select 2-4 relevant patterns from `patterns/`.
### Selection Matrix
| User Need | Pattern File |
|-----------|--------------|
| "Quick filtering before deep work" | triage-workflows.md |
| "Two-tier verification", "double-check", "validate" | cove-verification.md |
| "Hard requirements", "must have", "criteria" | decision-matrices.md |
| "Source attribution", "citations", "references" | citation-systems.md |
| "Structured outputs", "JSON", "templates", "reports" | output-templates.md |
| "Examples", "test cases", "worked examples" | few-shot-examples.md |
### Priority by Project Type
**research-knowledge:**
1. output-templates.md (for note templates)
2. citation-systems.md (for source attribution)
3. triage-workflows.md (for inbox processing)
**python-cli:**
1. cove-verification.md (for TDD workflow)
2. output-templates.md (for structured CLI outputs)
3. few-shot-examples.md (for test fixtures)
**web-app:**
1. output-templates.md (for component templates if design system)
2. decision-matrices.md (for A11y criteria)
**cli-tool:**
1. output-templates.md (for CLI output formats)
2. decision-matrices.md (for input validation)
3. few-shot-examples.md (for command examples)
**api-service:**
1. decision-matrices.md (for endpoint validation)
2. cove-verification.md (for integration tests)
3. citation-systems.md (for API docs)
**library:**
1. few-shot-examples.md (for usage examples)
2. decision-matrices.md (for breaking change criteria)
3. citation-systems.md (for API docs)
**mixed:**
- Select from all types based on components
- Max 4 patterns total
- Prioritize patterns mentioned in answers
### Selection Logic
```python
selected_patterns = []
# Check user answers for keywords
if any(keyword in answers for keyword in ["filter", "quick", "triage", "screening"]):
selected_patterns.append("triage-workflows.md")
if any(keyword in answers for keyword in ["verify", "double-check", "validate", "two-phase"]):
selected_patterns.append("cove-verification.md")
if any(keyword in answers for keyword in ["requirements", "criteria", "must-have", "scoring"]):
selected_patterns.append("decision-matrices.md")
if any(keyword in answers for keyword in ["sources", "citations", "references", "attribution"]):
selected_patterns.append("citation-systems.md")
if any(keyword in answers for keyword in ["template", "format", "structure", "JSON", "report"]):
selected_patterns.append("output-templates.md")
if any(keyword in answers for keyword in ["examples", "test cases", "fixtures", "samples"]):
selected_patterns.append("few-shot-examples.md")
# Apply type-based priorities if < 2 patterns selected
if len(selected_patterns) < 2:
selected_patterns.extend(type_priorities[project_type])
# Limit to 4 patterns
selected_patterns = selected_patterns[:4]
```text
---
## Phase 4: Template Customization & Generation
### Load Base Template
From `templates/{type}.md`:
- Single type: load one template
- Mixed: merge relevant sections from multiple templates
### Customization Steps
**1. Replace placeholders:**
```text
[Project Name] → project_context["name"]
[Tech Stack] → project_context["languages"] + project_context["frameworks"]
[Directory Structure] → project_context["directories"]
[Commands] → project_context["commands"]
[Linter Name] → project_context["linting"]
[Test Framework] → project_context["testing"]
```text
**2. Add domain-specific sections based on answers:**
```text
IF web-app + design system mentioned:
Add "Design System" section with breakpoints, components
IF python-cli + shared utils mentioned:
Add "Shared Utilities" section with location, conventions
IF research + note templates mentioned:
Add "Note Templates" section with actual templates
IF api-service + auth mentioned:
Add "Authentication" section with method, middleware
```text
**3. Include selected patterns (2-4 from Phase 3):**
For each pattern file:
- Read pattern from `patterns/{name}.md`
- Adapt examples to project context
- Add as section in generated CLAUDE.md
- Customize placeholders with project specifics
**4. Generate output templates if applicable:**
IF output_templates.md selected OR type requires it:
- Create "Output Templates" section
- Include 1-2 concrete examples with structure
- Use project-specific metadata/fields
- Show markdown formatting with sections
**5. Add quality gate checklist:**
```markdown
## Quality Gates
Before committing:
- [ ] {linter_name} passes
- [ ] {test_framework} tests pass
- [ ] {hook_name} hooks pass (if hooks detected)
- [ ] {additional_gates from user answers}
Commands:
```bash
{actual commands from project_context["commands"]}
```text
```text
**6. Add common commands:**
```markdown
## Common Commands
```bash
# {purpose from package.json script or Taskfile}
{actual command}
# {purpose}
{actual command}
```text
```text
**7. Add anti-patterns:**
Combine:
- Type-default anti-patterns from template
- User-mentioned pitfalls from answers
- Project-specific detected issues
Format:
```markdown
## Anti-Patterns
**AVOID:**
- ❌ {specific pitfall 1}
- ❌ {specific pitfall 2}
- ❌ {specific pitfall 3}
**REASON:** {why each is problematic}
```text
### Template Structure
All generated CLAUDE.md files follow this structure:
```markdown
# {Project Name}
{1-2 sentence description from README or inferred}
## Project Structure
```text
{auto-generated from directory analysis}
src/ - {purpose}
tests/ - {purpose}
docs/ - {purpose}
```text
## Tech Stack
**Language:** {language + version}
**Framework:** {framework + version}
**Testing:** {test framework}
**Linting:** {linters}
**Dependency Mgmt:** {tool}
## Development Workflow
{Type-specific workflows - 2-3 most common tasks}
### {Workflow 1: e.g., "Adding New Feature"}
1. {Concrete step}
2. {Concrete step}
3. {Concrete step}
### {Workflow 2: e.g., "Running Tests"}
1. {Concrete step}
2. {Concrete step}
## {Domain-Specific Section 1}
{Based on project type and user answers}
## {Domain-Specific Section 2}
{Based on project type and user answers}
## Quality Gates
{Generated from customization step 5}
## Common Commands
{Generated from customization step 6}
## Output Templates
{If applicable - generated from customization step 4}
### {Template 1 Name}
```markdown
{Template structure with placeholders}
```text
## Anti-Patterns
{Generated from customization step 7}
## {Included Pattern 1}
{Adapted from patterns/{name}.md}
## {Included Pattern 2}
{Adapted from patterns/{name}.md}
## Extensibility
To add sections as project evolves:
1. Add heading in appropriate location
2. Follow section structure above
3. Keep concrete and actionable
4. Include examples where helpful
See `.claude/skills/claude-md-gen/customization-guide.md` for:
- Adding new project types
- Creating custom patterns
- Updating as requirements change
```text
---
## Phase 5: Verification & Output
### Pre-Generation Checks
**During analysis:**
- [ ] At least 3 files read to understand structure
- [ ] Package file(s) parsed correctly
- [ ] Directory structure mapped
- [ ] Existing conventions identified
**During questions:**
- [ ] Max 7 questions asked
- [ ] Questions relevant to detected type
- [ ] No generic questions
- [ ] Answers captured for customization
**During pattern selection:**
- [ ] 2-4 patterns selected
- [ ] Selection based on user needs
- [ ] Patterns will be adapted (not copy-pasted)
### Post-Generation Verification
Load checklist from `checklist.md` and verify:
**Technical accuracy:**
- [ ] Language versions match package files
- [ ] Framework versions correct
- [ ] Directory paths accurate
- [ ] Commands executable
**Actionability:**
- [ ] Workflows have concrete steps
- [ ] Commands include actual syntax
- [ ] Quality gates list actual tools
- [ ] Output templates show structure
**Specificity:**
- [ ] No "TODO" or "Fill this in"
- [ ] No placeholder text remaining
- [ ] Anti-patterns specific to project
- [ ] Examples use project context
**Extensibility:**
- [ ] Customization guide referenced
- [ ] Clear how to add sections
- [ ] Pattern library location noted
**Completeness:**
- [ ] All major project areas covered
- [ ] Selected patterns included and adapted
- [ ] Quality gates comprehensive
- [ ] Common commands from actual project
### Write CLAUDE.md
**Location decision:**
- Default: `CLAUDE.md` at project root
- If `.claude/` exists: ask user if they want `.claude/CLAUDE.md` instead
**Write file** with fully customized content.
### Show Summary
```markdown
# Generated CLAUDE.md
**Location:** {path}
**Type:** {detected-type or mixed}
**Patterns Included:** {list 2-4 patterns}
## Sections Generated
1. Project Structure (auto-generated from {source})
2. Tech Stack ({languages/frameworks})
3. {Domain Section 1}
4. {Domain Section 2}
5. Quality Gates ({linter names})
6. Common Commands ({X commands from mise/make/npm})
7. Output Templates ({Y templates} or "N/A")
8. Anti-Patterns ({Z specific pitfalls})
9. {Pattern 1 name}
10. {Pattern 2 name}
{11-12 if 3-4 patterns}
## Next Steps
- Review {Section X} for accuracy
- Customize {Section Y} with additional details
- Update anti-patterns as you discover new ones
## Extensibility
Add sections as project evolves. See .claude/skills/claude-md-gen/customization-guide.md for:
- Adding new project type templates
- Creating custom patterns
- Adapting generated output as requirements change
```text
---
## Supporting Files
### File Locations
**Templates:** `.claude/skills/claude-md-gen/templates/{type}.md`
- web-app.md, cli-tool.md, python-cli.md, research-knowledge.md, api-service.md, library.md, mixed.md
**Patterns:** `.claude/skills/claude-md-gen/patterns/{name}.md`
- cove-verification.md, decision-matrices.md, triage-workflows.md, citation-systems.md, output-templates.md, few-shot-examples.md
**Questions:** `.claude/skills/claude-md-gen/questions/{type}-questions.md`
- web-app-questions.md, cli-tool-questions.md, python-cli-questions.md, research-questions.md, api-service-questions.md, library-questions.md, mixed-questions.md
**Support:** `.claude/skills/claude-md-gen/`
- checklist.md, customization-guide.md
---
## Implementation Notes
### Mixed Project Handling
When multiple type indicators detected:
1. Identify all component types (e.g., api-service + web-app)
2. Load relevant sections from each template
3. Merge into cohesive structure:
- Project Structure: combined view
- Tech Stack: all languages/frameworks
- Workflows: primary workflows from each component
- Domain sections: one per component type
4. Ask questions from multiple frameworks (max 7 total)
5. Select patterns from all component priorities
### Preserving Existing Sections
If existing CLAUDE.md detected:
1. Parse existing file for custom sections
2. Note sections not in standard templates
3. Preserve custom sections in generated output
4. Merge with generated content
5. Note preserved sections in summary
### Command Verification
For quality gates and common commands:
1. Test commands with `--help` or `--version` (non-destructive)
2. Verify exit codes (0 = success)
3. If command fails: mark with "(verify: command not found)" in output
4. User can fix after generation
### Pattern Adaptation
When including patterns:
1. Read pattern file
2. Replace generic placeholders with project specifics:
- [Project] → actual project name
- [Command] → actual command from project
- [OutputType] → actual output format from answers
3. Adapt examples to project domain
4. Keep pattern structure intact
5. Add project-specific customization notes
---
## Error Handling
**If auto-detection fails:**
- Show detected indicators
- Ask user to select type manually via AskUserQuestion
- Proceed with selected type
**If package files missing:**
- Infer from directory structure
- Ask user for key details (language, framework)
- Note gaps in summary
**If commands untestable:**
- Include in output with verification note
- List in "Next Steps" for user to verify
**If no patterns match:**
- Select type-default patterns (minimum 2)
- Note in summary: "Used default patterns for {type}"
**If template file missing:**
- Fall back to generic template structure
- Note in summary: "Generated generic structure"
- Suggest creating custom template
---
## Extension Points
Users can extend skill by:
1. **Adding project types:** Create new template in `templates/`
2. **Adding patterns:** Create new pattern in `patterns/`
3. **Adding question frameworks:** Create new framework in `questions/`
4. **Customizing templates:** Edit existing templates for conventions
5. **Improving detection:** Update auto-detection rules in this file
See `customization-guide.md` for details.
---
## Quality Principles
**Concrete over generic:**
- "Run pytest" not "Run tests"
- "ruff check ." not "Run linter"
- Actual directory names not "source code directory"
**Actionable over descriptive:**
- Step-by-step workflows not "handle this area"
- Specific commands not "use the build tool"
- Concrete examples not "see documentation"
**Self-contained over referential:**
- Complete instructions in CLAUDE.md
- No "see ~/.claude/CLAUDE.md" references
- No "ask your team" placeholders
**Extensible over rigid:**
- Clear how to add sections
- Pattern library for reuse
- Customization guide included
**Project-specific over universal:**
- Use actual project context
- Adapt patterns to domain
- Include project anti-patterns
1---2name: claude-md-gen3description: Generate project-specific CLAUDE.md files through codebase analysis, targeted questions, and pattern selection.4---5
6---
7name: claude-md-gen
8description: Generate project-specific CLAUDE.md with domain instructions, workflows, templates. Analyzes codebase, asks clarifying questions, produces tailored instructions.
9argument-hint: [project-path] [--type cli-tool|web-app|python-cli|research|api-service|library|mixed]
10allowed-tools: Read, Grep, Glob, Bash, AskUserQuestion, Write
11---
12
13# CLAUDE.md Generator Skill
14
15Generate project-specific CLAUDE.md files through codebase analysis, targeted questions, and pattern selection.
16
17## Critical Requirements
18
19- Analyze existing code structure before questions
20- Ask focused questions (max 5-7 per session)
21- Generate concrete, actionable instructions (no generic filler)
22- Include templates for common outputs
23- Provide extensibility patterns
24- No placeholders/TODOs in generated output
25- Self-contained instructions (no references to global ~/.claude/CLAUDE.md)
26
27---
28
29## Workflow Overview
30
31Five-phase generation process:
32
331. **Project Analysis** - Auto-detect type, extract context
342. **Clarifying Questions** - 5-7 targeted questions based on type
353. **Pattern Selection** - Choose 2-4 relevant reusable patterns
364. **Template Customization** - Generate tailored CLAUDE.md
375. **Verification** - Quality checks before output
38
39---
40
41## Phase 1: Project Analysis
42
43### Auto-Detection Logic
44
45Analyze codebase to determine project type:
46
47```text
48DETECTION RULES:
49
50research-knowledge:
51 IF content/ OR findings/ exists
52 IF PARA folders detected (0_Inbox, 1_Projects, 2_Areas, 3_Resources, 4_Archives)
53 IF .md files > 10 in root/subdirs
54 → research-knowledge
55
56python-cli:
57 IF pyproject.toml exists
58 IF click OR typer imports in main file
59 IF [tool.poetry] OR [tool.pdm] section
60 IF tests/ with pytest
61 → python-cli
62
63web-app:
64 IF package.json + astro.config.* exists
65 IF package.json + src/components/ + public/
66 IF package.json + vite.config OR webpack.config
67 → web-app
68
69cli-tool:
70 IF go.mod + cmd/ + main.go
71 IF Cargo.toml + src/main.rs + clap dependency
72 IF package.json + #!/usr/bin/env node in files
73 → cli-tool
74
75api-service:
76 IF go.mod + cmd/ + internal/ + (gin|echo|chi imports)
77 IF package.json + express|fastify|nest imports
78 IF pyproject.toml + (fastapi|flask) dependency
79 → api-service
80
81library:
82 IF lib/ exists AND no cmd/ or bin/
83 IF package.json + "main" field but no bin/
84 IF Cargo.toml with [lib] section
85 → library
86
87mixed:
88 IF multiple indicators (api + frontend, cli + lib)
89 → mixed
90
91FALLBACK:
92 IF ambiguous → ask user to select
93```text
94
95### Context Collection
96
97Gather for template customization:
98
99**From package files:**
100
101- Languages and versions
102- Frameworks and versions
103- Dependencies (testing, linting, etc.)
104- Scripts/tasks (build, test, lint)
105
106**From directory structure:**
107
108- Primary directories with purposes
109- Test organization
110- Documentation location
111- Configuration files
112
113**From existing files:**
114
115- README.md (project description, setup)
116- Existing CLAUDE.md (preserve custom sections)
117- Taskfile.yml / Makefile / mise.toml (commands)
118- .pre-commit-config.yaml / husky (hooks)
119- Linter configs (eslintrc, ruff.toml, golangci.yml)
120
121**Analysis steps:**
122
1231. Read package file(s): `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`
1242. Map directory structure: `ls -la` + glob for key directories
1253. Identify test framework: grep for imports, check dependencies
1264. Find linters/formatters: look for config files
1275. Extract commands: read Taskfile/Makefile/package.json scripts
1286. Check for existing conventions: read existing CLAUDE.md, pre-commit config
129
130**Store context:**
131
132```text
133project_context = {
134 "name": from directory or package file,
135 "type": detected type,
136 "languages": {lang: version},
137 "frameworks": {framework: version},
138 "testing": framework name,
139 "linting": [linter names],
140 "dependency_mgmt": tool name,
141 "directories": {path: purpose},
142 "commands": {task: command},
143 "hooks": [hook names],
144 "existing_claude_md": sections to preserve
145}
146```text
147
148---
149
150## Phase 2: Clarifying Questions
151
152Load question framework from `questions/{detected-type}-questions.md`.
153
154Ask 5-7 questions via AskUserQuestion tool based on project type.
155
156**Question categories:**
157
1581. Domain workflows (2-3 questions)
1592. Output formats (1-2 questions)
1603. Tool integrations (1-2 questions)
1614. Quality gates (1 question)
1625. Common pitfalls (1 question)
163
164**For mixed projects:** Combine questions from component types (max 7 total).
165
166**Store answers:**
167
168```text
169user_answers = {
170 "workflows": [workflow descriptions],
171 "output_formats": [format descriptions],
172 "tools": [tool integrations],
173 "quality_gates": [requirements],
174 "pitfalls": [common mistakes]
175}
176```text
177
178---
179
180## Phase 3: Pattern Selection
181
182Based on user answers, select 2-4 relevant patterns from `patterns/`.
183
184### Selection Matrix
185
186| User Need | Pattern File |
187|-----------|--------------|
188| "Quick filtering before deep work" | triage-workflows.md |
189| "Two-tier verification", "double-check", "validate" | cove-verification.md |
190| "Hard requirements", "must have", "criteria" | decision-matrices.md |
191| "Source attribution", "citations", "references" | citation-systems.md |
192| "Structured outputs", "JSON", "templates", "reports" | output-templates.md |
193| "Examples", "test cases", "worked examples" | few-shot-examples.md |
194
195### Priority by Project Type
196
197**research-knowledge:**
198
1991. output-templates.md (for note templates)
2002. citation-systems.md (for source attribution)
2013. triage-workflows.md (for inbox processing)
202
203**python-cli:**
204
2051. cove-verification.md (for TDD workflow)
2062. output-templates.md (for structured CLI outputs)
2073. few-shot-examples.md (for test fixtures)
208
209**web-app:**
210
2111. output-templates.md (for component templates if design system)
2122. decision-matrices.md (for A11y criteria)
213
214**cli-tool:**
215
2161. output-templates.md (for CLI output formats)
2172. decision-matrices.md (for input validation)
2183. few-shot-examples.md (for command examples)
219
220**api-service:**
221
2221. decision-matrices.md (for endpoint validation)
2232. cove-verification.md (for integration tests)
2243. citation-systems.md (for API docs)
225
226**library:**
227
2281. few-shot-examples.md (for usage examples)
2292. decision-matrices.md (for breaking change criteria)
2303. citation-systems.md (for API docs)
231
232**mixed:**
233
234- Select from all types based on components
235- Max 4 patterns total
236- Prioritize patterns mentioned in answers
237
238### Selection Logic
239
240```python
241selected_patterns = []
242
243# Check user answers for keywords
244if any(keyword in answers for keyword in ["filter", "quick", "triage", "screening"]):
245 selected_patterns.append("triage-workflows.md")
246
247if any(keyword in answers for keyword in ["verify", "double-check", "validate", "two-phase"]):
248 selected_patterns.append("cove-verification.md")
249
250if any(keyword in answers for keyword in ["requirements", "criteria", "must-have", "scoring"]):
251 selected_patterns.append("decision-matrices.md")
252
253if any(keyword in answers for keyword in ["sources", "citations", "references", "attribution"]):
254 selected_patterns.append("citation-systems.md")
255
256if any(keyword in answers for keyword in ["template", "format", "structure", "JSON", "report"]):
257 selected_patterns.append("output-templates.md")
258
259if any(keyword in answers for keyword in ["examples", "test cases", "fixtures", "samples"]):
260 selected_patterns.append("few-shot-examples.md")
261
262# Apply type-based priorities if < 2 patterns selected
263if len(selected_patterns) < 2:
264 selected_patterns.extend(type_priorities[project_type])
265
266# Limit to 4 patterns
267selected_patterns = selected_patterns[:4]
268```text
269
270---
271
272## Phase 4: Template Customization & Generation
273
274### Load Base Template
275
276From `templates/{type}.md`:
277
278- Single type: load one template
279- Mixed: merge relevant sections from multiple templates
280
281### Customization Steps
282
283**1. Replace placeholders:**
284
285```text
286[Project Name] → project_context["name"]
287[Tech Stack] → project_context["languages"] + project_context["frameworks"]
288[Directory Structure] → project_context["directories"]
289[Commands] → project_context["commands"]
290[Linter Name] → project_context["linting"]
291[Test Framework] → project_context["testing"]
292```text
293
294**2. Add domain-specific sections based on answers:**
295
296```text
297IF web-app + design system mentioned:
298 Add "Design System" section with breakpoints, components
299
300IF python-cli + shared utils mentioned:
301 Add "Shared Utilities" section with location, conventions
302
303IF research + note templates mentioned:
304 Add "Note Templates" section with actual templates
305
306IF api-service + auth mentioned:
307 Add "Authentication" section with method, middleware
308```text
309
310**3. Include selected patterns (2-4 from Phase 3):**
311
312For each pattern file:
313
314- Read pattern from `patterns/{name}.md`
315- Adapt examples to project context
316- Add as section in generated CLAUDE.md
317- Customize placeholders with project specifics
318
319**4. Generate output templates if applicable:**
320
321IF output_templates.md selected OR type requires it:
322
323- Create "Output Templates" section
324- Include 1-2 concrete examples with structure
325- Use project-specific metadata/fields
326- Show markdown formatting with sections
327
328**5. Add quality gate checklist:**
329
330```markdown
331## Quality Gates
332
333Before committing:
334
335- [ ] {linter_name} passes
336- [ ] {test_framework} tests pass
337- [ ] {hook_name} hooks pass (if hooks detected)
338- [ ] {additional_gates from user answers}
339
340Commands:
341```bash
342{actual commands from project_context["commands"]}
343```text
344
345```text
346
347**6. Add common commands:**
348
349```markdown
350## Common Commands
351
352```bash
353# {purpose from package.json script or Taskfile}
354{actual command}
355
356# {purpose}
357{actual command}
358```text
359
360```text
361
362**7. Add anti-patterns:**
363
364Combine:
365- Type-default anti-patterns from template
366- User-mentioned pitfalls from answers
367- Project-specific detected issues
368
369Format:
370```markdown
371## Anti-Patterns
372
373**AVOID:**
374
375- ❌ {specific pitfall 1}
376- ❌ {specific pitfall 2}
377- ❌ {specific pitfall 3}
378
379**REASON:** {why each is problematic}
380```text
381
382### Template Structure
383
384All generated CLAUDE.md files follow this structure:
385
386```markdown
387# {Project Name}
388
389{1-2 sentence description from README or inferred}
390
391## Project Structure
392
393```text
394
395{auto-generated from directory analysis}
396src/ - {purpose}
397tests/ - {purpose}
398docs/ - {purpose}
399
400```text
401
402## Tech Stack
403
404**Language:** {language + version}
405**Framework:** {framework + version}
406**Testing:** {test framework}
407**Linting:** {linters}
408**Dependency Mgmt:** {tool}
409
410## Development Workflow
411
412{Type-specific workflows - 2-3 most common tasks}
413
414### {Workflow 1: e.g., "Adding New Feature"}
415
4161. {Concrete step}
4172. {Concrete step}
4183. {Concrete step}
419
420### {Workflow 2: e.g., "Running Tests"}
421
4221. {Concrete step}
4232. {Concrete step}
424
425## {Domain-Specific Section 1}
426
427{Based on project type and user answers}
428
429## {Domain-Specific Section 2}
430
431{Based on project type and user answers}
432
433## Quality Gates
434
435{Generated from customization step 5}
436
437## Common Commands
438
439{Generated from customization step 6}
440
441## Output Templates
442
443{If applicable - generated from customization step 4}
444
445### {Template 1 Name}
446
447```markdown
448{Template structure with placeholders}
449```text
450
451## Anti-Patterns
452
453{Generated from customization step 7}
454
455## {Included Pattern 1}
456
457{Adapted from patterns/{name}.md}
458
459## {Included Pattern 2}
460
461{Adapted from patterns/{name}.md}
462
463## Extensibility
464
465To add sections as project evolves:
466
4671. Add heading in appropriate location
4682. Follow section structure above
4693. Keep concrete and actionable
4704. Include examples where helpful
471
472See `.claude/skills/claude-md-gen/customization-guide.md` for:
473
474- Adding new project types
475- Creating custom patterns
476- Updating as requirements change
477
478```text
479
480---
481
482## Phase 5: Verification & Output
483
484### Pre-Generation Checks
485
486**During analysis:**
487- [ ] At least 3 files read to understand structure
488- [ ] Package file(s) parsed correctly
489- [ ] Directory structure mapped
490- [ ] Existing conventions identified
491
492**During questions:**
493- [ ] Max 7 questions asked
494- [ ] Questions relevant to detected type
495- [ ] No generic questions
496- [ ] Answers captured for customization
497
498**During pattern selection:**
499- [ ] 2-4 patterns selected
500- [ ] Selection based on user needs
501- [ ] Patterns will be adapted (not copy-pasted)
502
503### Post-Generation Verification
504
505Load checklist from `checklist.md` and verify:
506
507**Technical accuracy:**
508- [ ] Language versions match package files
509- [ ] Framework versions correct
510- [ ] Directory paths accurate
511- [ ] Commands executable
512
513**Actionability:**
514- [ ] Workflows have concrete steps
515- [ ] Commands include actual syntax
516- [ ] Quality gates list actual tools
517- [ ] Output templates show structure
518
519**Specificity:**
520- [ ] No "TODO" or "Fill this in"
521- [ ] No placeholder text remaining
522- [ ] Anti-patterns specific to project
523- [ ] Examples use project context
524
525**Extensibility:**
526- [ ] Customization guide referenced
527- [ ] Clear how to add sections
528- [ ] Pattern library location noted
529
530**Completeness:**
531- [ ] All major project areas covered
532- [ ] Selected patterns included and adapted
533- [ ] Quality gates comprehensive
534- [ ] Common commands from actual project
535
536### Write CLAUDE.md
537
538**Location decision:**
539- Default: `CLAUDE.md` at project root
540- If `.claude/` exists: ask user if they want `.claude/CLAUDE.md` instead
541
542**Write file** with fully customized content.
543
544### Show Summary
545
546```markdown
547# Generated CLAUDE.md
548
549**Location:** {path}
550**Type:** {detected-type or mixed}
551**Patterns Included:** {list 2-4 patterns}
552
553## Sections Generated
554
5551. Project Structure (auto-generated from {source})
5562. Tech Stack ({languages/frameworks})
5573. {Domain Section 1}
5584. {Domain Section 2}
5595. Quality Gates ({linter names})
5606. Common Commands ({X commands from mise/make/npm})
5617. Output Templates ({Y templates} or "N/A")
5628. Anti-Patterns ({Z specific pitfalls})
5639. {Pattern 1 name}
56410. {Pattern 2 name}
565{11-12 if 3-4 patterns}
566
567## Next Steps
568
569- Review {Section X} for accuracy
570- Customize {Section Y} with additional details
571- Update anti-patterns as you discover new ones
572
573## Extensibility
574
575Add sections as project evolves. See .claude/skills/claude-md-gen/customization-guide.md for:
576- Adding new project type templates
577- Creating custom patterns
578- Adapting generated output as requirements change
579```text
580
581---
582
583## Supporting Files
584
585### File Locations
586
587**Templates:** `.claude/skills/claude-md-gen/templates/{type}.md`
588
589- web-app.md, cli-tool.md, python-cli.md, research-knowledge.md, api-service.md, library.md, mixed.md
590
591**Patterns:** `.claude/skills/claude-md-gen/patterns/{name}.md`
592
593- cove-verification.md, decision-matrices.md, triage-workflows.md, citation-systems.md, output-templates.md, few-shot-examples.md
594
595**Questions:** `.claude/skills/claude-md-gen/questions/{type}-questions.md`
596
597- web-app-questions.md, cli-tool-questions.md, python-cli-questions.md, research-questions.md, api-service-questions.md, library-questions.md, mixed-questions.md
598
599**Support:** `.claude/skills/claude-md-gen/`
600
601- checklist.md, customization-guide.md
602
603---
604
605## Implementation Notes
606
607### Mixed Project Handling
608
609When multiple type indicators detected:
610
6111. Identify all component types (e.g., api-service + web-app)
6122. Load relevant sections from each template
6133. Merge into cohesive structure:
614 - Project Structure: combined view
615 - Tech Stack: all languages/frameworks
616 - Workflows: primary workflows from each component
617 - Domain sections: one per component type
6184. Ask questions from multiple frameworks (max 7 total)
6195. Select patterns from all component priorities
620
621### Preserving Existing Sections
622
623If existing CLAUDE.md detected:
624
6251. Parse existing file for custom sections
6262. Note sections not in standard templates
6273. Preserve custom sections in generated output
6284. Merge with generated content
6295. Note preserved sections in summary
630
631### Command Verification
632
633For quality gates and common commands:
634
6351. Test commands with `--help` or `--version` (non-destructive)
6362. Verify exit codes (0 = success)
6373. If command fails: mark with "(verify: command not found)" in output
6384. User can fix after generation
639
640### Pattern Adaptation
641
642When including patterns:
643
6441. Read pattern file
6452. Replace generic placeholders with project specifics:
646 - [Project] → actual project name
647 - [Command] → actual command from project
648 - [OutputType] → actual output format from answers
6493. Adapt examples to project domain
6504. Keep pattern structure intact
6515. Add project-specific customization notes
652
653---
654
655## Error Handling
656
657**If auto-detection fails:**
658
659- Show detected indicators
660- Ask user to select type manually via AskUserQuestion
661- Proceed with selected type
662
663**If package files missing:**
664
665- Infer from directory structure
666- Ask user for key details (language, framework)
667- Note gaps in summary
668
669**If commands untestable:**
670
671- Include in output with verification note
672- List in "Next Steps" for user to verify
673
674**If no patterns match:**
675
676- Select type-default patterns (minimum 2)
677- Note in summary: "Used default patterns for {type}"
678
679**If template file missing:**
680
681- Fall back to generic template structure
682- Note in summary: "Generated generic structure"
683- Suggest creating custom template
684
685---
686
687## Extension Points
688
689Users can extend skill by:
690
6911. **Adding project types:** Create new template in `templates/`
6922. **Adding patterns:** Create new pattern in `patterns/`
6933. **Adding question frameworks:** Create new framework in `questions/`
6944. **Customizing templates:** Edit existing templates for conventions
6955. **Improving detection:** Update auto-detection rules in this file
696
697See `customization-guide.md` for details.
698
699---
700
701## Quality Principles
702
703**Concrete over generic:**
704
705- "Run pytest" not "Run tests"
706- "ruff check ." not "Run linter"
707- Actual directory names not "source code directory"
708
709**Actionable over descriptive:**
710
711- Step-by-step workflows not "handle this area"
712- Specific commands not "use the build tool"
713- Concrete examples not "see documentation"
714
715**Self-contained over referential:**
716
717- Complete instructions in CLAUDE.md
718- No "see ~/.claude/CLAUDE.md" references
719- No "ask your team" placeholders
720
721**Extensible over rigid:**
722
723- Clear how to add sections
724- Pattern library for reuse
725- Customization guide included
726
727**Project-specific over universal:**
728
729- Use actual project context
730- Adapt patterns to domain
731- Include project anti-patterns