Rules Management Skill
Comprehensive guidance for managing CLAUDE.md user-specific rules with context-based loading for optimal performance.
Core Principle: Load What's Relevant
Claude Code loads CLAUDE.md on every interaction. To avoid loading all rules upfront:
- Critical rules → Keep directly in CLAUDE.md (always loaded)
- Context-specific rules → Move to
.claude/rules/ with trigger hints (loaded on-demand)
Directory Structure
.claude/
├── CLAUDE.md # Critical rules + context hints
└── rules/ # Domain-specific rules (loaded when relevant)
├── python.md
├── typescript.md
├── docker.md
├── react.md
└── security-advanced.md
CLAUDE.md Structure (Always Loaded)
# Project Name
Brief project description.
## Critical Rules (Always Apply)
### Security
- Never commit secrets, API keys, or credentials
- Never disable security middleware or authentication checks
- Sanitize all user input before database operations
### Git Workflow
- Feature branches only, never commit directly to main
- Always run tests before committing
## Context (Read When Relevant)
Load context files based on what you're working on:
| Working On | Read |
|------------|------|
| Python/FastAPI backend | `.claude/rules/python.md` |
| React/TypeScript frontend | `.claude/rules/typescript.md` |
| Docker/containers | `.claude/rules/docker.md` |
| Authentication/security | `.claude/rules/security.md` |
What Goes Where?
Critical Rules (in CLAUDE.md)
Keep rules that are always relevant regardless of task:
- Security fundamentals (secrets, auth, input sanitization)
- Git workflow (branching, commits)
- Core project conventions (naming, structure)
- Communication preferences
Characteristics:
- Short and actionable
- Apply to 80%+ of tasks
- Safety-critical
- Never need context to understand
Context Files (in .claude/rules/)
Move rules that are domain-specific:
- Language-specific patterns (Python, TypeScript, Go)
- Framework conventions (React, FastAPI, Next.js)
- Tool configurations (Docker, Terraform, CI/CD)
- Detailed security practices
Characteristics:
- Only relevant for specific file types/tasks
- May be lengthy with examples
- Require specialized knowledge
- Not needed for every interaction
Context File Template
# [Technology/Domain] Context
Rules for [technology] development in this project.
## Key Patterns
- [Specific pattern or convention]
- [Another pattern]
## Examples
### Recommended
```python
# Good example with explanation
```
### Avoid
```python
# Bad example with explanation why
```
## Integration Points
- Related to: `.claude/context/[related].md` (when working with both)
Trigger Hints
The CLAUDE.md table tells Claude when to load context files from .claude/rules/:
| Trigger Keywords |
Context File |
.py, Python, FastAPI, Pydantic |
python.md |
.ts, .tsx, React, Next.js |
typescript.md |
| Docker, container, Dockerfile |
docker.md |
| auth, JWT, OAuth, security audit |
security.md |
.go, Go, Gin, Echo |
golang.md |
| database, SQL, migrations |
database.md |
Migration Guide
Before (All Loaded)
# CLAUDE.md
@rules/frontend/react.md
@rules/frontend/typescript.md
@rules/backend/python.md
@rules/backend/fastapi.md
@rules/devops/docker.md
@rules/security/auth.md
@rules/general/standards.md
Problem: All 7 files loaded on every interaction
After (Verrueckt Rules)
# CLAUDE.md
## Critical Rules
- Never commit secrets
- Feature branches only
- Run tests before commit
## Context (Read When Relevant)
| Working On | Read |
|------------|------|
| Python backend | `.claude/rules/python.md` |
| TypeScript/React | `.claude/rules/typescript.md` |
| Containers | `.claude/rules/docker.md` |
Improvement: Only load what's needed per task
Rule Priority
- CLAUDE.md critical rules → Always apply
- Loaded context files → Apply when read
- Default best practices → Fall back when no rule exists
Best Practices
For Critical Rules
- Keep under 20 lines total
- Use bullet points, not paragraphs
- Focus on "never do" and "always do"
- No examples needed (rules should be self-evident)
For Context Files
- One technology/domain per file
- Include examples for complex patterns
- Reference related context files
- Keep under 200 lines per file
For Trigger Hints
- Use file extensions as triggers (
.py, .tsx)
- Use technology keywords (Python, React)
- Use task keywords (auth, deploy, test)
- Be specific enough to avoid false matches
Commands Reference
| Command |
Purpose |
/coconut-rules:add-rule [desc] |
Add rule with auto-placement (critical vs context) |
/coconut-rules:list-rules |
Show current structure and loading pattern |
/coconut-rules:organize |
Restructure rules to context-based pattern |
1---2name: rules-management3description: This skill provides guidance on organizing CLAUDE.md rules, category structures, and rule file best practices. Use when the user asks about 'how to organize Claude rules', 'CLAUDE.md structure', 'rule categories', 'rules best practices', or needs help understanding the rules system.4---56# Rules Management Skill78Comprehensive guidance for managing CLAUDE.md user-specific rules with **context-based loading** for optimal performance.910## Core Principle: Load What's Relevant1112Claude Code loads CLAUDE.md on every interaction. To avoid loading all rules upfront:13141. **Critical rules** → Keep directly in CLAUDE.md (always loaded)152. **Context-specific rules** → Move to `.claude/rules/` with trigger hints (loaded on-demand)1617## Directory Structure1819```20.claude/21├── CLAUDE.md # Critical rules + context hints22└── rules/ # Domain-specific rules (loaded when relevant)23 ├── python.md24 ├── typescript.md25 ├── docker.md26 ├── react.md27 └── security-advanced.md28```2930## CLAUDE.md Structure (Always Loaded)3132```markdown33# Project Name3435Brief project description.3637## Critical Rules (Always Apply)3839### Security40- Never commit secrets, API keys, or credentials41- Never disable security middleware or authentication checks42- Sanitize all user input before database operations4344### Git Workflow45- Feature branches only, never commit directly to main46- Always run tests before committing4748## Context (Read When Relevant)4950Load context files based on what you're working on:5152| Working On | Read |53|------------|------|54| Python/FastAPI backend | `.claude/rules/python.md` |55| React/TypeScript frontend | `.claude/rules/typescript.md` |56| Docker/containers | `.claude/rules/docker.md` |57| Authentication/security | `.claude/rules/security.md` |58```5960## What Goes Where?6162### Critical Rules (in CLAUDE.md)6364Keep rules that are **always relevant** regardless of task:6566- Security fundamentals (secrets, auth, input sanitization)67- Git workflow (branching, commits)68- Core project conventions (naming, structure)69- Communication preferences7071**Characteristics:**72- Short and actionable73- Apply to 80%+ of tasks74- Safety-critical75- Never need context to understand7677### Context Files (in .claude/rules/)7879Move rules that are **domain-specific**:8081- Language-specific patterns (Python, TypeScript, Go)82- Framework conventions (React, FastAPI, Next.js)83- Tool configurations (Docker, Terraform, CI/CD)84- Detailed security practices8586**Characteristics:**87- Only relevant for specific file types/tasks88- May be lengthy with examples89- Require specialized knowledge90- Not needed for every interaction9192## Context File Template9394```markdown95# [Technology/Domain] Context9697Rules for [technology] development in this project.9899## Key Patterns100101- [Specific pattern or convention]102- [Another pattern]103104## Examples105106### Recommended107```python108# Good example with explanation109```110111### Avoid112```python113# Bad example with explanation why114```115116## Integration Points117118- Related to: `.claude/context/[related].md` (when working with both)119```120121## Trigger Hints122123The CLAUDE.md table tells Claude when to load context files from `.claude/rules/`:124125| Trigger Keywords | Context File |126|-----------------|--------------|127| `.py`, Python, FastAPI, Pydantic | `python.md` |128| `.ts`, `.tsx`, React, Next.js | `typescript.md` |129| Docker, container, Dockerfile | `docker.md` |130| auth, JWT, OAuth, security audit | `security.md` |131| `.go`, Go, Gin, Echo | `golang.md` |132| database, SQL, migrations | `database.md` |133134## Migration Guide135136### Before (All Loaded)137```markdown138# CLAUDE.md139140@rules/frontend/react.md141@rules/frontend/typescript.md142@rules/backend/python.md143@rules/backend/fastapi.md144@rules/devops/docker.md145@rules/security/auth.md146@rules/general/standards.md147```148*Problem: All 7 files loaded on every interaction*149150### After (Verrueckt Rules)151```markdown152# CLAUDE.md153154## Critical Rules155- Never commit secrets156- Feature branches only157- Run tests before commit158159## Context (Read When Relevant)160| Working On | Read |161|------------|------|162| Python backend | `.claude/rules/python.md` |163| TypeScript/React | `.claude/rules/typescript.md` |164| Containers | `.claude/rules/docker.md` |165```166*Improvement: Only load what's needed per task*167168## Rule Priority1691701. **CLAUDE.md critical rules** → Always apply1712. **Loaded context files** → Apply when read1723. **Default best practices** → Fall back when no rule exists173174## Best Practices175176### For Critical Rules177- Keep under 20 lines total178- Use bullet points, not paragraphs179- Focus on "never do" and "always do"180- No examples needed (rules should be self-evident)181182### For Context Files183- One technology/domain per file184- Include examples for complex patterns185- Reference related context files186- Keep under 200 lines per file187188### For Trigger Hints189- Use file extensions as triggers (`.py`, `.tsx`)190- Use technology keywords (Python, React)191- Use task keywords (auth, deploy, test)192- Be specific enough to avoid false matches193194## Commands Reference195196| Command | Purpose |197|---------|---------|198| `/coconut-rules:add-rule [desc]` | Add rule with auto-placement (critical vs context) |199| `/coconut-rules:list-rules` | Show current structure and loading pattern |200| `/coconut-rules:organize` | Restructure rules to context-based pattern |