v2/src/migration/README.md
A comprehensive migration system for existing claude-flow projects to adopt optimized prompts and configurations.
The migration system provides tools to:
# Analyze your project
npx claude-flow migrate analyze
# Run migration with dry-run preview
npx claude-flow migrate --dry-run --verbose
# Migrate with selective strategy (recommended)
npx claude-flow migrate --strategy selective --preserve-custom
# Rollback if needed
npx claude-flow migrate rollback
.claude folder--strategy full--strategy selective --preserve-custom--strategy merge# Basic analysis
claude-flow migrate analyze
# Detailed analysis with output file
claude-flow migrate analyze --detailed --output analysis.json
# Check specific project
claude-flow migrate analyze /path/to/project
# Preview changes (safe)
claude-flow migrate --dry-run --verbose
# Full migration
claude-flow migrate --strategy full
# Selective migration (recommended)
claude-flow migrate --strategy selective --preserve-custom
# Merge migration for complex projects
claude-flow migrate --strategy merge
# Force migration without prompts
claude-flow migrate --force
# Skip post-migration validation
claude-flow migrate --skip-validation
# List available backups
claude-flow migrate rollback --list
# Rollback to latest backup
claude-flow migrate rollback
# Rollback to specific backup
claude-flow migrate rollback --timestamp 2024-01-01T12:00:00
# Force rollback without confirmation
claude-flow migrate rollback --force
# Validate migration
claude-flow migrate validate
# Detailed validation report
claude-flow migrate validate --verbose
# Check project status
claude-flow migrate status
The system uses a manifest file (migration-manifest.json) to define:
{
"version": "1.0.0",
"files": {
"commands": {
"sparc.md": {
"source": ".claude/commands/sparc.md",
"target": ".claude/commands/sparc.md",
"transform": "replace",
"priority": 1
}
}
},
"strategies": {
"selective": {
"preserveCustom": true,
"backupRequired": true,
"riskLevel": "medium"
}
}
}
Projects can include migration preferences in CLAUDE.md:
## Migration Configuration
- strategy: selective
- preserveCustom: true
- customCommands: ['my-command', 'special-workflow']
import { MigrationRunner, MigrationAnalyzer } from 'claude-flow/migration';
// Analyze project
const analyzer = new MigrationAnalyzer();
const analysis = await analyzer.analyze('./my-project');
// Run migration
const runner = new MigrationRunner({
projectPath: './my-project',
strategy: 'selective',
preserveCustom: true,
dryRun: false,
});
const result = await runner.run();
console.log(`Migration ${result.success ? 'succeeded' : 'failed'}`);
import { RollbackManager } from 'claude-flow/migration';
const rollback = new RollbackManager('./my-project');
// Create backup
const backup = await rollback.createBackup({
type: 'pre-migration',
description: 'Before optimization update',
});
// List backups
const backups = await rollback.listBackups();
// Rollback
await rollback.rollback(backup.metadata.backupId);
# For new projects without existing customizations
claude-flow migrate --strategy full
Result: Clean installation of all optimized prompts and configurations.
# Analyze first
claude-flow migrate analyze --detailed
# Selective migration preserving customizations
claude-flow migrate --strategy selective --preserve-custom
Result: Core files updated, custom commands preserved.
# Use merge strategy for complex setups
claude-flow migrate --strategy merge --preserve-custom
# Validate after migration
claude-flow migrate validate --verbose
Result: Configurations merged, custom content preserved.
# Preview all changes
claude-flow migrate --dry-run --verbose
# Run actual migration if satisfied
claude-flow migrate --strategy selective
Result: Risk-free preview of all changes before applying.
# Find and migrate multiple projects
find . -name ".claude" -type d | while read dir; do
project_path=$(dirname "$dir")
echo "Migrating $project_path"
claude-flow migrate "$project_path" --strategy selective --force
done
Result: Multiple projects migrated with consistent strategy.
Every migration creates automatic backups:
.claude-backup/ directoryThe analyzer detects potential conflicts:
Multiple rollback options:
# Check and fix permissions
chmod -R u+w .claude/
claude-flow migrate --strategy selective
# Use preserve-custom flag
claude-flow migrate --strategy selective --preserve-custom
# Run detailed validation
claude-flow migrate validate --verbose
# Check for missing files or corruption
ls -la .claude/commands/
# List available backups
claude-flow migrate rollback --list
# Check backup integrity
cat .claude-backup/*/backup-manifest.json
Enable detailed logging:
export DEBUG=true
claude-flow migrate --verbose
Migration logs are stored in:
logs/migration.logCreate custom migration scripts using the API:
import { MigrationRunner } from 'claude-flow/migration';
class CustomMigration extends MigrationRunner {
async customTransform(content: string): Promise<string> {
// Apply custom transformations
return content.replace(/old-pattern/g, 'new-pattern');
}
}
Add custom validation rules:
import { MigrationValidator } from 'claude-flow/migration';
class ProjectValidator extends MigrationValidator {
async validateCustomRules(projectPath: string): Promise<ValidationResult> {
// Custom validation logic
return super.validate(projectPath);
}
}
Automate migrations in CI/CD pipelines:
# .github/workflows/migrate.yml
steps:
- name: Analyze Migration
run: claude-flow migrate analyze --output analysis.json
- name: Run Migration
run: claude-flow migrate --strategy selective --force
- name: Validate Migration
run: claude-flow migrate validate
--skip-validation for speed (not recommended for production)Typical performance metrics:
# Clone and setup
git clone https://github.com/ruvnet/claude-code-flow
cd claude-code-flow
npm install
# Run migration tests
npm test src/migration/
# Build migration system
npm run build:migration
# Unit tests
npm test src/migration/tests/
# Integration tests
npm run test:integration
# End-to-end tests
npm run test:e2e
MigrationAnalyzer for new detection rulesMigrationRunnerMigrationValidatorThis migration system is part of claude-code-flow and follows the same license terms.
For more information, see the main claude-code-flow documentation.