π Sahin Claude Code Rules - The Ultimate Claude Code Framework
Transform Claude Code from a helpful tool into a disciplined, systematic, and highly efficient development partner
Quick Start β’ 12 Core Rules β’ Agent Framework β’ Visual Workflow β’ Implementation β’ Connect
π Connect with Sahin
π Table of Contents
Page 1: Introduction & Why This Framework
Page 2: Quick Start & Setup
Page 3: The 12 Core Rules
Page 4: Visual Workflow Architecture
Page 5: High-ROI Development Strategy
Page 6: Testing-First Methodology
Page 7: Agent Framework
Page 8: Automation & Hooks
Page 9: Dynamic Rule Loading
Page 10: Context Management
Page 11: Quality Gates & Compliance
Page 12: Performance & Metrics
Page 13: Implementation Guide
Page 1: Introduction & Why This Framework
π― The Problem with Unstructured Claude Code Usage
Using Claude Code without proper rules leads to:
- β Immediate Coding: Starts writing code without understanding requirements
- β Context Loss: Forgets project patterns and conventions mid-task
- β Inconsistent Style: Different coding approaches in the same codebase
- β Over-Engineering: Creates unnecessary abstractions and complexity
- β Test Blindness: Writes code without tests or breaks existing ones
β The Sahin AI Rules Solution
This framework optimizes Claude Code through:
- β Plan-First Coding: Every feature starts with structured planning
- β Project-Aware Context: Loads relevant coding standards dynamically
- β Efficient Solutions: Reuse existing code, minimize new additions
- β Test-Driven Development: Write tests before implementation
- β Task Management: TodoWrite tool tracks every coding task
- β Automated Workflows: Git hooks, test runners, and commit automation
- β Specialized Agents: AI agents for complex testing and analysis tasks
π Proven Results
| Metric | Before Claude Code | With This Framework | Improvement |
|---|---|---|---|
| Code Planning | 5% | 20% | Better architecture |
| Lines per Feature | 200 | 50 | 75% less code |
| Test Coverage | 40% | 95% | Full user flow testing |
| Visual Regression | Manual | Automated | 100% coverage |
| Production Bugs | 12/week | 2/week | 83% reduction |
| Code Reuse | 20% | 80% | 4x improvement |
| Development Speed | Baseline | 2.5x | 150% faster |
Page 2: Quick Start & Setup
π Installation (5 Minutes)
# 1. Clone the Repository git clone https://github.com/sahin/ai-rules.git cd ai-rules # 2. Copy to Your Project (Works with Claude Code, Cursor, etc.) cp -r .claude/rules /your/project/.claude/rules/ cp -r .claude/docs /your/project/.claude/docs/ cp CLAUDE.md /your/project/ # 3. Set Up Hooks for Claude Code (Automated testing & commits) mkdir -p /your/project/.claude/hooks cp .claude/hooks/* /your/project/.claude/hooks/ 2>/dev/null || true chmod +x /your/project/.claude/hooks/*.sh # 4. Verify Setup for Claude Code cat /your/project/.claude/rules/manifest.json | jq '.rules | keys'
π Directory Structure
your-project/
βββ CLAUDE.md # Configuration for Claude Code
βββ .claude/ # Works with Claude Code, Cursor, etc.
β βββ rules/
β β βββ _mandatory/ # Always loaded for code quality
β β βββ core-standards/ # Coding standards
β β βββ general-policies/ # Technology-specific rules
β β β βββ backend/ # Node.js, Python, Go patterns
β β β βββ frontend/ # React, Vue, Angular patterns
β β β βββ testing/ # Jest, Playwright, Pytest
β β β βββ ops/ # Docker, CI/CD, deployment
β β βββ agents/ # Specialized AI agents
β β βββ testing/ # Comprehensive testing rules
β β βββ manifest.json # Dynamic loading config
β βββ docs/ # Framework documentation
β βββ hooks/ # Claude Code automation
β βββ session/ # Session state for Claude Code
β‘ First Test with Claude Code
Send this message to Claude Code:
"Create an API endpoint for user authentication with tests"
Claude Code will automatically:
- Load backend, testing, and security rules
- Create a structured implementation plan
- Ask for your approval before coding
- Write E2E tests first (Playwright/Jest)
- Implement minimal code to pass tests
- Run tests automatically after changes
- Commit with conventional format at session end
Page 3: The 12 Core Rules
π― Rule Categories
π΄ Critical Rules (Always Applied)
Rule 1: Plan-First Enforcement
- No code without approved plan
- Structured approach to every task
- Clear scope definition
Rule 2: High-ROI Development
- ROI = (Impact Γ Frequency) / Lines of Code
- Maximize value, minimize complexity
- 80% reuse, 20% new code
Rule 3: Testing-First Approach
- User story β E2E test β Implementation
- 100% user flow coverage
- Tests drive development
Rule 4: Circuit Breaker System
- Stop β Analyze β Plan β Approve β Execute
- Prevents immediate action
- Ensures thoughtful approach
π‘ Automation Rules (System Intelligence)
Rule 5: Smart Testing Automation
- Detect changed files automatically
- Run only affected tests
- Cache results for efficiency
Rule 6: Dynamic Rule Loading
- Keywords trigger specific rules
- Context-aware guidance
- Minimize token usage
Rule 7: Auto-Commit Workflow
- Intelligent commit messages
- Conventional format
- Rollback scripts included
Rule 8: Hook Orchestration
- Pre/post action automation
- Parallel execution
- Quality gate enforcement
π’ Quality Rules (Continuous Improvement)
Rule 9: Quality Gates
- Multi-stage validation
- Automated compliance checks
- Performance monitoring
Rule 10: Session State Management
- Continuous workflow tracking
- Progress persistence
- Context preservation
Rule 11: Error Recovery & Rollback
- Automatic failure detection
- Safe rollback mechanisms
- State restoration
Rule 12: Continuous Improvement
- Self-learning system
- Usage pattern analysis
- Performance optimization
Page 4: Visual Workflow Architecture
Complete System Flow
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SAHIN AI RULES WORKFLOW SYSTEM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β User Request β Analysis β Plan β Approval β Todo β Execute β Test β Commit β
β β β β β β β β β β
β [Natural [Context] [Task [User [Auto [Code [Smart [Auto β
β Language] Rules] List] OK/NO] File] Gen] Tests] Save] β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Phase 1: Request Analysis & Planning
User Request: "Build login with tests"
β
βββββββββββββββββββ
β Keyword Detectionβ
β "login" "tests" β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Load Rules: β
β β’ Auth β
β β’ Testing β
β β’ Security β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Create Plan β
β 1. UI Form β
β 2. Auth Logic β
β 3. E2E Tests β
βββββββββββββββββββ
β
"Would you like me to proceed?"
Phase 2: Execution Loop
Plan Approved β Generate Todo
β
βββββββββββββββββββ
β Todo Queue: β
β β‘ Login UI β
β β‘ Auth Service β
β β‘ E2E Tests β
βββββββββββββββββββ
β
For Each Task:
β
Execute β Test β Verify β Mark Complete
β
All Complete β Session Summary
Page 5: High-ROI Development Strategy
The ROI Formula
function calculateROI(feature) { const impact = getUserImpactScore(); // 1-10 const frequency = getUsageFrequency(); // 1-10 const linesOfCode = estimateLoC(); // number const roi = (impact * frequency) / linesOfCode; if (roi > 10) return "π DO IMMEDIATELY"; if (roi > 3) return "β SCHEDULE SOON"; if (roi < 3) return "β³ DEFER OR REJECT"; }
Decision Matrix
High Impact Low Impact
βββββββββββββββββββββββ¬ββββββββββββββββββββββ
Low LoC β π DO FIRST β β
DO NEXT β
β β β
β β’ User login β β’ UI polish β
β β’ Critical bugs β β’ Nice-to-haves β
β β’ Core features β β’ Minor features β
βββββββββββββββββββββββΌββββββββββββββββββββββ€
High LoC β β οΈ MINIMIZE β β AVOID β
β β β
β β’ Complex features β β’ Over-engineering β
β β’ Must-have only β β’ Premature optim β
β β’ Break into steps β β’ Scope creep β
βββββββββββββββββββββββ΄ββββββββββββββββββββββ
Code Reuse Strategy
Need Feature?
β
βΌ
Can Reuse Existing? ββYesβββ Use It (0 LoC)
βNo
βΌ
Can Extend Existing? ββYesβββ Extend It (10 LoC)
βNo
βΌ
Can Modify Slightly? ββYesβββ Modify It (30 LoC)
βNo
βΌ
Must Create New? ββYesβββ Minimize It (50+ LoC)
Target: 80% reuse, 15% extend, 5% new
Page 6: Testing-First Methodology
Playwright-First Development
User Story: "As a user, I want to login"
β
βββββββββββββββββββββββββββββββββββββββ
β Write E2E Test FIRST β
β β
β test('user can login', async () => {β
β await page.goto('/login'); β
β await page.fill('#email', ...); β
β await page.fill('#password',...);β
β await page.click('#submit'); β
β expect(page.url()).toBe('/home');β
β }); β
βββββββββββββββββββββββββββββββββββββββ
β
Test Fails (No Implementation)
β
Build Minimal Code to Pass
β
Test Passes β Feature Done
Testing Pyramid
/\
/E2E\ β 70% effort (User flows)
/------\
/ API \ β 20% effort (Integration)
/----------\
/ Unit \ β 10% effort (Functions)
/--------------\
Smart Testing System
# Automatic test detection
Changed: src/auth.service.ts
β
Detected: auth.test.ts, login.e2e.ts
β
Running: 2 tests (5 seconds vs 3 minutes full suite)
β
Results: β
All tests passedPage 7: Agent Framework
π€ Specialized AI Agents
The framework now includes specialized agents for complex tasks:
Agent Types: rule-learning: purpose: "Learns and documents new patterns from codebase" triggers: ["analyze", "learn", "document"] capabilities: ["pattern recognition", "rule generation"] frontend-validation: purpose: "Comprehensive frontend testing and validation" triggers: ["test", "validate", "frontend"] capabilities: ["visual testing", "accessibility", "performance"] visual-regression: purpose: "Visual regression testing for UI components" triggers: ["visual", "regression", "ui"] capabilities: ["screenshot comparison", "diff analysis"]
Agent Workflow Integration
Complex Task Detected
β
βββββββββββββββββββ
β Agent Selection β
β Based on Task β
β Complexity β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Specialized β
β Agent Execution β
β with Context β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Results β
β Integration β
β Back to Main β
βββββββββββββββββββ
Agent-Enhanced Testing
Frontend Validation Agent:
Capabilities: - Visual regression testing - Accessibility compliance (WCAG 2.1) - Performance benchmarking - Cross-browser compatibility - Mobile responsiveness - SEO optimization checks Automated Workflows: - Pre-commit visual testing - Accessibility audit reports - Performance regression alerts - Browser compatibility matrix
Rule Learning Agent:
Capabilities: - Codebase pattern analysis - Custom rule generation - Best practice documentation - Anti-pattern detection - Style guide enforcement Learning Process: 1. Analyze existing code patterns 2. Identify common structures 3. Generate custom rules 4. Validate with team feedback 5. Auto-update rule base
Page 8: Automation & Hooks
Hook Integration Points
| Hook | Trigger | Purpose | Example |
|---|---|---|---|
user-prompt-submit |
Message sent | Load rules by keywords | "API" β loads api-design.md |
pre-tool-use |
Before tools | Validate plan approval | Block if no plan |
post-tool-use |
After edit/write | Run affected tests | Auto-test changes |
stop |
Response complete | Auto-commit changes | Git commit with message |
Hook Workflow Example
# user-prompt-submit.sh #!/bin/bash MESSAGE="$1" KEYWORDS=$(echo "$MESSAGE" | grep -oE 'API|test|React|database') for KEYWORD in $KEYWORDS; do case $KEYWORD in "API") load_rules "api-design" "security" "testing" ;; "test") load_rules "smart-testing" "playwright" ;; "React") load_rules "react-patterns" "typescript" ;; esac done
Auto-Commit Flow
Session End Detected
β
βββββββββββββββββββ
β Git Status β
β 5 files changed β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Generate Messageβ
β "feat: Add user β
β authentication"β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Create Rollback β
β rollback.sh β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Commit Changes β
β Conventional β
β format applied β
βββββββββββββββββββ
Page 9: Dynamic Rule Loading
Keyword-Based Loading System
Foundation Rules (Always Loaded): - core-workflow.md # 5% tokens - coding-standards.md # 3% tokens - documentation.md # 2% tokens Total: 10% context usage Contextual Rules (By Keywords): "API": β api-design.md, security.md (+8%) "React": β react-patterns.md, typescript.md (+7%) "test": β smart-testing.md, playwright.md (+6%) "database": β schema.md, migrations.md (+5%) "deploy": β deployment.md, git-workflow.md (+6%)
Token Optimization Results
Before Optimization: All Rules Loaded: 104,676 tokens Context Usage: 85% Load Time: ~3 seconds After Optimization: Smart Loading: 12,000 tokens (88% reduction) Context Usage: 25% Load Time: <500ms
Manifest Configuration
{
"rules": {
"api-design": {
"summary": "RESTful API best practices",
"file": "general-policies/backend/api-design.md",
"triggers": ["API", "endpoint", "REST", "backend"],
"dependencies": ["security", "testing"],
"priority": "high",
"tokens": 2500
}
}
}Page 10: Context Management
Context Window Optimization
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CONTEXT WINDOW STATUS β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Used: 45% [βββββββββββββββββββββββββββββββββββββββββββββ] β
β β
β Breakdown: β
β β’ Foundation Rules: 10% β
β β’ Context Rules: 15% β
β β’ Todo File: 5% β
β β’ Code Context: 15% β
β β’ Available: 55% β
β β
β Status: π’ Safe to continue β
β Recommendation: Can handle 3 more complex tasks β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Task Splitting Strategy
Large Feature: "Complete auth system" (90% context)
β
Split into Tasks
β
ββββββββββββ ββββββββββββ ββββββββββββ
β Task 1 β β Task 2 β β Task 3 β
β Login UI β β Auth API β β Testing β
β 30% ctx β β 35% ctx β β 25% ctx β
ββββββββββββ ββββββββββββ ββββββββββββ
Rule: Each task β€ 70% context for safety margin
Todo File Management
# Tasks: Authentication System Created: 2024-01-15 Context Budget: 70% per task ## Task Queue ### Task 1: Login UI [30% context] - [ ] Status: Pending - **Files**: LoginForm.tsx, styles.css - **LoC**: ~50 - **ROI**: High (10Γ10/50 = 2.0) ### Task 2: Auth Service [35% context] - [ ] Status: Pending - **Dependencies**: Task 1 - **Files**: auth.service.ts, auth.test.ts - **LoC**: ~80
Page 11: Quality Gates & Compliance
5-Stage Quality Gate System
Stage 1: Plan Validation
β Must have clear scope
Stage 2: Code Quality
β TypeScript, ESLint pass
Stage 3: Test Coverage
β 80%+ coverage required
Stage 4: Performance Check
β Response time < 200ms
Stage 5: Security Scan
β No vulnerabilities
PASSED β Deploy Ready
Compliance Tracking
Session Compliance Report: ββββββββββββββββββββββββββββββββββββββ β Rule Compliance: 100% β β β’ Plans Created: 5/5 β β β’ Plans Approved: 5/5 β β β’ Tests Written: 15/15 β β β’ Tests Passed: 15/15 β β β’ Quality Gates: 5/5 passed β β β’ Auto-commits: 3 successful β ββββββββββββββββββββββββββββββββββββββ
Error Recovery Flow
Error Detected: Test Failure
β
βββββββββββββββββββ
β Capture State β
β Save to backup β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Analyze Error β
β Identify cause β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Auto-Fix or β
β Rollback β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Verify Recovery β
β Run tests again β
βββββββββββββββββββ
Page 12: Performance & Metrics
System Performance Metrics
Testing Performance: Before: 3 minutes (full suite) After: 15 seconds (smart selection) Improvement: 92% faster Development Speed: Features/Week: 8 β 15 (87% increase) Bug Rate: 12/week β 2/week (83% reduction) Code Reuse: 20% β 80% (4x improvement) Quality Metrics: Test Coverage: 40% β 95% Plan Compliance: 60% β 100% First-Time Success: 45% β 90%
Real-Time Dashboard
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LIVE METRICS DASHBOARD β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Current Session: β
β β’ Tasks Completed: ββββββββββ 8/10 β
β β’ Tests Passed: βββββββββββββ 45/45 β
β β’ Context Used: βββββββββββββ 65% β
β β’ Time Saved: 2.5 hours β
β β
β Weekly Stats: β
β β’ Features Shipped: 12 β
β β’ Average LoC/Feature: 45 β
β β’ ROI Score: 8.7/10 β
β β
β Quality Score: βββββ 98/100 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Success Mantras
π "Stop and plan before you code"
Every line of code starts with a plan
π§ͺ "Test what users do, not how code works"
E2E tests validate user success
π "Maximum impact, minimum code"
ROI drives every decision
β "Ship working features, iterate later"
Perfect is the enemy of good
Page 13: Implementation Guide
Complete Setup Checklist
# 1. Initial Setup β‘ Copy .claude/rules/ to your project β‘ Copy .claude/docs/ to your project β‘ Place CLAUDE.md in project root β‘ Set up .claude/hooks directory β‘ Make hooks executable # 2. Configuration β‘ Configure .claude/rules/manifest.json β‘ Set up smart testing β‘ Configure auto-commit β‘ Initialize .claude/session tracking # 3. Validation β‘ Test hook execution β‘ Verify rule loading from .claude/rules/ β‘ Check test automation β‘ Validate commits work # 4. Team Training β‘ Share .claude/docs/ documentation β‘ Run demo session β‘ Review first PR β‘ Gather feedback
Common Issues & Solutions
| Issue | Solution | Prevention |
|---|---|---|
| Rules not loading | Check manifest.json paths | Validate on setup |
| Tests not running | Verify hook permissions | chmod +x hooks/*.sh |
| Context overflow | Use task splitting | Monitor context % |
| Commits failing | Check git config | Test git access |
| Slow performance | Review rule count | Use smart loading |
Integration Examples
Claude Code Settings (.claude/settings.json):
{
"claude.rulesPath": ".claude/rules",
"claude.docsPath": ".claude/docs",
"claude.hooksEnabled": true,
"claude.autoCommit": true,
"claude.testRunner": "auto-detect",
"claude.todoTracking": true
}CI/CD Pipeline:
- name: Run Claude Rules Check run: | .claude/hooks/validate-compliance.sh .claude/hooks/run-quality-gates.sh
Measuring Success
Track these KPIs weekly:
- Features Completed: Target 10+ per week
- Average LoC/Feature: Target < 50
- Code Reuse Rate: Target > 80%
- Test Coverage: Target > 90%
- Bug Rate: Target < 2 per week
- Plan Compliance: Target 100%
Getting Help
- π Documentation - Complete framework guide
- π€ Claude Code Docs - Official Claude Code documentation
- π Report Issues
- π¬ Discussions
- π§ Contact
π Start Your Transformation Today
Join hundreds of developers who have revolutionized their Claude Code workflow
git clone https://github.com/sahin/ai-rules.git cd ai-rules && ./install.sh
β Star this repo β’ π Fork it β’ π’ Share it
Built with discipline, tested with rigor, delivered with confidence
Β© 2024 Sahin AI Rules Framework | MIT License
Making Claude Code work the way it should - systematically, efficiently, and reliably