Rules Generation
Overview
Generate project-specific coding rules from a confirmed technology stack. This skill produces .claude/rules/ files that use YAML frontmatter paths for conditional loading, ensuring rules only appear in context when Claude works on matching files. Rules focus on code quality and best practices, consolidating related concerns into fewer, deeper files rather than many fragmented ones.
Target output: 4–5 consolidated rule files for a typical single-language, single-framework project.
Prerequisites
- A confirmed tech stack document (output of the
tech-stack-confirmation skill), typically at docs/architecture/YYYY-MM-DD-<topic>-tech-stack.md
- ADR documents at
docs/architecture/adr/
- An existing
.claude/rules/ directory (global rules may already exist)
Scope Boundary
This skill covers coding rules generation ONLY:
- In scope: Reading tech stack artifacts, selecting applicable rule categories, generating consolidated rule files with
paths scoping, deduplication with existing global rules, user review
- Out of scope: Technology selection (use
tech-stack-confirmation), project scaffolding (use project-architecture-init), requirements gathering (use requirement-analysis)
If the user attempts to revisit technology selection decisions during this process, redirect: "That's a technology choice — the tech stack is already confirmed. To revise, re-run the tech-stack-confirmation skill."
The Process
Phase 1: Artifact Discovery — Locate All Inputs
Goal: Locate and read all tech stack artifacts produced by tech-stack-confirmation.
Execution rules:
- Search for the confirmed tech stack document at
docs/architecture/*-tech-stack.md
- Search for ADR documents at
docs/architecture/adr/ADR-*.md or docs/architecture/adr/*-ADR-*.md
- Search for NFR summary if available in
docs/architecture/ or inline in the tech stack document
- Scan existing
.claude/rules/ directory (both ~/.claude/rules/ and project-level) to identify global rules already in place
- Read the project's
CLAUDE.md file (if exists) for global instructions that affect rule generation
Phase 1 output: A summary listing:
- Tech stack document path and detected technologies (language, framework, database, testing, DevOps)
- ADR count and their titles
- Existing global rules already defined
Present this summary to the user for confirmation before proceeding.
Phase 2: Rule Selection — Determine Consolidated Rules
Goal: Based on the confirmed tech stack, determine which consolidated rule files to generate.
Method: Read references/rules-catalog.md for the consolidated rule category catalog and selection algorithm.
Execution rules:
- Apply the selection algorithm from the catalog:
- Always generate (max 1 always-loaded):
git-conventions.md
- Per language (1 file): Select the consolidated language best-practices file
- Per framework (1 file): Select the consolidated framework best-practices file; include security, caching, logging, API/MCP design as sections within it
- Per testing stack (1 file): Generate
testing-best-practices.md
- Per build/DevOps (1 file): Generate
build-and-devops.md if build tools, Docker, or CI/CD are in the stack
- Cross-check with existing
.claude/rules/ files — if a global rule already covers a topic, mark it as "skip (covered by global rule: <filename>)"
- For each selected rule file, note:
- File name and
paths glob patterns
- Primary technologies and versions it applies to
- ADR reference(s) tracing back to the decision
- Sections to include (consolidated from the catalog)
Phase 2 output: A rule generation plan table:
| # |
Rule File |
Paths |
Technologies |
ADR Refs |
Status |
| 1 |
git-conventions.md |
(always loaded) |
Git |
— |
To Generate |
| 2 |
java-best-practices.md |
**/*.java |
Java 21 |
ADR-001 |
To Generate |
| 3 |
spring-boot-best-practices.md |
src/main/**/*.java |
Spring Boot 3.x, ... |
ADR-002, ... |
To Generate |
| 4 |
testing-best-practices.md |
src/test/**/*.java |
JUnit 5, ... |
ADR-007 |
To Generate |
| 5 |
build-and-devops.md |
pom.xml, Dockerfile*, ... |
Maven, Docker, ... |
ADR-008, ... |
To Generate |
Present this plan to the user for confirmation. The user may:
- Remove rules they consider unnecessary
- Add custom rule categories
- Adjust scope, paths, or priority
Proceed only after user approval.
Phase 3: Rule Generation — Write Rule Files
Goal: Generate each approved rule file with concrete, actionable, version-specific content using the Claude Code .claude/rules/ format.
Method: Read references/rule-file-template.md for the standard rule file structure with YAML frontmatter.
Execution rules:
- Generate rules one file at a time, presenting each to the user for review before proceeding to the next
- For each rule file:
a. Follow the template structure from
references/rule-file-template.md
b. Include YAML frontmatter with paths for path-scoped rules, or omit for always-loaded rules
c. Include the ADR reference header linking the rule to the technology decision
d. Write Mandatory Rules (M-NNN) — non-negotiable best practices for the specific technology and version
e. Write Recommended Rules (R-NNN) — strong suggestions with documented rationale
f. Include DO/DON'T code examples in the project's primary language for every mandatory rule
g. Add a Checklist section for pre-commit verification
- Write each approved rule file to the project's
.claude/rules/ directory
- Respect existing global rules:
- Never overwrite files in
~/.claude/rules/ (user's global rules)
- Project-level rules go to
<project-root>/.claude/rules/
- If a project-level rule overlaps with a global rule, add a reference:
> Extends global rule: ~/.claude/rules/<filename>
- Content constraints:
- All code examples, log messages, and exception messages must use English (per project global rule)
- No hardcoded magic values — use named constants with environment variable support (per project global rule)
- Every rule must be concrete and actionable, not vague platitudes
- Prefer quantifiable thresholds over subjective guidance
Interaction model:
- Present ONE rule file at a time
- Allow the user to approve, modify, or reject each rule file
- If rejected, revise based on feedback and re-present
Phase 3 output: Complete set of rule files written to .claude/rules/.
Phase 4: Integration & Summary — Ensure Consistency
Goal: Verify all generated rules are consistent with each other and with existing global rules, then present a final summary.
Execution rules:
- Cross-check all generated rule files for contradictions (e.g., one rule mandates a pattern another forbids)
- Verify all ADR references are valid
- Verify all
paths patterns are correct and non-overlapping where it matters
- Check that existing global rules (from
~/.claude/rules/ and project CLAUDE.md) are not contradicted by new rules
- If conflicts are found, present them to the user for resolution
Phase 4 output: A final summary report:
- Rules generated — count and file paths with their
paths scoping
- Rules skipped — count and reasons (covered by global rules)
- Technologies covered — list of all technologies with corresponding rule files
- ADR coverage — verify every ADR has at least one corresponding rule file
- Global rule compatibility — confirm no conflicts with existing global rules
- Recommended next steps — suggest running
project-architecture-init if not yet done
Key Principles
- Consolidated files — merge related concerns into one file per domain (4–5 files total, not 15+)
- Paths-scoped — every rule file uses YAML frontmatter
paths unless truly cross-cutting; this prevents all rules from loading into context simultaneously
- Code quality focus — prioritize coding standards, error handling, and best practices over operational/infra rules
- One rule file at a time — never present all rules simultaneously; allow user review per file
- Version-specific — rules must reference the exact technology version from the tech stack, not generic advice
- ADR-traceable — every rule file must link back to the ADR that confirmed the technology
- No duplication — check existing global rules before generating; reference rather than repeat
- Concrete over vague — "method body must not exceed 30 lines" beats "keep methods short"
- DO/DON'T examples — mandatory rules require both correct and incorrect code examples
- English code artifacts — all code, logs, and exceptions in generated rules use English
- Incremental validation — present each phase output to the user before proceeding
Resources
references/
rules-catalog.md — Consolidated rule category catalog organized by technology domain, with the selection algorithm for determining which rules to generate and paths patterns for each category
rule-file-template.md — Standard template structure for generated rule files using Claude Code YAML frontmatter format, including paths glob pattern reference and content guidelines
1---2name: rules-generation3description: Use after the tech-stack-confirmation skill has been completed and a confirmed tech stack document exists. This skill reads the confirmed tech stack, ADRs, and NFR documents, then generates project-specific coding rules (.claude/rules/*.md files) with YAML frontmatter `paths` scoping, based on the best practices of each selected technology. It produces 4–5 consolidated rule files focused on code quality and best practices. It should be triggered when a user asks to 'generate project rules', 'create coding standards', 'set up code quality rules', 'generate rules from tech stack', or 'create best-practice rules'. It should NOT be used for technology selection (use tech-stack-confirmation instead) or for detailed system design.4---5
6# Rules Generation
7
8## Overview
9
10Generate project-specific coding rules from a confirmed technology stack. This skill produces `.claude/rules/` files that use YAML frontmatter `paths` for conditional loading, ensuring rules only appear in context when Claude works on matching files. Rules focus on **code quality and best practices**, consolidating related concerns into fewer, deeper files rather than many fragmented ones.
11
12**Target output**: 4–5 consolidated rule files for a typical single-language, single-framework project.
13
14## Prerequisites
15
16- A confirmed tech stack document (output of the `tech-stack-confirmation` skill), typically at `docs/architecture/YYYY-MM-DD-<topic>-tech-stack.md`
17- ADR documents at `docs/architecture/adr/`
18- An existing `.claude/rules/` directory (global rules may already exist)
19
20## Scope Boundary
21
22This skill covers **coding rules generation** ONLY:
23- **In scope**: Reading tech stack artifacts, selecting applicable rule categories, generating consolidated rule files with `paths` scoping, deduplication with existing global rules, user review
24- **Out of scope**: Technology selection (use `tech-stack-confirmation`), project scaffolding (use `project-architecture-init`), requirements gathering (use `requirement-analysis`)
25
26If the user attempts to revisit technology selection decisions during this process, redirect: "That's a technology choice — the tech stack is already confirmed. To revise, re-run the `tech-stack-confirmation` skill."
27
28## The Process
29
30### Phase 1: Artifact Discovery — Locate All Inputs
31
32**Goal**: Locate and read all tech stack artifacts produced by `tech-stack-confirmation`.
33
34**Execution rules**:
351. Search for the confirmed tech stack document at `docs/architecture/*-tech-stack.md`
362. Search for ADR documents at `docs/architecture/adr/ADR-*.md` or `docs/architecture/adr/*-ADR-*.md`
373. Search for NFR summary if available in `docs/architecture/` or inline in the tech stack document
384. Scan existing `.claude/rules/` directory (both `~/.claude/rules/` and project-level) to identify global rules already in place
395. Read the project's `CLAUDE.md` file (if exists) for global instructions that affect rule generation
40
41**Phase 1 output**: A summary listing:
42- Tech stack document path and detected technologies (language, framework, database, testing, DevOps)
43- ADR count and their titles
44- Existing global rules already defined
45
46Present this summary to the user for confirmation before proceeding.
47
48### Phase 2: Rule Selection — Determine Consolidated Rules
49
50**Goal**: Based on the confirmed tech stack, determine which **consolidated** rule files to generate.
51
52**Method**: Read `references/rules-catalog.md` for the consolidated rule category catalog and selection algorithm.
53
54**Execution rules**:
551. Apply the selection algorithm from the catalog:
56 - **Always generate** (max 1 always-loaded): `git-conventions.md`
57 - **Per language** (1 file): Select the consolidated language best-practices file
58 - **Per framework** (1 file): Select the consolidated framework best-practices file; include security, caching, logging, API/MCP design as sections within it
59 - **Per testing stack** (1 file): Generate `testing-best-practices.md`
60 - **Per build/DevOps** (1 file): Generate `build-and-devops.md` if build tools, Docker, or CI/CD are in the stack
612. Cross-check with existing `.claude/rules/` files — if a global rule already covers a topic, mark it as "skip (covered by global rule: `<filename>`)"
623. For each selected rule file, note:
63 - File name and `paths` glob patterns
64 - Primary technologies and versions it applies to
65 - ADR reference(s) tracing back to the decision
66 - Sections to include (consolidated from the catalog)
67
68**Phase 2 output**: A rule generation plan table:
69
70| # | Rule File | Paths | Technologies | ADR Refs | Status |
71|---|-----------|-------|-------------|----------|--------|
72| 1 | `git-conventions.md` | (always loaded) | Git | — | To Generate |
73| 2 | `java-best-practices.md` | `**/*.java` | Java 21 | ADR-001 | To Generate |
74| 3 | `spring-boot-best-practices.md` | `src/main/**/*.java` | Spring Boot 3.x, ... | ADR-002, ... | To Generate |
75| 4 | `testing-best-practices.md` | `src/test/**/*.java` | JUnit 5, ... | ADR-007 | To Generate |
76| 5 | `build-and-devops.md` | `pom.xml`, `Dockerfile*`, ... | Maven, Docker, ... | ADR-008, ... | To Generate |
77
78Present this plan to the user for confirmation. The user may:
79- Remove rules they consider unnecessary
80- Add custom rule categories
81- Adjust scope, paths, or priority
82
83Proceed only after user approval.
84
85### Phase 3: Rule Generation — Write Rule Files
86
87**Goal**: Generate each approved rule file with concrete, actionable, version-specific content using the Claude Code `.claude/rules/` format.
88
89**Method**: Read `references/rule-file-template.md` for the standard rule file structure with YAML frontmatter.
90
91**Execution rules**:
921. Generate rules **one file at a time**, presenting each to the user for review before proceeding to the next
932. For each rule file:
94 a. Follow the template structure from `references/rule-file-template.md`
95 b. **Include YAML frontmatter with `paths`** for path-scoped rules, or omit for always-loaded rules
96 c. Include the ADR reference header linking the rule to the technology decision
97 d. Write **Mandatory Rules** (M-NNN) — non-negotiable best practices for the specific technology and version
98 e. Write **Recommended Rules** (R-NNN) — strong suggestions with documented rationale
99 f. Include **DO/DON'T code examples** in the project's primary language for every mandatory rule
100 g. Add a **Checklist** section for pre-commit verification
1013. Write each approved rule file to the project's `.claude/rules/` directory
1024. Respect existing global rules:
103 - Never overwrite files in `~/.claude/rules/` (user's global rules)
104 - Project-level rules go to `<project-root>/.claude/rules/`
105 - If a project-level rule overlaps with a global rule, add a reference: `> Extends global rule: ~/.claude/rules/<filename>`
1065. Content constraints:
107 - All code examples, log messages, and exception messages must use English (per project global rule)
108 - No hardcoded magic values — use named constants with environment variable support (per project global rule)
109 - Every rule must be concrete and actionable, not vague platitudes
110 - Prefer quantifiable thresholds over subjective guidance
111
112**Interaction model**:
113- Present ONE rule file at a time
114- Allow the user to approve, modify, or reject each rule file
115- If rejected, revise based on feedback and re-present
116
117**Phase 3 output**: Complete set of rule files written to `.claude/rules/`.
118
119### Phase 4: Integration & Summary — Ensure Consistency
120
121**Goal**: Verify all generated rules are consistent with each other and with existing global rules, then present a final summary.
122
123**Execution rules**:
1241. Cross-check all generated rule files for contradictions (e.g., one rule mandates a pattern another forbids)
1252. Verify all ADR references are valid
1263. Verify all `paths` patterns are correct and non-overlapping where it matters
1274. Check that existing global rules (from `~/.claude/rules/` and project `CLAUDE.md`) are not contradicted by new rules
1285. If conflicts are found, present them to the user for resolution
129
130**Phase 4 output**: A final summary report:
131
1321. **Rules generated** — count and file paths with their `paths` scoping
1332. **Rules skipped** — count and reasons (covered by global rules)
1343. **Technologies covered** — list of all technologies with corresponding rule files
1354. **ADR coverage** — verify every ADR has at least one corresponding rule file
1365. **Global rule compatibility** — confirm no conflicts with existing global rules
1376. **Recommended next steps** — suggest running `project-architecture-init` if not yet done
138
139## Key Principles
140
141- **Consolidated files** — merge related concerns into one file per domain (4–5 files total, not 15+)
142- **Paths-scoped** — every rule file uses YAML frontmatter `paths` unless truly cross-cutting; this prevents all rules from loading into context simultaneously
143- **Code quality focus** — prioritize coding standards, error handling, and best practices over operational/infra rules
144- **One rule file at a time** — never present all rules simultaneously; allow user review per file
145- **Version-specific** — rules must reference the exact technology version from the tech stack, not generic advice
146- **ADR-traceable** — every rule file must link back to the ADR that confirmed the technology
147- **No duplication** — check existing global rules before generating; reference rather than repeat
148- **Concrete over vague** — "method body must not exceed 30 lines" beats "keep methods short"
149- **DO/DON'T examples** — mandatory rules require both correct and incorrect code examples
150- **English code artifacts** — all code, logs, and exceptions in generated rules use English
151- **Incremental validation** — present each phase output to the user before proceeding
152
153## Resources
154
155### references/
156- `rules-catalog.md` — Consolidated rule category catalog organized by technology domain, with the selection algorithm for determining which rules to generate and `paths` patterns for each category
157- `rule-file-template.md` — Standard template structure for generated rule files using Claude Code YAML frontmatter format, including `paths` glob pattern reference and content guidelines