/merge-rules:merge-rulesfrom merge-rules
Merges extract-rules output from multiple projects into a unified portable rule set, promoting shared .local.md patterns to Principles format.
Ships in merge-rules. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
/merge-rules # Merge using config file
/merge-rules --config <path> # Merge using specified config file
/merge-rules --dry-run # Show what would be merged without writing
Config file search order:
--config <path> argument.claude/merge-rules.local.md (project-level)~/.claude/merge-rules.local.md (user-level)File format: YAML frontmatter only (no markdown body).
---
# Source projects (each must have extract-rules output)
projects:
- ~/projects/frontend-app
- ~/projects/backend-api
- ~/projects/shared-lib
# Output directory (default: .claude/rules)
# Examples go to the sibling <output_dir>-extras (.claude/rules-extras)
output_dir: .claude/rules
# Rules directory within each project (default: .claude/rules)
rules_dir: .claude/rules
# Threshold for promoting .local.md patterns (default: 0.5 = majority)
# Examples: 3 projects → 2/3 needed, 4 projects → 3/4, 5 projects → 3/5
promote_threshold: 0.5
# Report language (default: ja)
language: ja
---
Examples directories (no configuration key). Examples live in a sibling of the rules directory: that path with any trailing / removed and -extras appended — {path}/{rules_dir}-extras for each source project, <output_dir>-extras for the output. Strip the trailing / before appending, or a configured .claude/rules/ yields .claude/rules/-extras. Collection takes each rule file's examples from the derived directory first and from the rule directory itself only when that misses, so a pre-split layout — examples still beside the rule files — is still collected; writing always targets the derived directory. merge-rules does not read extract-rules' examples_output_dir.
.claude/merge-rules.local.md or specify with --config."language resolution order: Skill config → Claude Code settings (~/.claude/settings.json → language field) → default japrojects must have at least 2 entriesrules_dirFor each project:
{path}/{rules_dir}/ and {path}/{rules_dir}-extras (derived per § Configuration's "Examples directories (no configuration key)" paragraph) — two listings per project, never a third. A missing -extras directory is the normal pre-split case: treat it as an empty listing rather than an error. Rule files are the .md and .local.md entries of the first listing; examples are the union of the *.examples.md entries of both, with -extras winning when the same relative sub-path appears in each. A project part-way through migration therefore contributes both its moved and its still-co-located exampleslanguages/*.md → portable principles (always merge). If the file also contains ## Project-specific patterns (hybrid format from split_output: false), treat patterns as promotion candidates (same as .local.md)frameworks/*.md → same as aboveintegrations/*.md → same as abovelanguages/*.local.md → promotion candidateframeworks/*.local.md → promotion candidateintegrations/*.local.md → promotion candidatelanguages/*.examples.md → example file (merge with rules)frameworks/*.examples.md → example file (merge with rules)integrations/*.examples.md → example file (merge with rules)project.md → skip (inherently project-specific)project.examples.md → skip (inherently project-specific)paths:) and body sections (## Principles, ## Project-specific patterns, ## Principles Examples, ## Project-specific Examples)Before merging, group files that refer to the same concept but have different names. This applies to .md, .local.md, and .examples.md files — a .md and its corresponding .local.md and .examples.md share the same normalization (e.g., rails-controller.md, rails-controller.local.md, and rails-controller.examples.md are normalized together with their rails-controllers.* variants).
rails-controller.md vs rails-controllers.md, rails-model.md vs rails-models.md). The rule tree and the examples tree mirror each other, so frameworks/ in either tree is the same position
controller / controllers)paths: frontmatter overlap)<framework>-<layer>)rails-controller.md + rails-controllers.md → rails-controllers.md")Once a pattern is promoted to a Principle (via Step 5), subsequent merge-rules runs preserve it through Step 4's principle deduplication, regardless of whether the original .local.md pattern still meets the promotion threshold. To demote or remove a promoted Principle, manually edit the org rules output.
For each unique (normalized) file name across projects (e.g., languages/typescript.md, integrations/rails-inertia.md):
## Principles sections:
paths: frontmatter: union of all path patterns, deduplicateFor each normalized category (e.g., languages/typescript, frameworks/rails-controllers, integrations/rails-inertia):
## Project-specific patterns from all projects — from .local.md files and from hybrid .md files that contain this section (see Step 2)-) semantically matches an existing principle name in the corresponding .md output (from Step 4). Use AI judgment for semantic equivalence (case-insensitive, synonyms).-)
useAuth() and useAuth() → { user, login, logout } refer to the same pattern)len(projects) * promote_threshold projects (i.e., strict majority when threshold = 0.5)## Principles in the corresponding normalized .md output:
`signature` - description → Principles format: Description (simplified signature)`useAuth() → { user, login, logout }` - auth hook interface → Auth hook interface (useAuth)`clean_bracket_params(:keyword)` - WAF付加のブラケット除去 → WAF付加のブラケット除去 (clean_bracket_params)`RefOrNull<T extends { id: string }> = T | { id: null }` - nullable refs → Nullable refs (RefOrNull<T>)For each normalized .examples.md file group:
### FP only)
## Principles Examples
### example headings to promoted patterns — do not rely solely on exact heading match### title uses the converted Principle name (from Step 5), not the original signature.examples.md file structure:# <Category> Rules - Examples
## Principles Examples
### <Principle name>
**Good:**
```<lang>
<example>
Bad:
<example>
- `###` titles must match the corresponding rule name in the merged output `.md` file. Do not rephrase
- No `paths:` frontmatter
- If no examples exist for any merged rule, skip generating the `.examples.md` file
### Step 6: Write Output
1. Check the output directories `output_dir` and `<output_dir>-extras` (derived per § Configuration's "Examples directories (no configuration key)" paragraph):
- If `--dry-run`: skip writing, show planned file list with contents summary, then go to Step 7
- If either exists and has files: warn and ask for confirmation before overwriting
- For either that does not exist: create with `mkdir -p`
2. Write merged files preserving directory structure:
- `<output_dir>/languages/<lang>.md`
- `<output_dir>-extras/languages/<lang>.examples.md` (if examples exist)
- `<output_dir>/frameworks/<framework>.md`
- `<output_dir>-extras/frameworks/<framework>.examples.md` (if examples exist)
- `<output_dir>/integrations/<framework>-<integration>.md`
- `<output_dir>-extras/integrations/<framework>-<integration>.examples.md` (if examples exist)
- Only `.md` and `.examples.md` files (no `.local.md` in output)
3. Output file format:
```markdown
---
paths:
- "**/*.ts"
- "**/*.tsx"
---
# TypeScript Rules
## Principles
- Immutability (spread, map/filter/reduce, const)
- Type safety (strict mode, explicit annotations, no any)
- Auth hook interface (useAuth)
.md contains only ## Principles (promoted patterns are converted and included here)## Principles section if no principles exist for this category.examples.md was generated, append a reference section at the end:
## Examples
When in doubt: <relative-path-to-examples-file>
The path is that examples file — <output_dir>-extras/<same relative sub-path>/<name>.examples.md — expressed relative to the rule file's own directory. With the default output_dir, languages/typescript.md gets ../../rules-extras/languages/typescript.examples.md.Display report using the project's directory name (last path component) as label. Report headers are always in English.
# Merge Rules Report
## Sources
- frontend-app (3 files)
- backend-api (2 files)
- shared-lib (4 files)
## File Name Normalization
- `rails-controller.md` + `rails-controllers.md` → `rails-controllers.md`
- `rails-model.md` + `rails-models.md` → `rails-models.md`
## Merge Results
| File | Sources | Principles | Promoted to Principles | Examples |
|------|---------|------------|------------------------|----------|
| languages/typescript.md | 3/3 | 5 | 2 | 7 |
| frameworks/react.md | 2/3 | 3 | 1 | 4 |
| integrations/rails-inertia.md | 2/3 | 2 | 0 | 2 |
**Principles** = total including promoted. **Examples** = total `###` entries in the output `.examples.md`.
## Promoted to Principles
- `useAuth()` → Auth hook interface (useAuth) - 3/3 projects
- `pathFor() + url()` → Path helpers (pathFor, url) - 2/3 projects
## Below Threshold (reference)
- `useCustomHook()` (typescript) - 1/3 (frontend-app only)
- `ApiClient.create()` (typescript) - 1/3 (backend-api only)
## Skipped
- project.md x3 (project-specific, skipped)
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub hiroro-work/claude-plugins --plugin merge-rulesOther plugins' skills for the same job