Rule create

From Alexander-M-Dickerson/ai-asset-pricing · View interactive version

Rule create is an AI agent skill from the GitHub repository Alexander-M-Dickerson/ai-asset-pricing. Creates new .claude/rules/ files following best practices, or audits existing rules for quality and effectiveness.

How to use this skill

Skill file

Rule Creator & Auditor

Two modes: Create a new rule or Audit an existing one.

Examples

Mode Selection

Parse $ARGUMENTS:


CREATE MODE

Four phases: Gather → Draft → Write → Verify.

Phase 1: Gather Context

1a. Scan existing rules

List all files in .claude/rules/ to understand what rules already exist. This prevents creating duplicates and helps identify the right scope.

1b. Ask the user

If $ARGUMENTS contains a topic description (anything beyond new), use it as the domain. Otherwise, use AskUserQuestion with all of the following:

  1. Domain: What does this rule cover? (e.g., database patterns, security, API conventions, testing, writing style, deployment)
  2. Scope: What file types or paths should trigger this rule? Give glob patterns (e.g., **/*.py, src/api/**/*.ts) or say "always load" if it applies everywhere.
  3. Key constraints: What are the 3-5 most important things Claude must know or do when this rule applies? Be specific — concrete patterns, not abstract goals.
  4. Bad patterns: Are there specific anti-patterns or mistakes Claude should avoid? (optional but valuable)

1c. Check for overlap

Compare the user's answers against existing rules. If there's significant overlap with an existing rule, warn the user and ask whether to:

Phase 2: Draft

2a. Choose a template

Based on the domain, select the best body pattern from the reference:

| Domain Type | Template Pattern | Best For |

|------------|-----------------|----------|

| Code conventions | Quick Reference + Sections | Naming, formatting, architecture patterns |

| Security / correctness | Do / Don't / Why / Refs | Vulnerability prevention, data integrity |

| Writing / style | Banned/Required + Examples | Prose style, documentation standards |

| Data / schema | Schema + Query + Gotchas | Database conventions, data pipelines |

2b. Generate the rule

Build the rule file with these requirements:

Frontmatter:

---
description: [Specific, keyword-rich — Claude uses this to assess relevance]
paths:      # Omit entirely if the rule should always load
  - "[glob patterns from user input]"
---

Description quality check:

Scope-gating decision (paths: field):

| Rule type | Scope | Rationale |

|-----------|-------|-----------|

| File conventions (naming, docstrings, formatting) | paths: ["**/*.py"] | Only relevant when editing those files |

| Workflow behavior (always save results, always use turnover=True) | Unscoped (omit paths:) | Must be active even during ad-hoc script execution |

| API gotchas (parameter validation, common mistakes) | Unscoped | Needed whenever writing API calls, not just editing source |

Key lesson: Path-scoped rules are invisible when the LLM isn't editing files matching those globs. If a rule governs behavior (not just file conventions), it must be unscoped.

Body:

Filename:

2c. Print the draft

Show the complete rule to the user before writing. Ask if they want changes.

Phase 3: Write

Write the file to .claude/rules/{name}.md using the Write tool.

Print confirmation:

Rule created: .claude/rules/{name}.md
Lines: {count}
Path scope: {paths or "always loaded"}

Phase 4: Verify

Run the full audit checklist (from Audit Mode below) against the newly created rule. Report results inline. If any checks fail, offer to fix them immediately.


AUDIT MODE

Three phases: Read → Analyze → Report.

Phase 1: Read

Phase 2: Analyze

Run 10 checks against the rule file. For each, determine PASS, WARN, or FAIL.

1. Focus

Does the rule cover one coherent topic?

2. Length

Count total lines (including frontmatter and blank lines).

3. Frontmatter Quality

4. Actionability

Does the rule contain concrete, implementable guidance?

5. Duplication

Does the rule repeat content from CLAUDE.md or other rule files?

6. Procedure Leak

Does the rule contain step-by-step workflows that belong in a skill?

7. Tool Overlap

Does the rule duplicate what linters, formatters, or CI already enforce?

8. Front-Loading

Are the most important rules near the top?

9. Example Quality

Do examples clearly show the right patterns?

10. Completeness

Is anything obviously missing for this domain?

Phase 3: Report

Print the structured report:

RULE AUDIT REPORT
=================

File: {path}
Lines: {count}
Domain: {detected domain}
Path scope: {paths from frontmatter, or "always loaded"}

CHECKLIST:
[PASS] Focus: {brief explanation}
[WARN] Length: {line count} lines — {explanation}
[PASS] Frontmatter: {brief explanation}
[FAIL] Actionability: {brief explanation with specific section references}
[PASS] Duplication: {brief explanation}
[PASS] No procedures: {brief explanation}
[PASS] No tool overlap: {brief explanation}
[WARN] Front-loading: {brief explanation}
[PASS] Examples: {brief explanation}
[PASS] Completeness: {brief explanation}

SUGGESTIONS:
1. {Specific, actionable suggestion with section reference}
2. {Another suggestion}
3. ...

OVERALL: {N}/10 passed, {W} warnings, {F} failures

After printing the report, offer to fix any FAIL or WARN items if the user wants.

For all mode, after all individual reports, print a summary table:

SUMMARY: {N} rules audited
==============================
| Rule                   | Pass | Warn | Fail |
|------------------------|------|------|------|
| academic-writing       |   9  |   1  |   0  |
| latex-citations        |  10  |   0  |   0  |
| latex-compile          |   9  |   0  |   1  |
| latex-conventions      |  10  |   0  |   0  |
| presentation-rules     |   9  |   1  |   0  |

Communication Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.