From build
Create a correctly-structured rule for LLM-based semantic enforcement. Use when the user wants to "create a rule", "build a rule", "add a rule", "capture this convention", or "enforce this pattern".
How this skill is triggered — by the user, by Claude, or both
Slash command
/build:build-ruleThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Create semantic enforcement rules that Claude evaluates for compliance.
Create semantic enforcement rules that Claude evaluates for compliance. Rules capture conventions too nuanced for traditional linters — architectural boundaries, naming intent, layer purity, documentation quality.
Every rule requires both a non-compliant and compliant example from real code. Every rule requires a fix-safety declaration. Do not write a rule without these.
Before proceeding, confirm a rule is the right mechanism. Full decision matrix: primitive-routing.md.
Not right — redirect instead:
/wos:build-hook/wos:build-skillA rule is right when: enforcement requires LLM judgment on static file content and the convention is too nuanced for grep or an AST linter. Proceed only when this holds.
Check the project structure to determine rule format:
.cursor/ exists → Cursor (.mdc in .cursor/rules/)CLAUDE.md exists and no docs/rules/ → Claude Code (CLAUDE.md section)docs/rules/<slug>.rule.md)Report the detected format: "Detected format: [format] — proceed with this or override?" Wait for confirmation before drafting.
Before eliciting the pattern, determine the rule category. Present the eight categories and ask which best describes the rule:
| Category | What it enforces |
|---|---|
| Correctness | Code that will behave incorrectly or produce errors |
| Suspicious | Code that is probably wrong but not guaranteed |
| Security | Code that creates vulnerabilities or exposes sensitive data |
| Complexity | Code that is too complex to maintain safely |
| Performance | Code patterns with measurable performance cost |
| Convention/Style | Project-specific naming, structure, or formatting conventions |
| Accessibility | Code that creates accessibility barriers |
| LLM Directive | AI response-generation behavior (not code correctness) |
Use the category to set structural defaults before drafting:
auto-remediable for Correctness and Convention/Style only; requires-review for all otherswarn) for Complexity, Performance, Convention/Stylefail is appropriate only for Correctness and Security; use warn for all others unless the user explicitly requests failDetermine the intake mode from the user's input:
| Input | Mode |
|---|---|
| User describes a convention | conversation |
| User points to files or code | from-code |
| User provides style guide or RFC | from-source |
Conversation mode:
warnFrom-code mode:
From-source mode:
If the user describes something a traditional linter handles (syntax, formatting, import ordering), recommend the appropriate linter tool instead.
Before drafting, read existing rules in the project:
Do not skip this step. Undetected conflicts create contradiction in the rule library and degrade enforcement reliability.
Compose the rule following the Rule Format Guide for the detected format.
Required in all formats:
Intent five-component requirement. The Intent section must contain:
Non-compliant before compliant: listing exclusions first improves classification accuracy. Use actual code snippets with file path comments — synthetic examples with generic identifiers (foo, bar, myFunction) produce weaker anchors.
Default severity: warn. Use fail only when the category is Correctness or Security,
or the user explicitly requests it.
Before presenting, self-check against all twelve criteria. Fix any gap before presenting.
Four structural requirements (llm-rule-structural-characteristics.context.md):
Five linter patterns (linter-patterns-transferable-to-llm-rules.context.md):
5. Meta/create separation — criterion defined separately from evaluation context (Intent section exists and explains the criterion, not the enforcement mechanism)
6. Start-narrow — scope targets the specific file pattern where the known failure occurs; not **/* or **/*.ext without directory prefix
7. Default-closed — rule declares how uncertain cases resolve (WARN, not PASS)
8. Fix-safety classification — fix-safety field is set to auto-remediable or requires-review
9. Concern-prefix (if library has >5 rules) — rule name prefixed by domain (e.g., quality-, safety-, compliance-, style-)
Three new quality checks (from this session's research):
10. Intent completeness — Intent section contains all five components: violation, failure cost, principle, exception policy, fix-safety signal; no weak signals present (hedging language, prohibition-without-consequence, no exception policy)
11. Single canonical example — primary example is one canonical instance; flag if multiple examples risk introducing conflicting signals
12. Example realism — examples have file path comments or domain-specific identifiers; flag if synthetic (generic foo/bar identifiers, no file path context)
Show the complete rule file to the user. Iterate on feedback. Do not write until approved.
<same-dir>/<slug>.tests.md with at minimum 3 PASS cases and 3 FAIL cases, each with a rationale note. Reference the Rule Testing Guide for format. Test cases must use different code than the rule's own examples.Assistant detects WOS format (docs/rules/ exists). Classifies rule type: Convention/Style (enforcing architectural layer purity). Fix-safety default: requires-review. Framing: warn-first. Asks: "Which files should this apply to?" User: "models/staging/**/*.sql". Asks: "Should violations block (fail) or just warn?" User: "warn". Checks existing rules — no overlap found.
Drafts:
---
name: Staging layer purity
description: Staging models must only cast, rename, and deduplicate — no business logic
type: rule
scope: "models/staging/**/*.sql"
severity: warn
fix-safety: requires-review
---
## Intent
Staging models that include business logic (revenue calculations, tier
classifications) couple source schema changes to business definitions,
requiring coordinated updates across both layers when either changes.
This enforces the principle that staging models are a clean interface
over raw sources — not a transformation layer. Exception: calculated
fields that are pure data-type normalization (e.g., parsing a date
string to a date type) are permitted. Fix-safety: requires-review —
violations involve architectural decisions. When evidence is borderline,
prefer WARN over PASS.
## Non-Compliant Example
```sql
-- models/staging/stg_orders.sql
select id, quantity * unit_price as revenue,
case when lifetime_value > 1000 then 'high' else 'standard' end as tier
from {{ source('raw', 'orders') }}
Violations: revenue calculation and tier classification are business logic.
-- models/staging/stg_orders.sql
select id as order_id, cast(order_date as date) as order_date,
cast(quantity as integer) as quantity
from {{ source('raw', 'orders') }}
qualify row_number() over (partition by id order by _loaded_at desc) = 1
Only casts, renames, and deduplication.
Validates all 12 criteria — passes. Presents for approval. On approval, writes rule to
`docs/rules/staging-layer-purity.rule.md` and test file to
`docs/rules/staging-layer-purity.tests.md`.
</example>
## Key Instructions
- Every rule MUST have both a non-compliant and compliant example. Refuse to write without both.
- Won't replace a traditional linter: if the user's request is syntax, formatting, import ordering, or naming case, recommend the appropriate linter tool instead and stop.
- Intent must contain all five components. Missing failure cost (component 2) or exception policy (component 4) — stop and require them before drafting.
- Default severity is `warn`. False positives from `fail` rules erode trust faster than missed violations from `warn` rules.
- Start narrow: scope targets the specific known-failure pattern. Broaden only after validating negative examples.
- Default-closed: every rule declares how uncertain cases resolve. Rules without this default to PASS, hiding violations.
- Fix-safety is mandatory: always declare `auto-remediable` or `requires-review`.
- Never skip the conflict check. Undetected contradictions degrade the entire rule library.
- Do not write the file until the user approves the drafted rule.
- Always write the co-located test file. A rule without test cases cannot be validated before deployment.
## Anti-Pattern Guards
1. **Rules without both examples** — refuse to write; examples improve enforcement reliability 4×
2. **Overly broad scope** — `**/*` or `**/*.ext` without directory prefix fires on unrelated files; flag and require narrowing
3. **Multiple conventions in one rule** — any "and" in the description is a split signal
4. **Linter-appropriate checks** — syntax, formatting, import ordering belong in a linter, not here
5. **Missing default-closed stance** — rules without uncertainty handling default to PASS; always require a declaration
6. **Skipping conflict check** — contradictions in the rule library produce unpredictable enforcement
7. **Missing fix-safety** — without this, automated tools cannot safely apply fixes
8. **Incomplete Intent section** — an Intent that states only what the rule catches (not why it matters, not when to disable it) produces enforcement-without-education and workaround behavior
9. **Missing test file** — a rule without a co-located `.tests.md` file cannot be validated before deployment; this is a delivery failure, not optional polish
## Handoff
**Receives:** Code pattern, behavior description, or existing rule draft to formalize
**Produces:** Rule file written to the correct location for the detected project format
**Chainable to:** check-rule (verify the new rule fits the existing library without conflicts)
npx claudepluginhub bcbeidel/toolkit --plugin buildGuides 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.
Generates a coding rule from intent and renders it per supported host tool. Use when adding, refactoring, or scanning for rules, conventions, or standards.