rule-creator
Skill0 starsChanged 8 months agoMITView on GitHub
Create, maintain, audit, remove, improve, and optimize Claude Code project rules (.md files in .claude/rules/). Trigger for: "create a rule", "add a coding standard as a Claude rule", "audit my rules", "delete/remove a rule", "this rule isn't working", "improve a rule", "optimize this rule", or references to .claude/rules/ and project coding standards. Do NOT trigger for creating skills (use skill-creator), editing CLAUDE.md directly, or general code review without rule context.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- adeonir/agent-skillstheir own version, first seen Oct 13, 2026
- bazel-contrib/rules_pythontheir own version, first seen Oct 8, 2026
- bis-code/claude-toolkittheir own version, first seen May 29, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- bazel-contrib/rules_python★ 692same name
- adeonir/agent-skills★ 8same name
- bis-code/claude-toolkit★ 8same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
28 rules. About 0 are common, 15 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Audit: all rules for quality, conciseness, and overlap
- Very specific: line 59
All script commands below are run from the repository root and cd into the skill directory as needed.
- Very specific: line 71
Check existing rules for overlap (run cd .claude/skills/rule-creator && python3 -m scripts.audit_rules)
- Distinctive: line 72
Read existing rules in the same path scope to check for semantic contradictions (the audit script catches keyword overlap but not …
- Distinctive: line 73
Check CLAUDE.md for conflicting directives — rules and CLAUDE.md are both loaded, and contradictions cause unpredictable behavior
- Very specific: line 74
Read references/best-practices.md for writing guidelines
- Distinctive: line 75
If the rule targets a specific codebase area, read existing files to understand conventions
- Distinctive: line 76
If the user wants deterministic enforcement (e.g., "never allow X"), suggest a hook instead of a rule — rules are advisory, hooks are hard …
- Distinctive: line 77
If the user's need involves a multi-step workflow with scripts or agents, suggest using skill-creator instead — rules are for directives, …
- Very specific: line 78
Consider @path/to/file import syntax in CLAUDE.md as an alternative to duplicating large content into a rule
- Very specific: line 94
Follow these principles from references/best-practices.md:
- Very specific: line 100
Naming: use kebab-case for rule filenames (e.g., error-handling.md, import-ordering.md).
- Very specific: line 123
Put results in .claude/skills/rule-creator-workspace/ (a sibling to the skill directory).
- Very specific: line 131
Baseline run (without_rule): After the with-rule run completes, back up the rule file (cp rule.md rule.md.bak), remove it, execute the same …
- Very specific: line 133
Write eval_metadata.json for each test case with the prompt and expectations.
- Very specific: line 144
When each subagent completes, save timing.json with total_tokens, duration_ms, and total_duration_seconds.
- Very specific: line 167
Read feedback.json from the workspace.
- Distinctive: line 175
When improving a rule based on eval results, think carefully — rules get applied across many conversations, so small improvements compound.
- Distinctive: line 183
Look for repeated work across test cases: Read the transcripts and notice if the subagents all independently took the same multi-step …
- Distinctive: line 185
Test negative cases: Ensure the rule doesn't trigger where it shouldn't.
- Distinctive: line 187
Always explain what you changed and why: When fixing anti-patterns or improving rules, tell the user what the problem was and how your …
- Very specific: line 191
Before deleting a rule, check whether other rules reference it (e.g., via references/ pointers or overlap notes).
- Distinctive: line 195
Run a full audit of all project rules (from the repository root):
- Distinctive: line 207
Budget guidance: Keep unconditional rules as small as possible — they consume context on every conversation.
- Very specific: line 209
Use --include-user-rules to also scan ~/.claude/rules/ for user-level rules.
- Distinctive: line 217
Ask for feedback inline: "How does this look?
- Distinctive: line 237
Follow the Core Workflow phases (above) in order.
- Distinctive: line 243
Add these to your TodoList (if you have one).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rule Creator
A skill for creating, maintaining, and evaluating Claude Code project rules.
Overview
This skill handles the full lifecycle of project rules:
- Create new rules with proper frontmatter and structure
- Validate rule files for correctness
- Audit all rules for quality, conciseness, and overlap
- Test rule effectiveness via eval cases
- Improve rules based on eval results
- Package rules for sharing via PR
Rule Frontmatter
Rules live in .claude/rules/ (native to Claude Code). Frontmatter is optional and controls when a rule activates. The only valid frontmatter field is paths:.
Unconditional rules (no frontmatter)
Rules without frontmatter are loaded at the start of every conversation, with the same priority as .claude/CLAUDE.md. Use sparingly — they consume context budget on every query. Keep them short.
Path-targeted rules
---
paths:
- "lib/**/*.py"
- "src/**/*.ts"
---The rule activates only when Claude reads files matching the glob patterns (not on every tool use). This is where most rules should live — they only cost context when relevant. Brace expansion is supported (e.g., "src/**/*.{ts,tsx}").
Choosing the right mode
- Applies to specific file types/paths? → Add
paths:frontmatter - Must Claude always follow this regardless of files? → No frontmatter (unconditional)
- Not sure? → Start with
paths:targeting and broaden to unconditional if needed
Note:
alwaysApply:anddescription:are not valid frontmatter fields for.claude/rules/files. These fields are for skills (SKILL.md), not rules. If you encounter them in a rule file, remove them — use no frontmatter for unconditional rules, orpaths:for scoped rules.
User-Level and Shared Rules
~/.claude/rules/— Personal rules applied to every project (e.g., communication preferences, editor style).claude/rules/— Project rules shared via git (team conventions, project-specific patterns)- Symlinks — Symlink files into
.claude/rules/to share rules across projects without duplication @path/to/file— Use import syntax in CLAUDE.md to reference larger docs instead of inlining them
Core Workflow
All script commands below are run from the repository root and cd into the skill directory as needed.
Phase 1: Capture Intent
Understand what the user wants the rule to enforce:
- What behavior should Claude follow (or avoid)?
- Which files does this apply to? (path patterns)
- Is this Claude-specific or a universal standard?
- Are there examples of the correct vs incorrect behavior?
Phase 2: Interview & Research
- Check existing rules for overlap (run
cd .claude/skills/rule-creator && python3 -m scripts.audit_rules) - Read existing rules in the same path scope to check for semantic contradictions (the audit script catches keyword overlap but not conflicting directives)
- Check CLAUDE.md for conflicting directives — rules and CLAUDE.md are both loaded, and contradictions cause unpredictable behavior
- Read
references/best-practices.mdfor writing guidelines - If the rule targets a specific codebase area, read existing files to understand conventions
- If the user wants deterministic enforcement (e.g., "never allow X"), suggest a hook instead of a rule — rules are advisory, hooks are hard gates
- If the user's need involves a multi-step workflow with scripts or agents, suggest using skill-creator instead — rules are for directives, skills are for workflows
- Consider
@path/to/fileimport syntax in CLAUDE.md as an alternative to duplicating large content into a rule
Proactive Warnings
When you encounter anti-patterns — whether in an existing rule you're fixing, a user request that would create one, or during an audit — always explain the problem to the user before fixing it. Don't silently correct issues. The user needs to understand why something is wrong so they can avoid repeating it. Key anti-patterns to flag:
- Unrecognized frontmatter fields (e.g.,
alwaysApply,description) — not valid for.claude/rules/files - Unconditional 100+ line rule → context bloat on every conversation
- Rules that duplicate linter/CI checks → wasted tokens on already-enforced standards
- Multiple overlapping rules → consolidate to reduce context cost
- Rules contradicting CLAUDE.md directives → unpredictable behavior
A one-sentence explanation is enough — e.g., "This rule has alwaysApply: true in frontmatter, but that's not a valid field for rules — I'll remove the frontmatter so it loads unconditionally."
Phase 3: Write the Rule
Follow these principles from references/best-practices.md:
- Lead with the action: "Use X when Y"
- Give concrete examples: one good example beats three paragraphs
- Explain the why: Claude follows reasoned instructions better than mandates
- Stay concise: unconditional rules should be kept minimal since every conversation pays the cost. Path-targeted rules have more room since they only load when relevant
- Don't duplicate linters: trust your project's linters
- Naming: use kebab-case for rule filenames (e.g.,
error-handling.md,import-ordering.md). If a rule already exists for the topic, prefer updating it over creating a new one.
Phase 4: Validate
Run validation:
cd .claude/skills/rule-creator && python3 -m scripts.quick_validate <rule-file>Note: Frontmatter is optional for .claude/rules/ files.
Phase 5: Test (Optional)
For important rules, create eval cases and run the evaluation pipeline. See "Running and Evaluating Test Cases" below.
Phase 6: Iterate
Review the rule, check for overlap with existing rules, and iterate based on feedback.
Running and Evaluating Test Cases
This follows a 5-step process:
Put results in .claude/skills/rule-creator-workspace/ (a sibling to the skill directory). Organize by iteration (iteration-1/, iteration-2/, etc.).
Step 1: Spawn runs (with_rule AND baseline)
For each test case, use the Agent tool to spawn two subagents. Important: run them sequentially, not in parallel. The baseline agent temporarily removes the rule file, which would corrupt the with-rule run if both ran simultaneously. Run the with-rule agent first, then the baseline:
With-rule run: Execute the task with the rule active. The rule is already in place in .claude/rules/. Save to with_rule/outputs/.
Baseline run (without_rule): After the with-rule run completes, back up the rule file (cp rule.md rule.md.bak), remove it, execute the same task, then restore it (mv rule.md.bak rule.md). Save to without_rule/outputs/.
Write eval_metadata.json for each test case with the prompt and expectations.
Step 2: Draft expectations
Good expectations for rules:
- "Claude follows the rule's directive without being explicitly asked"
- "The rule does NOT activate for unrelated file types" (negative test)
- "The rule doesn't cause unwanted side effects on the output"
Step 3: Capture timing data
When each subagent completes, save timing.json with total_tokens, duration_ms, and total_duration_seconds.
Step 4: Grade, aggregate, and launch the viewer
- Grade each run — use
agents/grader.md. Save tograding.jsonwithtext,passed,evidencefields. - Aggregate:
cd .claude/skills/rule-creator && python3 -m scripts.aggregate_benchmark <workspace>/iteration-N --rule-name <rule-name> - Analyze — read benchmark data and surface patterns per
agents/analyzer.md. - Launch viewer:
For iteration 2+, addcd .claude/skills/rule-creator && nohup python3 eval-viewer/generate_review.py \ <workspace>/iteration-N \ --rule-name "<rule-name>" \ --benchmark <workspace>/iteration-N/benchmark.json \ > /dev/null 2>&1 & VIEWER_PID=$!--previous-workspace <workspace>/iteration-<N-1>to show diffs.
Step 5: Read feedback and iterate
Read feedback.json from the workspace. Empty feedback for a run means it looked fine. Kill the viewer when done:
kill $VIEWER_PID 2>/dev/nullImprove the rule based on feedback, rerun into iteration-<N+1>/.
Improving Rules
When improving a rule based on eval results, think carefully — rules get applied across many conversations, so small improvements compound.
- Generalize from the feedback. The user is iterating on a few examples, but the rule will be used thousands of times across many prompts. Rather than adding fiddly fixes for specific test cases, try to understand why the model failed and address the underlying cause. If you find yourself writing heavy-handed MUSTs, step back and explain the reasoning instead — Claude follows reasoned instructions better than arbitrary mandates.
- Keep the rule lean. Read the eval transcripts, not just outputs. If the rule is making the model waste time on unproductive steps, cut those parts. Every token in a rule competes for context budget across all conversations. A 50-token rule that achieves 80% of the effect is often better than a 200-token rule at 90%.
- Check for over-application. Rules can bleed into unrelated contexts in ways skills don't. Does the rule cause unwanted changes to files outside its intended scope? Does it activate for file types it shouldn't? Path targeting (
paths:globs) is your main defense. - Look for repeated work across test cases. Read the transcripts and notice if the subagents all independently took the same multi-step approach. If all test runs show the same pattern, that's a signal the rule should address it more directly.
- Test negative cases. Ensure the rule doesn't trigger where it shouldn't. A rule for Python files should not affect TypeScript. A rule for frontend components should not affect backend handlers.
- Always explain what you changed and why. When fixing anti-patterns or improving rules, tell the user what the problem was and how your change addresses it. Silent fixes leave users unable to learn from the issue or catch it themselves next time.
Removing Rules
Before deleting a rule, check whether other rules reference it (e.g., via references/ pointers or overlap notes). Confirm deletion with the user. If the rule was unconditional (no frontmatter), note that removing it saves context budget on every future conversation.
Rule Auditing
Run a full audit of all project rules (from the repository root):
cd .claude/skills/rule-creator && python3 -m scripts.audit_rulesThis reports:
- Token budget broken down by activation mode (
unconditional,path_targeted) - Per-rule token and line counts with activation mode column
- Overlap detection between rules
- Stale glob patterns (matching no files)
- Frontmatter validation issues (including unrecognized fields)
Budget guidance: Keep unconditional rules as small as possible — they consume context on every conversation. Path-targeted rules only cost tokens when activated, so they're cheaper. If the audit shows high unconditional totals, convert rules to paths: targeting.
Use --include-user-rules to also scan ~/.claude/rules/ for user-level rules.
Claude.ai-Specific Instructions
In Claude.ai (no subagents, no claude -p):
- Execute each test task within the conversation with the rule's directives in mind. Compare the output against eval expectations manually.
- Skip baseline runs — without subagents, the comparison isn't meaningful.
- Present results directly in conversation. For files the user needs to inspect, create them as artifacts or describe the contents inline.
- Ask for feedback inline: "How does this look? Anything you'd change?"
- Skip description optimization and blind comparison (both require CLI).
Cowork-Specific Instructions
- Subagents work, so the main workflow (spawn runs, grade evals) all works. Remember that with-rule and baseline runs must be sequential (the baseline temporarily removes the rule file), but grading multiple evals can be parallel. If timeouts are an issue, run test prompts in series.
- You don't have a browser, so use
--static <output_path>for the eval viewer instead of starting a server. - Generate the eval viewer before evaluating results yourself. This lets the human review outputs in parallel while you analyze, saving wall-clock time.
- Feedback works differently: the viewer's "Submit All Reviews" downloads
feedback.jsonas a file. - Description optimization should work since it uses
claude -pvia subprocess.
Communicating with the User
Pay attention to context cues about the user's technical level. Some users creating rules are deeply technical; others may be less familiar with coding jargon. In the default case:
- "evaluation" and "benchmark" are fine to use
- For "JSON", "expectation", or "frontmatter", briefly explain if you're not sure the user knows the term
- Match the user's communication style — if they're casual, be casual back
The Core Loop
Follow the Core Workflow phases (above) in order. Three steps that matter most:
- Generate the eval viewer early — the human can review outputs in parallel while you analyze, cutting wall-clock time significantly.
- Run baselines (with_rule AND without_rule) unless in Claude.ai — without a baseline, you cannot tell whether the rule actually changed behavior or the model would have done the same thing anyway.
- Iterate on feedback until the user is satisfied — rules affect every future conversation, so incremental refinement has compounding value.
Add these to your TodoList (if you have one). If in Cowork, specifically add "Generate eval viewer so human can review test cases."
Reference Files
Agents (read when spawning subagents):
agents/grader.md— Evaluate expectations against outputsagents/comparator.md— Blind A/B comparisonagents/analyzer.md— Post-hoc analysis and benchmark patterns
References (read for context):
references/best-practices.md— Rule writing guidelinesreferences/schemas.md— JSON schemas for all data structuresreferences/advanced-workflows.md— Description optimization and blind comparison workflows
Scripts (execute directly):
scripts/quick_validate.py— Validate rule structurescripts/audit_rules.py— Audit all rules for qualityscripts/run_eval.py— Test trigger accuracy for skill descriptionscripts/improve_description.py— Improve skill description based on eval resultsscripts/run_loop.py— Eval + improve iteration loopscripts/aggregate_benchmark.py— Aggregate benchmark resultsscripts/generate_report.py— HTML report from optimizationscripts/package_rule.py— Package rule for sharing/PR
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

