Create modular Claude Code rules files in .claude/rules/
Creates modular Claude Code rules files in .claude/rules/
/plugin marketplace add dariuszparys/claudecode-enhancements/plugin install dp-tools@claude-code-toolkitdp/You are helping me create modular rules files for Claude Code. Rules are topic-specific instruction files stored in .claude/rules/.
| Use Case | Approach |
|---|---|
| Project overview, stack, commands | CLAUDE.md |
| Path-specific conventions (API, tests) | Rules with paths: frontmatter |
| Large project with many conventions | Rules organized in subdirectories |
| Shared rules across projects | Rules (can be symlinked) |
# Check if rules directory exists
ls -la .claude/rules/ 2>/dev/null || echo "No rules directory yet"
# Check existing CLAUDE.md
cat .claude/CLAUDE.md 2>/dev/null || cat CLAUDE.md 2>/dev/null || echo "No CLAUDE.md found"
# Understand project structure
tree -L 2 -d 2>/dev/null || find . -type d -maxdepth 2
Look for areas that would benefit from dedicated rules:
typescript.md, python.md, go.mdapi.md, frontend.md, database.mdtesting.md, security.md, logging.mdpayments.md, auth.md, notifications.mdApply to all files in the project:
# Testing Standards
- Use descriptive test names: `test_<function>_<scenario>_<expected>`
- Each test file must have a corresponding source file
- Mock external services, never call real APIs in tests
Apply only to matching files:
---
paths: src/api/**/*.ts
---
# API Development Rules
- All endpoints must validate input with zod schemas
- Use standard error response format from `lib/errors`
- Rate limiting required for public endpoints
| Pattern | Matches |
|---|---|
**/*.ts | All TypeScript files |
src/api/**/*.ts | API TypeScript files only |
src/**/*.{ts,tsx} | All TS/TSX in src |
tests/**/*.test.ts | Test files only |
{src,lib}/**/*.ts | Multiple directories |
For a typical project, suggest this structure:
.claude/
├── CLAUDE.md # Main project memory (overview, stack, commands)
└── rules/
├── typescript.md # Language conventions
├── testing.md # Testing standards
├── api.md # API-specific (paths: src/api/**)
└── database.md # Database conventions
For larger projects with many rules:
.claude/
├── CLAUDE.md
└── rules/
├── languages/
│ ├── typescript.md
│ └── python.md
├── layers/
│ ├── api.md
│ ├── frontend.md
│ └── database.md
└── practices/
├── testing.md
└── security.md
security.md for auth requirements"Bad: "Write clean code" Good: "Functions must have max 20 lines, extract helpers for complex logic"
For each rule file, provide:
## Rule: {filename}
**Scope**: Global / Path-scoped to `{pattern}`
**Purpose**: {one sentence}
### Content
\`\`\`markdown
{rule content}
\`\`\`
.claude/rules/ directory if neededRemind the user:
paths: frontmatter for path-specific rules