From create-rule
Use when the user wants to create, write, update, or generate a .claude/rules/ file for any topic — testing, networking, error handling, dependency injection, UI patterns, architecture, git workflow, or any other coding convention. Trigger whenever the user mentions "rule file", "write a rule", "rules markdown", "document conventions", "create coding guidelines", ".claude/rules/", or wants Claude to analyze existing code patterns and capture them as persistent rules. Also use when the user says Claude keeps doing something wrong and wants to codify the correct approach, or when they want to update an existing rule file. Do NOT trigger for writing CLAUDE.md files, reviewing/auditing existing rules, setting up linters/eslint/prettier configs, creating CONTRIBUTING.md, writing tests, fixing bugs, or refactoring code — even if those tasks mention conventions.
How this skill is triggered — by the user, by Claude, or both
Slash command
/create-rule:create-ruleThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate focused `.claude/rules/<topic>.md` files by analyzing existing code patterns, confirming findings with the user, and self-validating via an eval loop.
Generate focused .claude/rules/<topic>.md files by analyzing existing code patterns, confirming findings with the user, and self-validating via an eval loop.
Create a task for each of these items and complete them in order:
.claude/rules/*.md and CLAUDE.md, flag content overlap.claude/rules/<topic>.md/claude-md-improver — tell user to run it after all issues are resolvedSometimes the user already knows the conventions and states them directly (e.g., "We use thiserror for library errors and anyhow for app errors. Never use unwrap() in production."). When this happens:
@file/pathMap the user's topic to likely file patterns. Adapt to whatever language/framework the project uses:
**/__tests__/**/*.test.{ts,tsx}, **/*.spec.ts**/src/test/**/*.kt, **/*Test.kt**/*_test.go**/handler/**/*.go, **/controller/**/*.java, **/routes/**/*.ts**/error*/**, **/exception/**, then broaden with grep for error/Result/throw patternsIf the topic doesn't map to obvious patterns, ask the user.
Read sampled files in parallel. Focus on patterns that are non-obvious and project-specific — things Claude would get wrong without the rule file. Ask yourself: "If I were writing new code in this project without this rule, what would I do differently from what the codebase actually does?"
Good patterns to document:
Skip patterns that are standard for the language/framework — Claude already knows those.
Show a summary: "I found these patterns across these files: [list]. Are these good examples, or should I look elsewhere?"
Wait for confirmation before proceeding. If the user redirects, adjust and re-sample.
paths: FrontmatterDecide whether the rule should be contextually loaded or always loaded:
paths: globspaths: (always loaded)!IMPORTANT: Always include paths: frontmatter when the topic applies to specific file types. Without it, the rule loads every session and wastes context tokens.
!IMPORTANT: Before writing, read ALL files in .claude/rules/ and CLAUDE.md. This is not optional — skipping it leads to contradictory or duplicated guidance.
For each existing rule file, check whether it already covers any of the patterns you plan to document. If overlap exists:
.claude/rules/<topic>.md): ask the user — overwrite, merge, or rename?!IMPORTANT: The complementary reference is the single most important thing when existing rules overlap. Add it as the first line after the frontmatter, e.g.:
This complements
api.md(which covers HTTP-side error mapping in handlers) andlogging.md(which covers structured error logging). This file focuses on domain error types and service-layer error conventions.
Then actively exclude any content the other rules already cover — don't just note the overlap, actually remove the duplicated sections.
If merge: match sections by heading, replace matched sections, append new ones.
Use lowercase-kebab-case with broadest category first:
testing-unit.mdtesting-instrumented.mddependency-injection.mdCheck existing rule filenames to match the project's naming convention.
Include:
!IMPORTANT for critical constraints Claude might skip@file/path references to exemplar code instead of inlining large blocksExclude:
These are common mistakes when writing rule files. Do NOT:
@file/path references to real files in the codebase instead (e.g., @src/domain/error.rs or @internal/handler/user_handler.go). This keeps the rule file short and always points to current code. Inline only short snippets (< 10 lines) that illustrate a non-obvious pattern.src/test/" or "name test files FooTest.kt" or "use @RestController for REST endpoints" adds nothing — Claude already knows standard conventions for every major language and framework. The litmus test: would Claude do this differently without the rule? If no, cut it..claude/rules/ files and CLAUDE.md first. Do not introduce guidance that conflicts with what's already documented.!IMPORTANT markers. Critical constraints that Claude might otherwise violate (e.g., "never use mocks", "only use kotlin.test assertions") MUST be marked with !IMPORTANT.After writing the rule file, validate it by testing whether a fresh agent follows the conventions.
Launch a subagent with isolation: "worktree" and a concrete task. The subagent runs with full project context (CLAUDE.md + all rules). Do NOT inline the rule content — the point is to test whether the rule file works in-situ.
Review the subagent's output against each convention in the rule:
!IMPORTANT constraints respected?If all conventions followed: done.
If gaps found: determine whether the rule was unclear or the convention was missing. Update the rule file. Re-launch a fresh eval (new worktree).
Max 3 iterations. After 3, surface remaining issues to the user.
Tell the user: "Rule file written to .claude/rules/<topic>.md. Consider running /claude-md-improver (if available) when you're done making rule files to review the full setup."
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub milis92/claude-toolbox --plugin create-rule