Skip to content

sahin/ai-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Sahin Claude Code Rules - The Ultimate Claude Code Framework

Version Status Compliance Framework

Transform Claude Code from a helpful tool into a disciplined, systematic, and highly efficient development partner

Quick Start12 Core RulesAgent FrameworkVisual WorkflowImplementationConnect


🌐 Connect with Sahin

LinkedIn Twitter


📖 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:

  1. Load backend, testing, and security rules
  2. Create a structured implementation plan
  3. Ask for your approval before coding
  4. Write E2E tests first (Playwright/Jest)
  5. Implement minimal code to pass tests
  6. Run tests automatically after changes
  7. 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 passed

Page 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


🌟 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages