From claude-factory
Scaffold a Claude Code rule (.claude/rules/) from a natural language description. Use when creating project rules, coding standards, or path-scoped instructions. Triggers on /factory:rule.
npx claudepluginhub lingelo/marketplace-claude-code --plugin claude-factoryThis skill is limited to using the following tools:
Official specification: @../../references/rule-spec.md
Guides creation of .claude/rules/ files for path-scoped project conventions using TDD workflow: RED (test gaps), GREEN (write rule), REFACTOR (optimize). Triggers on 'add rule', 'create convention', 'scope guideline'.
Guides authoring rule files in .claude/rules/ for project conventions including formatting, testing, commits, architecture, and referencing from CLAUDE.md.
Guides authoring .claude/rules/*.md files for auto-applied constraints scoped by file patterns. Use when creating or updating rules for code conventions and quality standards.
Share bugs, ideas, or general feedback.
Official specification: @../../references/rule-spec.md
/factory:rule "description of the rule"
/factory:rule my-rule "description of the rule"
Extract name + description from $ARGUMENTS. If empty, ask: "What rule should Claude follow? Describe it in natural language."
Check if the target rule already exists:
ls -la .claude/rules/<rule-name>.md 2>/dev/null
Determine:
| Indicator | Scope | Example |
|---|---|---|
| General coding standard | Global (no paths) | "Always use 2-space indentation" |
| Mentions specific directories | Path-scoped | "In src/api/, validate all inputs" |
| Mentions file types | Path-scoped | "For .tsx files, use functional components" |
| Project-wide convention | Global | "Use conventional commits" |
| Framework-specific | Path-scoped | "In Rails controllers, use strong params" |
Convert the description to glob patterns:
"src/api/**/*" (inspect actual project structure)"**/*.ts" or "**/*.{ts,tsx}""test/**/*" or "**/*.test.*" (inspect actual project structure)When possible, check the actual project structure to determine the right paths:
ls -d */ 2>/dev/null # top-level dirs
The rule should be:
Use AskUserQuestion to resolve ambiguities — only if the description leaves key decisions unclear. Skip this step if the description is precise enough.
Ask only what is unresolved:
.tsx files, I recommend path-scoped. Should this rule be path-scoped or global?")Do not ask questions whose answers are obvious from the description.
Rules always go to .claude/rules/ — they are project-level, not plugin-level.
# Ensure rules directory exists
ls -la .claude/rules/ 2>/dev/null
Target: .claude/rules/<rule-name>.md
For user-level rules: ~/.claude/rules/<rule-name>.md (only if user explicitly wants a global rule)
ls -la .claude/rules/<rule-name>.md 2>/dev/null
If exists: show error, suggest alternative name. Do not overwrite.
Create .claude/rules/<rule-name>.md:
If path-scoped:
---
paths:
- "<pattern-1>"
- "<pattern-2>"
---
# <Rule Title>
<Rule content — specific, verifiable instructions>
If global (no paths):
# <Rule Title>
<Rule content — specific, verifiable instructions>
Rule content guidelines:
Rule created: <rule-name>
Location: .claude/rules/<rule-name>.md
Scope: <global | path-scoped to: pattern1, pattern2>
Loaded: <every session | when Claude reads matching files>
Tip: Run /factory:audit .claude/rules/<rule-name>.md to validate.
Triggered when Step 2 detects the rule already exists.
Read the existing rule file and parse its frontmatter (paths) and body content.
Display to the user:
Existing rule: <rule-name>
Location: .claude/rules/<rule-name>.md
Scope: <global | path-scoped to: pattern1, pattern2>
---
<current rule content>
Use AskUserQuestion: "What would you like to change? (e.g., rule content, scope, path patterns, or add/remove instructions)"
Edit the existing file with the requested changes. Use the Edit tool to make targeted modifications, not a full rewrite.
Rule updated: <rule-name>
Location: .claude/rules/<rule-name>.md
Scope: <global | path-scoped to: pattern1, pattern2>
Changes: <summary of what was modified>
Tip: Run /factory:audit .claude/rules/<rule-name>.md to validate.