From claude-doctor
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.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-doctor:rule-creatorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
A skill for creating, maintaining, and evaluating Claude Code project rules.
agents/analyzer.mdagents/comparator.mdagents/grader.mdassets/eval_review.htmleval-viewer/generate_review.pyeval-viewer/viewer.htmlevals/evals.jsonreferences/advanced-workflows.mdreferences/best-practices.mdreferences/contributing.mdreferences/schemas.mdscripts/__init__.pyscripts/aggregate_benchmark.pyscripts/audit_rules.pyscripts/generate_report.pyscripts/improve_description.pyscripts/package_rule.pyscripts/quick_validate.pyscripts/run_eval.pyscripts/run_loop.pyA skill for creating, maintaining, and evaluating Claude Code project rules.
This skill handles the full lifecycle of project rules:
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:.
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.
---
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}").
paths: frontmatterpaths: targeting and broaden to unconditional if neededNote:
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.
~/.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).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 themAll script commands below are run from the repository root and cd into the skill directory as needed.
Understand what the user wants the rule to enforce:
cd .claude/skills/rule-creator && python3 -m scripts.audit_rules)references/best-practices.md for writing guidelines@path/to/file import syntax in CLAUDE.md as an alternative to duplicating large content into a ruleWhen 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:
alwaysApply, description) — not valid for .claude/rules/ filesA 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."
Follow these principles from references/best-practices.md:
error-handling.md, import-ordering.md). If a rule already exists for the topic, prefer updating it over creating a new one.Run validation:
cd .claude/skills/rule-creator && python3 -m scripts.quick_validate <rule-file>
Note: Frontmatter is optional for .claude/rules/ files.
For important rules, create eval cases and run the evaluation pipeline. See "Running and Evaluating Test Cases" below.
Review the rule, check for overlap with existing rules, and iterate based on feedback.
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.).
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.
Good expectations for rules:
When each subagent completes, save timing.json with total_tokens, duration_ms, and total_duration_seconds.
agents/grader.md. Save to grading.json with text, passed, evidence fields.cd .claude/skills/rule-creator && python3 -m scripts.aggregate_benchmark <workspace>/iteration-N --rule-name <rule-name>
agents/analyzer.md.cd .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=$!
For iteration 2+, add --previous-workspace <workspace>/iteration-<N-1> to show diffs.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/null
Improve the rule based on feedback, rerun into iteration-<N+1>/.
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.
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.
Run a full audit of all project rules (from the repository root):
cd .claude/skills/rule-creator && python3 -m scripts.audit_rules
This reports:
unconditional, path_targeted)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.
In Claude.ai (no subagents, no claude -p):
--static <output_path> for the eval viewer instead of starting a server.feedback.json as a file.claude -p via subprocess.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:
Follow the Core Workflow phases (above) in order. Three steps that matter most:
Add these to your TodoList (if you have one). If in Cowork, specifically add "Generate eval viewer so human can review test cases."
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 patternsReferences (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 workflowsScripts (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/PRnpx claudepluginhub aka-momo/claude-doctor --plugin claude-doctorGuides 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 writing effective .claude/rules/ files for Claude Code, with imperative framing and enforceability checks. Useful when creating or refining project-specific rules.
Manages modular Claude rules in .claude/rules/ directory, supporting path-specific globs, brace expansion, project-wide, and user-level rules. Use to create, edit, list, generate, or sync rules.