From rules-review
Extracts project-specific coding rules and domain knowledge from codebase, PRs, or conversations into structured markdown documentation for AI agents. Use for onboarding or after code reviews.
npx claudepluginhub hiroro-work/claude-plugins --plugin apply-rulesThis skill is limited to using the following tools:
Analyzes existing codebase to identify what Claude would get wrong without project-specific guidance, extracting coding rules and domain knowledge as structured markdown documentation for AI agents.
Applies organization-wide rules from merge-rules output to current project. Detects tech stack, merges Principles, cleans .local.md patterns, and fixes non-conforming files.
Generates tailored Development Principles for CLAUDE.md by auto-detecting project structure, monorepo setup, tech stack including TypeScript, React, Python, Django, and user preferences via interactive questions.
Analyzes multi-language projects (Java, Kotlin, TypeScript, Python, Rust, Go) to extract etalon classes, patterns, and layer-based architecture. Generates convention documents and rules in .claude/convention/.
Share bugs, ideas, or general feedback.
Analyzes existing codebase to identify what Claude would get wrong without project-specific guidance, extracting coding rules and domain knowledge as structured markdown documentation for AI agents.
/extract-rules # Extract rules from codebase (initial)
/extract-rules --update # Re-scan and add new patterns (preserve existing)
/extract-rules --restructure # Re-analyze, reorganize structure, merge existing rules
/extract-rules --from-conversation # Extract from current session (latest)
/extract-rules --from-conversation <session-id> # Extract from a specific session
/extract-rules --from-pr 123 # カレントリポのPR指定
/extract-rules --from-pr owner/repo#123 # 他リポのPR指定(URL形式も可)
/extract-rules --from-pr 100..110 # 範囲指定(カレントリポ)
/extract-rules --from-pr owner/repo#100..110 # 範囲指定(他リポ)
# 複数指定可(スペース区切り)→ 横断分析で組織重視の原則を検出
Settings file: extract-rules.local.md (YAML frontmatter only, no markdown body)
.claude/extract-rules.local.md (takes precedence)~/.claude/extract-rules.local.md| Setting | Default | Description |
|---|---|---|
target_dirs | ["."] | Analysis target directories |
exclude_dirs | [".git", ".claude"] | Exclude directories (in addition to .gitignore) |
exclude_patterns | [] | Exclude file patterns (e.g., *.generated.ts, *.d.ts) |
output_dir | .claude/rules | Output directory |
language | ja | Report language (e.g., ja) |
split_output | true | Separate Principles (.md) and patterns (.local.md) |
resolve_references | true | Resolve file references during restructure |
---
target_dirs:
- .
exclude_dirs:
- .git
- .claude
exclude_patterns:
- "*.generated.ts"
output_dir: .claude/rules
language: ja
split_output: true
resolve_references: true
---
Default (split_output: true):
.claude/rules/
├── languages/
│ ├── typescript.md # Principles only (portable)
│ ├── typescript.local.md # Project-specific patterns only
│ ├── typescript.examples.md # Examples for both (no auto-load)
│ └── ...
├── frameworks/
│ ├── react.md # Principles only (portable)
│ ├── react.local.md # Project-specific patterns only
│ ├── react.examples.md # Examples for both (no auto-load)
│ └── ...
├── project.md # Always single file (no split)
└── project.examples.md # Examples (no auto-load)
Principles (portable across projects) and Project-specific patterns (local) are separated by default. This enables organizational rule sharing and AI-driven merge across projects.
Hybrid mode (split_output: false):
.claude/rules/
├── languages/
│ ├── typescript.md # Principles + Project-specific patterns
│ └── typescript.examples.md # Examples (no auto-load)
├── frameworks/
│ ├── react.md # Principles + Project-specific patterns
│ └── react.examples.md # Examples (no auto-load)
├── project.md # Domain, architecture, conventions
└── project.examples.md # Examples (no auto-load)
Layered frameworks (Rails, Django, Spring, etc.): When a framework has distinct architectural layers, generate layer-specific files:
<framework>.md — Cross-layer rules (no paths: or broad scope)<framework>-<layer>.md — Layer-specific rules with scoped paths: (e.g., app/models/**).local.md counterpartsIntegration libraries (Inertia, Pundit, Devise, Turbo, etc.): When integration libraries are detected alongside a layered framework:
integrations/<framework>-<integration>.md — Integration-specific rulesintegrations/ directoryrender inertia: vs Laravel: Inertia::render()).local.md counterpartsExample output with integrations (split mode — each category also gets .examples.md):
.claude/rules/
├── languages/
│ ├── ruby.md / ruby.local.md / ruby.examples.md
├── frameworks/
│ ├── rails.md / rails.local.md / rails.examples.md
│ ├── rails-controllers.md / .local.md / .examples.md
│ └── rails-models.md / .local.md / .examples.md
├── integrations/
│ ├── rails-inertia.md / .local.md / .examples.md
│ └── rails-pundit.md / .local.md / .examples.md
├── project.md
└── project.examples.md
Format switching: Run --restructure after changing split_output setting to switch between split and hybrid formats.
Check arguments to determine mode:
--update → Update Mode (Step U1-U6)--restructure → Restructure Mode (Step R1-R5)--from-conversation [session-id] → Conversation Extraction Mode (Step C1-C5)--from-pr <number|owner/repo#number|range> [...] → PR Review Extraction Mode (Step P1-P5)Search for extract-rules.local.md:
.claude/extract-rules.local.md~/.claude/extract-rules.local.mdPriority:
Extract settings (target_dirs, exclude_dirs, exclude_patterns, output_dir, language, split_output, resolve_references) from the config file. See Configuration section above for defaults.
language resolution: skill config → Claude Code settings (~/.claude/settings.json language field) → default ja
Detect project language and framework:
1. Detect languages by config files (package.json, tsconfig.json, pyproject.toml, go.mod, Cargo.toml, Gemfile, pom.xml, etc.) and file extensions (.ts/.tsx, .py, .go, .rb, etc.)
2. Detect frameworks by their config files (e.g., next.config.*, playwright.config.*) and dependencies in package manifests.
3. Detect architectural layers (for layered frameworks):
If a framework has distinct layers with separate directories (e.g., Rails: app/models/, app/controllers/; Django: models.py, views.py), detect them for layer-specific rule files. Only split when corresponding directories actually exist.
4. Detect integration libraries (for layered frameworks):
Read references/integration-criteria.md for detection rules and classification criteria.
Output: List of detected languages, frameworks, architectural layers, and integration libraries
Collect target files for analysis:
git ls-files (respects .gitignore). If not a git repo, fall back to Glob with manual exclusions from settings.target_dirs, exclude_dirs, exclude_patterns, and detected language extensionsRead references/extraction-criteria.md before proceeding to understand the classification criteria. The core question for every pattern is: "Would Claude produce something different without knowing this?" — extract only what fills the gap between Claude's general knowledge and this project's actual conventions.
For each detected language, framework, and integration library:
1.5. Separate integration-specific patterns (for layered frameworks with integrations):
See references/integration-criteria.md "Pattern routing" section.
Classify each pattern (see references/extraction-criteria.md):
For general style patterns:
For project-specific patterns:
signature - brief context (2-5 words)Apply AI judgment to determine which patterns meet the extraction criteria (see references/extraction-criteria.md)
Determine appropriate detection methods based on language and project structure.
Also analyze non-code documentation:
Extract explicit coding rules and guidelines from these documents.
Deduplication check: Read any files under .claude/rules/ to build a set of already-documented rules. Rules extracted in Step 4 that overlap with these existing rules should be skipped to avoid duplication. Note: CLAUDE.md is NOT a deduplication source — rules should exist in .claude/rules/ even if also mentioned in CLAUDE.md, because rule files are portable across projects via merge-rules. This check applies to all modes (Full Extraction, Update, Conversation, PR Review).
Read references/security.md before generating output to ensure sensitive information is not included.
Check if output directory exists
--restructure to reorganize, --update to add new patterns, or delete the directory manually to start fresh."Generate rule files per category:
languages/<lang>.md for language-specific rulesframeworks/<framework>.md for framework-specific rulesproject.md for project-specific rules<framework>.md (cross-layer) + <framework>-<layer>.md per detected layer with scoped paths:references/integration-criteria.md "Output structure" section.By default (split_output: true): Generate 3 files per category (except project.md which gets 2):
<name>.md — ## Principles only (portable)<name>.local.md — ## Project-specific patterns only (local)<name>.examples.md — Examples for both (no paths: frontmatter, no auto-load)paths: frontmatter independently. Cross-layer files (<framework>.md) use no paths: or broad scope as they apply across all layers.When split_output: false: Generate single hybrid file per category with both sections.
Rule file format (hybrid example):
---
paths:
- "**/*.ts"
- "**/*.tsx"
---
# TypeScript Rules
## Principles
- FP only (no classes, pure functions, composition over inheritance)
- Strict null handling (no non-null assertions, explicit narrowing required)
- Barrel exports required (re-export from index.ts per directory)
## Project-specific patterns
- `RefOrNull<T extends { id: string }> = T | { id: null }` - nullable relationships
- `pathFor(page) + url()` - Page Object navigation pair
- `useAuthClient()` returns `{ user, login, logout }` - auth hook interface
Format guidelines:
For Principles section:
Principle name (hint1, hint2, hint3)For Project-specific patterns section:
`signature` - brief contextuseAuth() → { user, login, logout } (not full implementation)For .examples.md files: Read references/examples-format.md for file structure, Good/Bad contrast guidelines, and the reference section format. Each rule file with a corresponding .examples.md must end with a ## Examples reference section (see the reference for format). ### titles must match the corresponding rule name exactly — do not translate or rephrase.
paths patterns by category:
**/*.ts, **/*.tsx**/*.py**/*.tsx, **/*.jsxpaths: to layers where the integration is used
(e.g., Inertia in controllers: app/controllers/**)After generating all rule files, verify no sensitive information was included:
[0-9a-fA-F]{20,}[A-Za-z0-9+/=]{40,}(key|token|secret|password|credential)\s*[:=]\s*["'][^"']+(internal|staging|localhost:[0-9]+)API_KEY_REDACTED) and warn the userNote: This check applies to all modes that generate or update rule files (Full Extraction, Update, Restructure, Conversation Extraction). Also check .examples.md files — they contain actual code from the codebase and may include sensitive information.
Display analysis summary. See references/report-templates.md for format.
When --update is specified, re-scan the codebase and add new patterns while preserving existing rules.
Load settings from extract-rules.local.md (same as Step 1 in Full Extraction Mode)
Check if output directory exists (default: .claude/rules/)
split_output: true and hybrid files exist (.md files containing both ## Principles and ## Project-specific patterns): warn that hybrid files were found — recommend running --restructure to migrate to split formatsplit_output: false and .local.md files exist: warn that orphaned .local.md files were found — recommend deleting orphaned files manually or running --restructureLoad existing rule files to understand current rules (load <name>.md, <name>.local.md, and <name>.examples.md when split)
Execute Step 2-5 from Full Extraction Mode:
Before adding new rules, check existing project-specific patterns for staleness:
## Project-specific patterns sections:
split_output: true: from .local.md filessplit_output: false: from ## Project-specific patterns sections in .md files`symbol`), verify the symbol still exists in the codebase using Grep
`pathFor() + url()`), check each symbol individuallyThis prevents rule files from growing indefinitely as the codebase evolves.
For each extracted principle/pattern:
Check if already exists: Compare with existing rules (check both shared and local files if split_output: true)
.md file (use AI judgment: case-insensitive, synonyms). For example, `useAuth() → { user, login, logout }` - auth hook interface is a duplicate of Auth hook interface (useAuth) in ## Principles. Skip patterns that already exist as Principles.Preserve manual edits: Do not modify existing rules
## Principles section## Project-specific patterns sectionsplit_output: true: Principles go to <name>.md, patterns go to <name>.local.md. Create missing files with proper frontmatter.project.md: always append to the single file.examples.md: Follow the common generation procedure in references/examples-format.md to add examples for each new rule.Run Security Self-Check (same as Step 6.5) on new/updated files.
Report what was added per file. Also report any stale rules found in Step U3. See references/report-templates.md for format.
When --restructure is specified, re-analyze the codebase to determine the optimal file structure, then merge existing rule content into the new structure. Use this when the project has evolved (new frameworks, architectural changes), when split_output settings change, or after updating the extract-rules skill itself.
.md, .local.md, and .examples.md)Execute Step 2-5 from Full Extraction Mode to determine the ideal file structure.
Skip this step if resolve_references is false. Default is true.
Scan existing rule content (loaded in R1) for file references (Markdown links, text references like "See <path>", @path references), resolve them, extract rules from referenced files, and merge into the R1 snapshot. Rules from references are treated as existing rules (take priority on conflict in R4). See references/resolve-references.md for detailed processing steps.
Compare old and new file structures, display planned changes (Keep/New/Remove per file), and wait for user confirmation before proceeding. If references were resolved in R2.5, include the number of rules extracted from referenced files in the plan display so the user understands where additional rules came from.
project.md as fallback; preserve custom sections in the most relevant filesplit_output setting (handle hybrid ↔ split transitions), deduplicate.examples.md: Rename/merge .examples.md files following the same structure changes as rule files. Generate new .examples.md for categories that didn't have one (see references/examples-format.md).Run Security Self-Check (same as Step 6.5) on all generated files.
Report structural changes, content merge summary, unmatched rules, and reference resolution results. See references/report-templates.md for format.
When --from-conversation is specified, extract rules from the full conversation history stored in session .jsonl files. The heavy processing (jsonl parsing, analysis, rule writing) is delegated to a subagent to keep the main context clean.
Load settings from extract-rules.local.md (same as Step 1 in Full Extraction Mode)
Check if output directory exists (default: .claude/rules/)
Locate the session file:
pwd)/ and . with - (leading - is kept)
/Users/hiropon/Sources/github.com/myproject → -Users-hiropon-Sources-github-com-myproject~/.claude/projects/<encoded-path>/<session-id>.jsonlSelect the target session:
<session-id> argument is provided: use ~/.claude/projects/<encoded-path>/<session-id>.jsonl.jsonl file in the directory (by ls -t)
Spawn a subagent using the Agent tool. The subagent performs all heavy processing (C3–C5) and returns a summary of what was added. Read references/conversation-mode.md for the full subagent instructions (Steps C3–C5).
Include in the agent prompt:
split_output / language settingsreferences/conversation-mode.mdAfter the subagent completes, report the results to the user.
When --from-pr is specified, extract rules from PR review comments (human comments only).
Single or multiple PRs can be specified. Numbers and URLs can be mixed. Cross-repository PRs are allowed.
Read references/pr-review-mode.md for the full processing steps (P1-P5). Key flow:
gh CLI authentication)references/extraction-criteria.md).examples.md (same as Step C5)