v2/docs/features/automatic-error-recovery.md
Claude-Flow v2.7.35+ includes intelligent automatic error recovery that handles common installation and initialization issues without manual intervention.
The error recovery system automatically detects and fixes:
The system automatically detects common error patterns:
// Detects npm cache errors
if (error.includes('ENOTEMPTY') && error.includes('npm')) {
// Automatic recovery triggered
}
// Detects better-sqlite3 issues
if (error.includes('better-sqlite3')) {
// Automatic recovery triggered
}
When an error is detected, the system:
npm cache clean --force)~/.npm/_npx)// Automatic retry with backoff
retryWithRecovery(operation, {
maxRetries: 5, // Try up to 5 times
delay: 1000, // Start with 1s delay
exponentialBackoff: true // 1s, 2s, 4s, 8s, 16s
});
If SQLite continues to fail:
// Automatic fallback to JSON storage
if (sqliteInitFails && retries > maxRetries) {
console.log('🔄 Switching to JSON storage...');
switchToJSONProvider();
}
# Standard initialization with automatic recovery
npx claude-flow@alpha init
# Force mode with extended retries (5 attempts)
npx claude-flow@alpha init --force
For advanced users, manual recovery tools are also available:
# Clean npm cache manually
npm cache clean --force
rm -rf ~/.npm/_npx
# Check WSL environment
npx claude-flow@alpha diagnose --wsl
# Verify dependencies
npx claude-flow@alpha verify --deps
┌─────────────────────────┐
│ Initialize Command │
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ Detect WSL? Apply Fixes│
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ Run Initialization │
└───────────┬─────────────┘
│
▼
Error Detected?
│
┌───────┴───────┐
│ │
Yes No
│ │
▼ ▼
┌─────────────┐ Success!
│ Is Npm Cache│
│ Error? │
└─────┬───────┘
│
Yes
│
▼
┌─────────────────────────┐
│ Clean npm/npx cache │
│ Fix permissions │
│ Apply WSL optimizations │
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ Retry with Backoff │
│ (Attempt N/5) │
└───────────┬─────────────┘
│
▼
Max Retries?
│
┌───────┴───────┐
│ │
Yes No
│ │
▼ ▼
┌─────────────┐ Try Again
│ Fallback to │
│ JSON Storage│
└─────────────┘
// Automatic WSL detection
if (process.platform === 'linux') {
const isWSL = fs.readFileSync('/proc/version', 'utf8')
.toLowerCase()
.includes('microsoft');
if (isWSL) {
applyWSLOptimizations();
}
}
chmod -R 755 ~/.npm)/mnt/c/)// In your code or configuration
export interface RetryOptions {
maxRetries?: number; // Default: 3 (5 with --force)
delay?: number; // Default: 1000ms
exponentialBackoff?: boolean; // Default: true
cleanupFn?: () => Promise<void>; // Custom cleanup
}
// .claude-flow/config.json
{
"errorRecovery": {
"enabled": true,
"maxRetries": 5,
"cleanCacheOnError": true,
"wslOptimizations": true,
"fallbackToJSON": true
}
}
npx claude-flow@alpha init --force
🔍 WSL environment detected
✅ WSL environment optimized
📁 Phase 1: Creating directory structure...
⚠️ Detected npm cache error (attempt 1/5)
🧹 Cleaning npm cache...
✅ npm cache cleaned
🗑️ Removing npx cache: /home/user/.npm/_npx
✅ npx cache removed
✅ npm directory permissions fixed
✅ Cache cleaned, retrying...
🔄 Retry attempt 1 after error recovery...
✅ Recovered from error, retrying initialization...
📁 Phase 1: Creating directory structure...
⚙️ Phase 2: Creating configuration...
🎉 Project initialized successfully!
# Enable verbose error recovery logging
DEBUG=claude-flow:error-recovery npx claude-flow@alpha init --force
import { errorRecovery } from 'claude-flow/utils/error-recovery';
// Check if error is recoverable
if (errorRecovery.isNpmCacheError(error)) {
// Clean cache
await errorRecovery.cleanNpmCache();
// Retry operation
await errorRecovery.retryWithRecovery(myOperation, {
maxRetries: 5,
delay: 1000
});
}
// Custom cleanup function
await errorRecovery.retryWithRecovery(
async () => {
return await myOperation();
},
{
maxRetries: 3,
cleanupFn: async () => {
// Custom cleanup logic
await fs.remove('./temp-files');
await clearCustomCache();
}
}
);
Error recovery adds minimal overhead:
Check WSL version: Use WSL2 (not WSL1)
wsl --list --verbose
wsl --set-version Ubuntu 2
Install build tools:
sudo apt-get update
sudo apt-get install -y build-essential python3
Use WSL filesystem (not /mnt/c/):
cd ~/projects # Good
cd /mnt/c/Users/name/project # Bad
Manual cache cleanup:
sudo npm cache clean --force
sudo rm -rf ~/.npm
Need Help? Report issues at https://github.com/ruvnet/claude-flow/issues