SnapBack

Pattern Learning

SnapBack gets smarter the longer you use it.

Day 1: catches common patterns. Day 30: learns YOUR risks. Day 90: predicts issues before you notice them.

Pattern learning is SnapBack’s intelligence layer that transforms from a generic protection tool into a codebase-specific risk prevention system.

How Pattern Learning Works

The Learning Loop

Every interaction teaches SnapBack about your codebase:

graph LR
    A[Code Change] --> B[Context Capture]
    B --> C[Pattern Analysis]
    C --> D[Risk Scoring]
    D --> E[Protection Decision]
    E --> F[User Feedback]
    F --> G[Pattern Update]
    G --> C

📅 Day 1

Catches common patterns with 94% accuracy:

  • • Hardcoded secrets in code
  • • Phantom dependencies
  • • Test code in production
  • • Risky refactoring patterns

📈 Day 30

Learns YOUR specific risks:

  • • “Cursor breaks this auth module”
  • • “This refactor pattern fails”
  • • “This folder has issues”
  • • Your team’s coding patterns

🎯 Day 90

Predicts issues proactively:

  • • Folder-specific fragility
  • • Pattern-specific risks
  • • Tool-specific warnings
  • • Preemptive protection

What SnapBack Learns

File Fragility

SnapBack tracks which files cause issues:

interface FileFragilityScore {
  filePath: string;
  issueFrequency: number;      // How often issues occur
  lastIssueDate: Date;         // Recency weighting
  aiToolCorrelation: {         // Which AI tools cause issues
    cursor: number;
    copilot: number;
    claude: number;
  };
  patternTriggers: string[];   // What patterns cause issues
}

Example insight: “src/auth/login.ts has 3x higher issue rate when modified by Cursor”

AI Tool Behavior

Each AI assistant has different strengths and weaknesses in your codebase:

🔵 Cursor85% success rate

Strong at: Refactoring, TypeScript types

Weak at: Auth modules, database queries

🟣 GitHub Copilot89% success rate

Strong at: Boilerplate, common patterns

Weak at: Complex async logic, edge cases

🟠 Claude Code92% success rate

Strong at: Architecture, comprehensive refactors

Weak at: Minor edits (tends to over-engineer)

Change Patterns

SnapBack recognizes patterns that lead to issues:

PatternRisk LevelDetection
Async function conversionMediumFunction signature changes
Variable renaming across filesHighMulti-file simultaneous edits
Import restructuringMediumImport statement patterns
Type definition changesHighInterface/type modifications
Configuration file editsCritical.env, config, package.json

Pattern Categories

Risk Patterns

Patterns that indicate elevated risk:

// HIGH RISK: Async conversion without error handling
// Before
function getData() { return fetch('/api').then(r => r.json()); }

// After (AI changed)
async function getData() { return await fetch('/api').json(); }
// Missing: .then(), error handling, await on response

SnapBack learns: “Async conversions in src/api/ frequently miss error handling”

Success Patterns

Patterns that work well in your codebase:

// SUCCESS PATTERN: Your team's error handling style
async function getData() {
  try {
    const response = await fetch('/api');
    if (!response.ok) throw new Error(`HTTP ${response.status}`);
    return await response.json();
  } catch (error) {
    logger.error('getData failed', { error });
    throw error;
  }
}

SnapBack learns: “This error handling pattern succeeds 95% of the time”

Anti-Patterns

Patterns your codebase should avoid:

// ANTI-PATTERN: Silent error swallowing
async function getData() {
  try {
    return await fetch('/api').then(r => r.json());
  } catch (e) {
    return null; // SnapBack flags this
  }
}

SnapBack learns: “Silent catches in src/ cause issues 78% of the time”

Viewing Pattern Insights

In VS Code

Access pattern insights through the SnapBack sidebar:

  1. Click the Patterns tab in the sidebar
  2. View patterns grouped by:
    • File patterns - Which files are fragile
    • Tool patterns - AI tool behavior in your codebase
    • Change patterns - Types of changes that cause issues

CLI Access

# View learned patterns
snap patterns list

# View patterns for a specific file
snap patterns show src/auth/login.ts

# View AI tool performance
snap patterns tools

# Export pattern data
snap patterns export --format json > patterns.json

Pattern Report

$ snap patterns report

📊 Pattern Learning Report
==========================

Files at Risk (top 5):
  1. src/auth/login.ts      - 3.2x baseline risk
  2. src/db/queries.ts      - 2.8x baseline risk
  3. src/api/handlers.ts    - 2.1x baseline risk

AI Tool Performance:
  Cursor:     85% success | 12% issues | 3% critical
  Copilot:    89% success | 9% issues  | 2% critical
  Claude:     92% success | 6% issues  | 2% critical

Common Issue Patterns:
 Async conversion without error handling (34%)
 Variable renaming inconsistencies (28%)
 Import path changes (18%)
 Type definition conflicts (12%)
 Other (8%)

Pattern-Based Protection

Automatic Risk Adjustment

When SnapBack detects a risky pattern, it automatically adjusts protection:

Normal file save:
  └── Standard protection state created

Risky pattern detected:
  └── Protection state created
  └── Detailed context captured
  └── Warning badge added
  └── Pattern tracked for learning

Preemptive Warnings

After learning your codebase, SnapBack can warn before issues occur:

⚠️ Pattern Warning
━━━━━━━━━━━━━━━━━━

Cursor is modifying src/auth/login.ts

Historical data shows:
  • 3x higher issue rate for this file
  • 2 issues in the last 7 days
  • Common pattern: async conversion errors

Recommendation: Review changes carefully before saving

Privacy and Data

All pattern learning happens locally by default.

Your code patterns, file names, and codebase structure never leave your machine unless you explicitly opt-in to anonymous pattern sharing.

What’s Stored Locally

  • File fragility scores (relative paths only)
  • AI tool performance metrics
  • Change pattern frequencies
  • Risk correlations

What’s Never Collected

  • Actual code content
  • File contents or diffs
  • Proprietary logic or algorithms
  • Personal or team identifiers

Optional: Anonymous Pattern Sharing

Help improve SnapBack for everyone by sharing anonymized patterns:

// Example anonymized pattern (what gets shared)
{
  "pattern_type": "async_conversion",
  "risk_level": 0.72,
  "context": "auth_module",
  "outcome": "issue_detected",
  "ai_tool": "cursor"
}

Enable in settings: SnapBack → Share Anonymous Patterns

Configuring Pattern Learning

Sensitivity Adjustment

// .snapbackrc
{
  "patternLearning": {
    "sensitivity": "high",    // low, medium, high
    "lookbackDays": 30,       // How far back to analyze
    "minSampleSize": 5,       // Minimum events for pattern
    "weightRecency": true     // Prioritize recent patterns
  }
}

File-Specific Overrides

// .snapbackrc
{
  "patternOverrides": {
    "src/auth/**": {
      "riskMultiplier": 1.5,
      "alwaysProtect": true
    },
    "**/*.test.ts": {
      "riskMultiplier": 0.5,
      "learningEnabled": false
    }
  }
}

Next Steps

🤖 AI Detection

How SnapBack detects and attributes AI-generated changes.

Learn more →

⏱️ Sessions

How sessions group related changes for pattern analysis.

Explore sessions →

Privacy First: SnapBack works 100% offline on the Free plan. MCP is optional and requires explicit consent on paid plans. Learn more →