Restructure existing rules to context-based loading pattern for optimal performance
Restructures rules into context-based loading pattern for optimal performance
/plugin marketplace add FrancisVarga/coconut-claude-code-plugins/plugin install coconut-rules@coconut-claude-code-pluginsIf the user passes --help as an argument, display this help and stop:
/coconut-rules:organize - Organize Rules Structure
DESCRIPTION
Organize rules into the .claude/rules/ structure
for context-based loading (load only when relevant).
USAGE
/coconut-rules:organize
/coconut-rules:organize --help
STRUCTURE
.claude/
├── CLAUDE.md # Critical rules inline + context table
└── rules/
├── typescript.md # Frontend rules
├── python.md # Backend rules
└── docker.md # DevOps rules
PROCESS
1. Analyze current rules in project
2. Classify rules as Critical or Context
3. Extract critical rules to CLAUDE.md
4. Consolidate context rules by domain in .claude/rules/
5. Create context table in CLAUDE.md
EXAMPLES
# Run organization
/coconut-rules:organize
BENEFITS
- Faster context loading (only relevant rules)
- Cleaner CLAUDE.md (critical rules only)
- Better organization (domain-based)
- Reduced token usage per interaction
Organize rules into the .claude/rules/ structure for context-based loading.
Target structure:
.claude/
├── CLAUDE.md # Critical rules inline + context table
└── rules/
├── typescript.md # Frontend rules
├── python.md # Backend rules
└── docker.md # DevOps rules
Check for any existing rules in the project:
# Check for coconut rules structure
ls -la .claude/rules/ 2>/dev/null
Read CLAUDE.md to find existing rules or references.
For each rule found, classify as:
Critical (keep in CLAUDE.md):
Context (move to .claude/rules/):
Extract one-liner critical rules for CLAUDE.md:
## Critical Rules
### Security
- Never commit secrets, API keys, or credentials
- Sanitize all user input before database operations
### Git
- Feature branches only, never commit to main
- Run tests before committing
Create domain-based context files in .claude/rules/:
| Domain | File | Content |
|---|---|---|
| Frontend | typescript.md | React, Next.js, TypeScript patterns |
| Backend | python.md | Python, FastAPI patterns |
| DevOps | docker.md | Container, CI/CD patterns |
| Security | security.md | Auth, authorization patterns |
Add to CLAUDE.md:
## Rules
Context rules are loaded on-demand from `.claude/rules/`:
| Context | Rule File |
|---------|-----------|
| Python/FastAPI backend | `.claude/rules/python.md` |
| React/TypeScript frontend | `.claude/rules/typescript.md` |
| Docker/containers | `.claude/rules/docker.md` |
# Show new structure
tree .claude/rules/ 2>/dev/null || find .claude/rules -type f
After completing organization, report:
## Organization Complete
### Critical Rules Added to CLAUDE.md
- [List of critical rules]
### Context Files Created
| File | Content |
|------|---------|
| `rules/python.md` | Python/FastAPI patterns |
| `rules/typescript.md` | React/TypeScript patterns |
### Next Steps
- Test the new structure
- Add more context files as needed
rules/python.md:
# Python Context
## FastAPI Patterns
- Use Pydantic models for request/response validation
- Implement dependency injection for services
- Use async/await for I/O operations
## Examples
### Service Pattern
```python
from fastapi import Depends
class UserService:
def __init__(self, repo: UserRepository = Depends()):
self.repo = repo
## Tips
- Consolidate aggressively - fewer context files = easier to manage
- Test by asking Claude about a topic and verifying it reads the right context
- Keep CLAUDE.md under 50 lines including critical rules