| name | project-rules |
| description | Manage coding guidelines and CLAUDE.md rules. Use when the user wants to
add, change, delete, analyze, or discover coding conventions. Triggers
include: "add rule", "coding guidelines", "convention", "CLAUDE.md",
"coding standard", "project rules", "discover patterns".
|
| allowed-tools | Read, Write, Edit, Glob, Grep, Bash, AskUserQuestion |
Rules Skill
Manage Claude Code coding guidelines stored in CLAUDE.md files.
Memory Hierarchy
When modifying rules, understand the target location:
| Priority | Location | Scope | Path |
|---|
| 1 (highest) | Enterprise Policy | All users, all projects | /etc/claude-code/CLAUDE.md or C:\ProgramData\ClaudeCode\CLAUDE.md |
| 2 | Project Memory | All users, this project | ./CLAUDE.md |
| 3 | User Memory | Current user, all projects | ~/.claude/CLAUDE.md |
| 4 (lowest) | Project Memory Local | Current user, this project | ./CLAUDE.local.md (deprecated) |
Default assumption: Unless specified otherwise, modify ./CLAUDE.md (project memory).
Actions
ADD Rules
Add new rules to a CLAUDE.md file.
Input sources:
- From file: User provides path to file containing rules
- From text: User provides rule text directly
- From discovery: Generated from codebase scan (see DISCOVER)
Process:
- Determine target CLAUDE.md file (ask if unclear)
- Read existing content to understand structure
- Parse new rules and categorize them
- Find appropriate section or create new one
- Format rules according to template (see references/RULE_TEMPLATE.md)
- Insert maintaining markdown structure
- Consider using
@import for large rule sets
Example insertion:
## Code Style
- Use 2-space indentation for all files
- Use single quotes for strings in JavaScript/TypeScript
- Add trailing commas in multiline structures
CHANGE Rules
Modify existing rules in a CLAUDE.md file.
Process:
- Search CLAUDE.md for rules matching the query using Grep/Read
- Present all matching rules with context (section, surrounding rules)
- Ask user to confirm which rule(s) to modify
- Accept the modification (full replacement or guided edit)
- Apply change preserving formatting and structure
Matching strategies:
- Exact section name match
- Keyword search within rule text
- Fuzzy match for partial queries
Example:
User: /rules change indentation
Found in section "Code Style":
"- Use tabs for indentation"
Change to: "- Use 2-space indentation"
DELETE Rules
Remove rules from a CLAUDE.md file.
Process:
- Search CLAUDE.md for rules matching the query
- Present all matching rules with context
- Ask user to confirm deletion
- Remove rule cleanly
- If section becomes empty, ask whether to remove section
- Clean up any orphaned
@import references
Example:
User: /rules delete jquery
Found in section "Dependencies":
"- Use jQuery for DOM manipulation"
Delete this rule? [Y/n]
ANALYZE Rules
Analyze current CLAUDE.md rules for quality issues.
Analysis dimensions:
-
Coverage - What aspects of development are covered?
- Code style, naming, file organization, error handling, testing, security, performance, documentation, dependencies, git
-
Conflicts - Are there contradictory rules?
- Example: "Use tabs" vs "Use 2-space indentation"
-
Redundancy - Duplicate or overlapping rules?
-
Specificity - Are rules actionable?
- Vague: "Follow best practices", "Write clean code"
- Specific: "Use 2-space indentation", "Name components with PascalCase"
-
Organization - Is the structure logical?
- Consistent heading levels
- Logical grouping
- Appropriate section ordering
Output format:
# Rules Analysis Report
**Target:** ./CLAUDE.md
**Date:** <date>
**Score:** X/10
## Coverage Summary
| Category | Rules | Gaps |
|----------|-------|------|
| Code Style | 5 | - |
| Testing | 2 | Missing: test naming, coverage threshold |
| ... | ... | ... |
## Issues Found
| # | Type | Location | Issue | Recommendation |
|---|------|----------|-------|----------------|
| 1 | VAGUE | Style | "Follow best practices" | Be specific: define what practices |
| 2 | CONFLICT | Formatting | Conflicting indent rules | Consolidate to one rule |
## Suggestions
1. Add testing naming convention rule
2. Specify error handling patterns
3. Remove redundant "clean code" rule
DISCOVER Rules
Scan codebase to discover existing conventions and suggest rules.
Discovery process:
-
Detect Tech Stack
- Check for: package.json, Cargo.toml, pyproject.toml, go.mod, etc.
- Identify frameworks: React, Vue, Django, Rails, etc.
- Identify test frameworks: Jest, pytest, Go test, etc.
-
Analyze File Naming
- Use Glob to find patterns:
*.tsx, *.test.ts, *.spec.js, test_*.py
- Detect conventions: PascalCase, camelCase, kebab-case
- Identify suffixes: .test, .spec, .module, .config
-
Analyze Directory Structure
- Common directories: src/, lib/, components/, hooks/, utils/
- Colocation patterns (tests next to source vs separate)
-
Analyze Code Patterns
- Use Grep to find import patterns
- Detect export patterns (named vs default)
- Identify comment conventions
- Find error handling patterns
-
Check Existing Configs
- Linting: .eslintrc, ruff.toml, clippy.toml
- Formatting: .prettierrc, .editorconfig
- CI/CD: .github/workflows/, .gitlab-ci.yml
Output format:
# Discovered Conventions
## Tech Stack
- **Language:** TypeScript
- **Framework:** React
- **Testing:** Jest + React Testing Library
- **Build:** Vite
## File Naming Patterns
| Type | Pattern | Examples |
|------|---------|----------|
| Components | PascalCase.tsx | Button.tsx, UserProfile.tsx |
| Tests | *.test.tsx | Button.test.tsx |
| Utilities | camelCase.ts | formatDate.ts |
| Styles | *.module.css | Button.module.css |
## Directory Structure
- `src/components/` - React components
- `src/hooks/` - Custom hooks
- `src/lib/` - Utility functions
- `src/__tests__/` - Test files
## Import Patterns
- Path alias: `@/` for src/
- Named exports preferred for utilities
- Default exports for page components
## Existing Configs
- ESLint: .eslintrc.json (airbnb base)
- Prettier: .prettierrc (2 spaces, single quotes)
- TypeScript: strict mode enabled
## Suggested Rules
### Code Style
- Use 2-space indentation (from Prettier config)
- Use single quotes for strings (from Prettier config)
- Use path alias `@/` for imports from src/
### Naming Conventions
- Components: PascalCase.tsx
- Test files: colocated with source, *.test.tsx suffix
- Utilities: camelCase.ts
### Architecture
- Components in src/components/
- Custom hooks in src/hooks/
- Utilities in src/lib/
### Testing
- Use Jest + React Testing Library
- Test files colocated with source files
---
Add these rules to CLAUDE.md? [all/selective/none]
Reference Files
references/RULE_TEMPLATE.md - Template for writing rules
references/DISCOVERY_PATTERNS.md - Detailed discovery patterns
references/MEMORY_HIERARCHY.md - CLAUDE.md hierarchy reference
Best Practices
- Be Specific: "Use 2-space indentation" > "Format code properly"
- Use Structure: Organize with markdown headings and bullet points
- Provide Examples: Include code examples for complex rules
- Keep Current: Review and update rules as project evolves
- Use Imports: For large rule sets, use
@path/to/import syntax
- Avoid Redundancy: Don't duplicate rules across sections
- One Concept Per Rule: Keep rules focused and atomic