Rule Extraction skill
Extracts a structured JSON list of behavioral rules from markdown files within a skill directory for conflict checking and merging.
- GitHub stars
- 42
- Files
- 1
- Last commit
- Apr 9, 2026
- License
- MIT
- Allowed tools
- —
What does the Rule Extraction skill do?
Rule Extraction extracts a structured JSON list of behavioral rules from markdown files within a skill directory for conflict checking and merging.
Summary generated from the skill's SKILL.md.
About the Rule Extraction skill
Parsing behavioral directives from markdown files is what this skill enables for developers managing agent instructions. It scans a specified skill directory to identify imperative directives, prohibitions, requirements, and conditional behaviors. By targeting top-level markdown files, it transforms unstructured text into a structured JSON array of rule objects. This process allows for automated conflict checking, merging, or diffing of agent behaviors.
An agent should load this tool when it needs to analyze a directory of rules to ensure consistency across multiple files. The skill processes SKILL.md and other markdown files in alphabetical order while intentionally skipping subdirectories, non-markdown files, YAML frontmatter, and code blocks. Each extracted rule includes a sequential ID, the filename, the specific line number, the cleaned text, the original source text, and a flag for vague statements. This structured output helps distinguish between actionable mandates and descriptive context or examples.
What an agent can do with it
- 1Check for conflicting agent instructionsIdentify if different markdown files in a skill directory contain contradictory behavioral rules.
- 2Merge multiple rule setsCombine behavioral mandates from several markdown files into a single structured JSON list.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the Rule Extraction skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the Rule Extraction skill in Plugin
/plugin marketplace add KnowledgeXLab/skill-git /plugin install skill-git@knowledgexlab
Install the Rule Extraction skill in Claude Code
~/.claude/skills/Rule-Extraction/SKILL.md
$ npx degit KnowledgeXLab/skill-git/skills/rule-extraction ~/.claude/skills/Rule-ExtractionInstall the Rule Extraction skill in Claude Code (project)
.claude/skills/Rule-Extraction/SKILL.md
$ npx degit KnowledgeXLab/skill-git/skills/rule-extraction .claude/skills/Rule-ExtractionInstall the Rule Extraction skill in Codex
~/.agents/skills/Rule-Extraction/SKILL.md
$ npx degit KnowledgeXLab/skill-git/skills/rule-extraction ~/.agents/skills/Rule-ExtractionInstall the Rule Extraction skill in Gemini CLI
~/.gemini/skills/Rule-Extraction/SKILL.md
$ npx degit KnowledgeXLab/skill-git/skills/rule-extraction ~/.gemini/skills/Rule-ExtractionInstall the Rule Extraction skill in Claude.ai
npx degit KnowledgeXLab/skill-git/skills/rule-extraction Rule-Extraction && zip -r Rule-Extraction.zip Rule-Extraction # claude.ai → Customize → Skills → + → Create skill → Upload a skill → Rule-Extraction.zip
SKILL.md
View on GitHubRule Extraction
This skill teaches you how to extract a structured, line-numbered list of rules from a skill directory.
What Counts as a Rule
A rule is any statement that prescribes or constrains agent behavior. Recognize rules by their form:
- Imperative directives: "Always add type annotations", "Never use
var" - Prohibition patterns: "Do not X", "Avoid X", "禁止 X"
- Requirement patterns: "Must X", "Should X", "需要 X", "必须 X"
- Conditional behavior: "If X, then Y", "When X, do Y"
- Style/format mandates: "Use camelCase", "Limit lines to 80 characters"
- Preference statements: "Prefer X over Y", "优先使用 X"
Rules can appear as:
- Bullet list items (
-or*or+) - Numbered list items (
1.,2.) - Bold or emphasized sentences (
**Always do X**) - Plain sentences within a paragraph that contain directive language
- Section headers that are themselves imperatives ("Never commit secrets")
What Does NOT Count as a Rule
Exclude the following from extraction:
- Descriptive text: Explanations of why a rule exists, background context
- Examples: Code blocks, sample outputs, "for example..." passages
- Metadata: YAML frontmatter, version info, author notes
- Headings that introduce a section (unless the heading itself is an imperative rule)
- Vague non-actionable statements: "Do good work", "Be helpful" — extract these but flag them as
vague: true
Output Format
Return a JSON array. Each rule is an object:
[
{
"id": 1,
"file": "SKILL.md",
"line": 12,
"text": "Always add type annotations to function parameters",
"source_text": "- Always add type annotations to function parameters",
"vague": false
},
{
"id": 2,
"file": "SKILL.md",
"line": 15,
"text": "Do not use var, prefer const or let",
"source_text": "**Do not use `var`** — prefer `const` or `let`",
"vague": false
},
{
"id": 3,
"file": "examples.md",
"line": 4,
"text": "Do good work",
"source_text": "- Do good work",
"vague": true
}
]
Field definitions:
id: Sequential integer starting from 1, across all files combinedfile: Filename (basename only, e.g.SKILL.md,examples.md) where the rule appearsline: Line number within that file where the rule appears (1-indexed)text: Cleaned rule text, stripped of markdown formattingsource_text: Original raw line as it appears in the filevague:trueif the rule is too broad to be actionable
Input Scope
The input is a skill directory path (e.g. ~/.claude/skills/humanizer/).
Files to read: all *.md files directly inside the skill directory — SKILL.md first, then any other *.md files in alphabetical order.
Files to skip:
- Subdirectories and any files inside them (no recursive scan)
- Non-markdown files (
.sh,.py,.js,.json, etc.)
Extraction Process
- List all
*.mdfiles at the top level of the skill directory (non-recursive). ReadSKILL.mdfirst if present; read remaining*.mdfiles in alphabetical order. - For each file, read it line by line, tracking line numbers within that file.
- Skip frontmatter (everything between
---delimiters at the top of each file) - Skip code blocks (between
```fences) — these are examples, not rules - For each line, determine if it contains a rule using the criteria above
- For paragraph text: split into sentences, check each sentence independently
- Clean the extracted text: remove markdown syntax (
-,*,**, backticks) but preserve the meaning - Assign line numbers based on where the rule text starts within its file
- Record the source filename for every rule
Handling Ambiguous Cases
- Compound bullet: "Use camelCase and limit lines to 80 chars" → split into two rules, both on the same line number
- Nested bullets: Treat each nested item as an independent rule
- Conditional rules: Keep the full conditional ("If Python, use type hints") as one rule — do not split on the condition
- Negated rules: "Don't use X" and "Never use X" are equivalent — normalize to a consistent form in
text, preserve original insource_text
Example
Input skill directory: ~/.claude/skills/code-style/
Files found at top level: SKILL.md, extra-rules.md
(Any subdirectory contents are ignored.)
SKILL.md:
---
name: Code Style
---
# Code Style Guidelines
Keep code clean and maintainable.
## Naming
- Use camelCase for variables and functions
- Use PascalCase for classes and types
- Never use single-letter variable names except for loop indices
## Comments
Always write comments in English.
Do not write comments explaining what the code does — only explain why.
## Example
\`\`\`python
# good
def calculate_total(items):
return sum(items)
\`\`\`
extra-rules.md:
- Prefer explicit returns over implicit ones
Output:
[
{
"id": 1,
"file": "SKILL.md",
"line": 10,
"text": "Use camelCase for variables and functions",
"source_text": "- Use camelCase for variables and functions",
"vague": false
},
{
"id": 2,
"file": "SKILL.md",
"line": 11,
"text": "Use PascalCase for classes and types",
"source_text": "- Use PascalCase for classes and types",
"vague": false
},
{
"id": 3,
"file": "SKILL.md",
"line": 12,
"text": "Never use single-letter variable names except for loop indices",
"source_text": "- Never use single-letter variable names except for loop indices",
"vague": false
},
{
"id": 4,
"file": "SKILL.md",
"line": 15,
"text": "Always write comments in English",
"source_text": "Always write comments in English.",
"vague": false
},
{
"id": 5,
"file": "SKILL.md",
"line": 16,
"text": "Do not write comments explaining what the code does — only explain why",
"source_text": "Do not write comments explaining what the code does — only explain why.",
"vague": false
},
{
"id": 6,
"file": "extra-rules.md",
"line": 1,
"text": "Prefer explicit returns over implicit ones",
"source_text": "- Prefer explicit returns over implicit ones",
"vague": false
}
]
Notes:
- SKILL.md lines 18–23 (the code block) are skipped entirely
idis sequential across all files;lineresets to 1 for each new file- Any subdirectories inside
~/.claude/skills/code-style/are not scanned
Files in this skill
1Rule Extraction skill questions
How do I install the Rule Extraction skill in Claude Code?
Run npx degit KnowledgeXLab/skill-git/skills/rule-extraction ~/.claude/skills/Rule-Extraction. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the Rule Extraction skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
What qualifies as a rule during extraction?
A rule is any statement that prescribes or constrains agent behavior, such as imperative directives, prohibitions, requirements, or conditional behaviors.
Which files are included in the extraction process?
The skill reads all markdown files directly inside the skill directory, processing SKILL.md first followed by other markdown files in alphabetical order.
Does the skill scan subdirectories?
No, the extraction is non-recursive and ignores subdirectories and any files contained within them.
How are code blocks handled?
Code blocks are skipped during extraction because they are considered examples rather than rules.