hiroro-work/claude-plugins/apply-rules
Claude Code and agent skill by hiroro-work/claude-plugins
- community
Checking that the SKILL.md file is still in the repository.
Apply organization-wide rules (from merge-rules output) to the current project. Detects tech stack, merges Principles, cleans up promoted patterns from .local.md, and fixes non-conforming files.
Install
npx vskill@latest install hiroro-work/claude-plugins/apply-rulesSKILL.md
Apply Rules
Usage
<source> points directly to the rules directory (merge-rules or extract-rules output):
- GitHub:
https://github.com/org/repo/tree/main/.claude/rules - Local:
~/org-rules/.claude/rules
Configuration
Config file search order:
--config <path>argument.claude/apply-rules.local.md(project-level)~/.claude/apply-rules.local.md(user-level)
File format: YAML frontmatter only (no markdown body).
CLI argument <source> overrides the config's source field.
Examples directory (no configuration key). .examples.md files live in a sibling of the rules directory: that path with any trailing / removed and -extras appended — <output_dir>-extras in the target project, <source>-extras on the source side, .claude/rules-extras/ under the default output_dir. Reading takes each rule file's examples from the derived directory first and from the rule file's own directory only when that misses, so a pre-split layout — examples still beside the rule files — is still picked up; writing always targets the derived directory. apply-rules does not read extract-rules' examples_output_dir.
Processing Flow
Step 1: Load Configuration
- If CLI
<source>argument provided, use it (overrides configsource) - Search for config file (see search order above)
- Parse YAML frontmatter, apply defaults for omitted fields
- `language` resolution order: Skill config → Claude Code settings (
~/.claude/settings.json→languagefield) → defaultja
- Validate:
sourcemust be specified (via CLI argument or config file)- If neither: Error "No source specified. Provide a GitHub URL or local path as argument, or create
.claude/apply-rules.local.mdwith asource:field."
Step 2: Fetch Source Rules
If source is a local path:
- Expand
~and resolve to absolute path - Verify directory exists and contains rule files (
.md) - Read directly from this location
If source is a GitHub URL:
Parse URL to extract owner, repo, branch, and path:
https://github.com/{owner}/{repo}/tree/{branch}/{path}- Example:
https://github.com/org/repo/tree/main/.claude/rules
→ owner: org, repo: repo, branch: main, path: .claude/rules
Note on ambiguous refs: Branch names may contain / (e.g., feature/rules-v2), and refs can also be tags or SHAs:
- Try ref candidates from the longest prefix first:
gh api repos/{owner}/{repo}/git/ref/heads/{candidate}, thengh api repos/{owner}/{repo}/git/ref/tags/{candidate}; for a SHA-shaped candidate usegh api repos/{owner}/{repo}/commits/{candidate} - A successful response is a match: stop there, use the candidate as
{branch}and the remaining segments as{path}. A 404 (git/ref) or 422 (commits) means no match — try the next shorter prefix. Any other error, or no candidate matching, stops with an error suggestingsource_repo/source_ref/source_path - Alternatively, the user can specify components separately in the config:
``yaml source_repo: org/repo source_ref: feature/rules-v2 source_path: .claude/rules `` When these fields are present, they take precedence over URL parsing.
- For the common case (branch =
mainormaster), simple URL parsing works.
Fetch using gh api:
- Verify authentication:
gh auth status - Create temp directory:
mktemp -d - List top-level directory contents:
`` gh api repos/{owner}/{repo}/contents/{path}?ref={branch} ` For each entry with type: "dir", recursively fetch subdirectory contents: ` gh api repos/{owner}/{repo}/contents/{path}/{subdir}?ref={branch} ` This dynamically discovers all categories (not limited to languages/, frameworks/, integrations/`).
- For each
.mdfile found, fetch content and decode:
`` gh api repos/{owner}/{repo}/contents/{file_path}?ref={branch} --jq '.content | @base64d' ` Save under <tmpdir>/rules/, preserving the directory structure below {path}`
- Repeat items 3-4 (the recursive directory listing and the per-file content fetch) for
{path}-extras, saving under<tmpdir>/rules-extras/. A404on the listing means this source keeps no separate examples directory — skip it silently.<source>for the rest of this Step is<tmpdir>/rules, so<source>-extrasresolves to<tmpdir>/rules-extras - Temp dir is cleaned up in Step 8 (Cleanup)
Inventory source files:
- Glob for
**/*.mdunder<source>— the result includes any.examples.mda pre-split source kept beside its rule files - Glob for
**/*.examples.mdunder<source>-extras. A missing<source>-extrasis the normal pre-split case: treat it as an empty listing rather than an error - A rule file's examples are the
<name>.examples.mdat the same relative sub-path, with<source>-extraswinning over a co-located copy from the first glob - Skip
project.mdandproject.examples.md(inherently project-specific) - Skip
.local.mdfiles (merge-rules output should not contain these, but handle gracefully) - Parse each file: extract YAML frontmatter (
paths:) and body sections
Step 3: Detect Target Project Tech Stack
Analyze the current working directory to determine which source rules are relevant. Detection is best-effort, based on dependency files (e.g., Gemfile, package.json) and project directory structure (e.g., app/controllers/).
Read references/detection-heuristics.md for the full detection table mapping indicators to rule files. If the source contains rule files not covered in the table, use AI judgment to match them against the project's dependencies and file structure.
Apply overrides:
- Add
include:entries to the detected set - Remove
exclude:entries from the detected set - If
auto_detect: false: start with ALL source rules, then applyexcludeonly
Step 4: Filter and Propose
If `auto_detect: false`: Apply ALL source rules (minus exclude entries). Skip the proposal step entirely — no integration proposals or skipped rules. Proceed directly to Step 5.
If `auto_detect: true` (default):
- Auto-matched rules: Rules that match detected tech stack → apply automatically
- Integration proposals: For integrations NOT detected in the project but related to a detected framework (e.g., source has
integrations/rails-punditbut project doesn't usepundit), useAskUserQuestionto present them as a single list:
> The following integration rules are available in the source but were not detected in your project. Which would you like to apply? > 1. integrations/rails-pundit — Authorization library Pundit rules > 2. integrations/rails-good-job — Job queue GoodJob rules > > Options: all / none / specify by number (e.g. "1" or "1,2")
Apply only those the user approves.
- Skipped rules: Rules for tech not detected and not in related frameworks → skip, list in report
Step 5: Inventory Existing Target Rules
- Check if
{output_dir}/exists in the target project - If exists, list
{output_dir}/**/*.md— which includes any co-located.examples.md— and<output_dir>-extras/**/*.examples.md. A missing<output_dir>-extrasis the normal pre-split case: treat it as an empty listing rather than an error - Read each rule file (the
.mdand.local.mdentries of the first listing) and resolve its examples per § Configuration's "Examples directory (no configuration key)" paragraph: the<name>.examples.mdat the same relative sub-path, with a trailing.localdropped from the rule file's basename (languages/ruby.local.md→languages/ruby.examples.md). Read each resolved examples file once — a.mdand its.local.mdresolve to the same one. Every later step reads target examples through this resolution - Parse frontmatter and body sections for each
- Categorize files the same way as source files
- Detect hybrid format: If any target
.mdfile contains## Project-specific patterns(hybrid format from extract-rulessplit_output: false), note this. The merge step will convert hybrid to split format
Step 5.5: Normalize File Names
Before merging, align target file names with source (canonical) names.
- Compare target file names against source file names within the same category
- Detect naming variants: singular/plural (
controller/controllers), minor differences for the same concept - If renames are detected, use
AskUserQuestionto confirm:
> The following target files will be renamed to match source (canonical) names: > 1. frameworks/rails-controller.md → frameworks/rails-controllers.md > > Options: all / none / specify by number
- Apply approved renames and report in the summary
Step 6: Merge Rules
For each filtered source rule file, determine the merge action:
6a. Merge `.md` files (Principles):
Case: No existing `.md`
- Copy source
.mdas-is (source from merge-rules contains only## Principles)
Case: Existing `.md` exists
- `paths:` frontmatter: Union of all path patterns, deduplicate
- Hybrid → split conversion: If existing
.mdcontains## Project-specific patterns(hybrid format):
- Extract that section and move to
.local.md(create if not exists, append if exists) - Remove the section from
.md, keeping only## Principles
- `## Principles`:
- Match principles by name (text before parenthetical hints)
- Source principle not in target → Add
- Target principle not in source → Keep (project may have added its own)
- Same principle, same meaning but different hints → Union hints from both
- Same principle name but different content → Collect all conflicts, then use
AskUserQuestionto present them together:
> The following principles differ between org rules and project rules: > > 1. Immutability (in languages/ruby.md) > - Org: Immutability (spread, map/filter/reduce, const) > - Project: Immutability (freeze, deep clone, readonly) > > 2. Error handling (in frameworks/rails.md) > - Org: Error handling (rescue, custom exceptions) > - Project: Error handling (rescue, retry, circuit breaker) > > For each, choose: (a) Adopt org rule / (b) Keep project rule / (c) Keep both > Example: "1a, 2c" or "all a"
6b. Clean up promoted patterns from `.local.md` files:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/apply-rules/SKILL.md
Popularity
- Repository stars
- 47
- Repository forks
- 3
- 7-day trend score
- 19
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hiroro-work/claude-plugins/apply-rules)