Always Preview First
Run cortex-tms migrate (no flags) before applying. Understand what will change.
The cortex-tms migrate command upgrades TMS template files to the latest version while preserving your custom changes. It includes a Safe-Fail Migration Engine with automatic backups, smart upgrade detection, and one-click rollback.
cortex-tms migrate [options]Template Evolution Without Fear. Templates improve over time, but your customizations matter. The migrate command solves the upgrade problem with three components:
How it works:
--force)Typical workflow:
# Check migration status (safe preview)cortex-tms migrate
# Apply automatic upgradescortex-tms migrate --apply
# If something breaks, rollbackcortex-tms migrate --rollback-a, --applyApply automatic upgrades with backup creation.
Behavior:
.cortex/backups/--force also used)Example:
cortex-tms migrate --applyOutput:
π Cortex TMS Migration
β Configuration loadedβ Analyzed 12 files
π Migration Summary: β 3 file(s) can be safely upgraded β 2 file(s) have custom changes (manual review needed)
πΎ Creating backup...β Backup created: .cortex/backups/2026-01-19T10-30-00-123Z 3 file(s) backed up safely
π Applying upgrades...β Upgraded 3 file(s) to v2.6.0
β¨ Migration complete!
π‘ Tip: Review changes with: git diff
π‘ To rollback, run: cortex-tms migrate --rollback-r, --rollbackRestore files from a previous backup snapshot.
Interactive selection:
Example:
cortex-tms migrate --rollbackOutput:
βͺ Cortex TMS Rollback
β Found 3 backup(s)
? Select a backup to restore:β― 2026-01-19T10-30-00-123Z - v2.6.0 - 3 file(s) - 12.5 KB 2026-01-15T14-22-15-456Z - v2.5.0 - 5 file(s) - 18.2 KB 2026-01-10T09-15-30-789Z - v2.4.0 - 4 file(s) - 15.1 KB Cancel
π Files to be restored: β NEXT-TASKS.md β CLAUDE.md β docs/core/PATTERNS.md
? This will overwrite current files. Continue? Yes
βͺ Restoring backup...β Restored 3 file(s) from backup
β¨ Rollback complete!
π‘ Tip: Review restored files with: git diff-f, --forceForce upgrade of CUSTOMIZED files (requires --apply).
Use with caution: This will overwrite files that have custom changes.
Workflow:
Example:
cortex-tms migrate --apply --forceOutput shows warning:
π Files to be upgraded: β NEXT-TASKS.md β οΈ CLAUDE.md (CUSTOMIZED) β οΈ docs/core/PATTERNS.md (CUSTOMIZED)
β οΈ 2 CUSTOMIZED file(s) will be overwritten due to --force flag-v, --verboseShow detailed output during migration analysis.
Extra information:
Example:
cortex-tms migrate --verboseOutput includes:
Analyzing files... β NEXT-TASKS.md - LATEST (v2.6.0 = v2.6.0) π CLAUDE.md - OUTDATED (v2.5.0 β v2.6.0) β οΈ docs/core/PATTERNS.md - CUSTOMIZED (v2.5.0 β v2.6.0) Reason: File has custom changes βΉοΈ FUTURE-ENHANCEMENTS.md - MISSING Reason: File not installed-d, --dry-runPreview migration changes without applying them.
What it shows:
Example:
cortex-tms migrate --dry-runOutput:
π DRY RUN MODE: No files will be modified.
β Configuration loadedβ Analyzed 12 files
π Migration Report (Target: v2.6.0):
β
UP TO DATE (8): NEXT-TASKS.md v2.6.0 = v2.6.0 CLAUDE.md v2.6.0 = v2.6.0 ...
π OUTDATED (2): docs/core/PATTERNS.md v2.5.0 β v2.6.0 .github/copilot-instructions.md v2.5.0 β v2.6.0
β οΈ CUSTOMIZED (1): FUTURE-ENHANCEMENTS.md v2.4.0 β v2.6.0 - File has custom changes
βΉοΈ NOT INSTALLED (1): docs/core/SECURITY.md - File not installed
π Next Steps: 1. Review OUTDATED files marked above β These match the old template and can be safely upgraded 2. Review CUSTOMIZED files marked above β These have custom changes - preserve your modifications
π Automatic Upgrade Available: cortex-tms migrate --apply β Safely upgrade OUTDATED files (creates backup)Meaning: File is already on the target version
Example:
β
UP TO DATE (1): NEXT-TASKS.md v2.6.0 = v2.6.0Action: Nothing needed
Meaning: File matches old template exactly (no customizations)
Example:
π OUTDATED (1): CLAUDE.md v2.5.0 β v2.6.0Action: Safe to auto-upgrade with --apply
How itβs detected:
<!-- @cortex-tms-version 2.5.0 -->Meaning: File has custom changes beyond template
Example:
β οΈ CUSTOMIZED (1): docs/core/PATTERNS.md v2.5.0 β v2.6.0 - File has custom changesAction: Manual review required (or --force to overwrite)
How itβs detected:
Manual merge workflow:
# See what's new in latest templatediff docs/core/PATTERNS.md node_modules/cortex-tms/templates/docs/core/PATTERNS.md
# Manually merge changesvim docs/core/PATTERNS.md
# Update version comment# <!-- @cortex-tms-version 2.6.0 -->Meaning: File not installed (optional file from scope)
Example:
βΉοΈ NOT INSTALLED (1): docs/core/SECURITY.md - File not installedAction: Optional, install manually if needed
Install manually:
# Copy from templatescp node_modules/cortex-tms/templates/docs/core/SECURITY.md docs/core/
# Or reinitialize with broader scopecortex-tms init --scope enterprise --forceLocation: .cortex/backups/<timestamp>/
Timestamp format: YYYY-MM-DDTHH-MM-SS-sssZ
Example:
.cortex/βββ backups/ βββ 2026-01-19T10-30-00-123Z/ β βββ manifest.json β βββ NEXT-TASKS.md β βββ CLAUDE.md β βββ docs/ β βββ core/ β βββ PATTERNS.md βββ 2026-01-15T14-22-15-456Z/ β βββ ... βββ 2026-01-10T09-15-30-789Z/ βββ ...File: .cortex/backups/<timestamp>/manifest.json
Contents:
{ "timestamp": "2026-01-19T10:30:00.123Z", "version": "2.6.0", "reason": "migrate to v2.6.0", "files": [ { "relativePath": "NEXT-TASKS.md", "originalPath": "/home/user/project/NEXT-TASKS.md", "size": 4521 }, { "relativePath": "CLAUDE.md", "originalPath": "/home/user/project/CLAUDE.md", "size": 3201 } ]}Purpose:
Default: Backups are kept indefinitely
Manual cleanup:
# List backups with sizesdu -sh .cortex/backups/*
# Remove old backups (older than 30 days)find .cortex/backups -type d -mtime +30 -exec rm -rf {} \;
# Keep only 5 most recentls -t .cortex/backups | tail -n +6 | xargs -I {} rm -rf .cortex/backups/{}Preview Migration Status
cortex-tms migrateReview which files are OUTDATED, CUSTOMIZED, or LATEST
Commit Current State
git add .git commit -m "chore: commit before template migration"Safety net for rollback
Apply Upgrades
cortex-tms migrate --applyUpgrades OUTDATED files, skips CUSTOMIZED files
Review Changes
git diffSee what changed in upgraded files
Handle CUSTOMIZED Files
Option A: Manual merge
# Compare with templatediff docs/core/PATTERNS.md node_modules/cortex-tms/templates/docs/core/PATTERNS.md
# Merge manuallyvim docs/core/PATTERNS.mdOption B: Force upgrade, then re-add customizations
# Backup custom sections firstgrep "## Custom Section" docs/core/PATTERNS.md > custom.txt
# Force upgradecortex-tms migrate --apply --force
# Re-add customizationsvim docs/core/PATTERNS.md# Paste custom.txt content backValidate Installation
cortex-tms validate --strictEnsure no issues after migration
Test Changes
# Test buildnpm run build
# Test developmentnpm run devCommit Migration
git add .git commit -m "chore: migrate TMS templates to v2.6.0"(Optional) Rollback If Issues
cortex-tms migrate --rollback# Select backup to restore# Check what needs upgradingcortex-tms migrateOutput:
π Migration Report (Target: v2.6.0):
β
UP TO DATE (10): NEXT-TASKS.md v2.6.0 = v2.6.0 ...
π OUTDATED (2): docs/core/PATTERNS.md v2.5.0 β v2.6.0 CLAUDE.md v2.5.0 β v2.6.0
π Next Steps: cortex-tms migrate --apply# Apply upgradescortex-tms migrate --applyOutput:
π Cortex TMS Migration
πΎ Creating backup...β Backup created: .cortex/backups/2026-01-19T10-30-00-123Z
π Applying upgrades...β Upgraded 2 file(s) to v2.6.0
β¨ Migration complete!# Review changesgit diff
# Validate healthcortex-tms validate --strict
# Commitgit commit -am "chore: migrate TMS templates to v2.6.0"# Preview shows CUSTOMIZED filescortex-tms migrate
# Output:# β οΈ CUSTOMIZED (1):# docs/core/PATTERNS.md v2.5.0 β v2.6.0 - File has custom changes
# Option 1: Manual mergediff docs/core/PATTERNS.md node_modules/cortex-tms/templates/docs/core/PATTERNS.mdvim docs/core/PATTERNS.md# Merge changes manually
# Option 2: Force upgrade (overwrites customizations)cortex-tms migrate --apply --force# Warning: Custom changes lost, but backup exists
# Restore customizations from Git historygit diff HEAD~1 docs/core/PATTERNS.md# Copy custom sections back# Applied upgrade but something brokecortex-tms migrate --apply
# Tests failnpm test# FAIL: pattern validation
# Rollback to previous statecortex-tms migrate --rollback
# Select most recent backup? Select a backup to restore:β― 2026-01-19T10-30-00-123Z - v2.6.0 - 3 file(s)
# Restored successfully⨠Rollback complete!
# Tests now passnpm test# PASS# On staging branch, test migrationgit checkout stagingcortex-tms migrate --dry-run
# Review what would change# No files modified
# If looks good, applycortex-tms migrate --apply
# Test thoroughlynpm run testnpm run build
# If successful, apply to productiongit checkout maincortex-tms migrate --apply| Code | Meaning | Scenario |
|---|---|---|
0 | Success | Migration analysis completed or upgrades applied |
1 | Error | No .cortexrc found, backup failed, template errors |
Backup failure behavior:
Problem: Project not initialized with Cortex TMS
Solution:
cortex-tms initcortex-tms migrateProblem: Cannot create backup directory or write files
Causes:
.cortex/ directory read-onlySolution:
# Check disk spacedf -h
# Check permissionsls -la .cortex/chmod 755 .cortex/
# Ensure .cortex/backups/ exists and is writablemkdir -p .cortex/backupschmod 755 .cortex/backups
# Retry migrationcortex-tms migrate --applyProblem: Cortex TMS installation incomplete or corrupted
Solution:
# Reinstall Cortex TMSnpm uninstall -g cortex-tmsnpm install -g cortex-tms@latest
# Verify templates existls node_modules/cortex-tms/templates/
# Retry migrationcortex-tms migrateNot an error, just informational. Files with custom changes require manual review.
Solutions:
# Compare with templatediff docs/core/PATTERNS.md \ node_modules/cortex-tms/templates/docs/core/PATTERNS.md
# Apply changes manuallyvim docs/core/PATTERNS.md# Backup customizations firstcp docs/core/PATTERNS.md docs/core/PATTERNS.md.custom
# Force upgradecortex-tms migrate --apply --force
# Re-add custom sectionsvim docs/core/PATTERNS.md# Paste from PATTERNS.md.customCause: Version metadata missing or incorrect format
Check version comments:
grep "@cortex-tms-version" NEXT-TASKS.mdExpected:
<!-- @cortex-tms-version 2.6.0 -->Fix missing metadata:
# Add version comment to top of filevim NEXT-TASKS.md# Add: <!-- @cortex-tms-version 2.5.0 -->Cause: No backups created yet (first migration) or backups deleted
Solution:
# Check .cortex/backups/ directoryls -la .cortex/backups/
# If empty, cannot rollback# Use Git instead:git log --onelinegit checkout <commit-hash> -- NEXT-TASKS.mdCause: Very large project with thousands of files
Solution:
# Kill hung processCtrl+C
# Check project sizefind . -type f | wc -l
# Migration only checks files listed in .cortexrc scope# If custom scope, reduce file listvim .cortexrcAlways Preview First
Run cortex-tms migrate (no flags) before applying. Understand what will change.
Commit Before Migrate
Commit your changes to Git before running --apply. Provides fallback beyond backups.
Test After Migration
Run tests and builds after migration. Validate everything works before committing.
Review Diffs Carefully
Use git diff to see template changes. Understand whatβs new before accepting.
name: Auto-Migrate Templates
on: schedule: - cron: '0 0 * * 0' # Every Sunday at midnight workflow_dispatch:
jobs: migrate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20'
- name: Install Cortex TMS run: npm install -g cortex-tms@latest
- name: Check Migration Status id: check run: | cortex-tms migrate > migration-report.txt if grep -q "OUTDATED" migration-report.txt; then echo "needs_migration=true" >> $GITHUB_OUTPUT fi
- name: Apply Migration if: steps.check.outputs.needs_migration == 'true' run: cortex-tms migrate --apply
- name: Create Pull Request if: steps.check.outputs.needs_migration == 'true' uses: peter-evans/create-pull-request@v5 with: title: "chore: migrate TMS templates to latest version" body: | Automated template migration detected updates.
## Migration Report
\`\`\` $(cat migration-report.txt) \`\`\`
## Backup Created
Backup snapshot: `.cortex/backups/<timestamp>`
## Rollback Command
If issues arise: \`\`\` cortex-tms migrate --rollback \`\`\` branch: chore/auto-migrate-templates delete-branch: true# Only migrate specific files (not officially supported, manual workaround)
# Step 1: Check migration statuscortex-tms migrate
# Step 2: Manually copy specific templatescp node_modules/cortex-tms/templates/CLAUDE.md ./CLAUDE.md
# Step 3: Update version commentvim CLAUDE.md# Change: <!-- @cortex-tms-version 2.5.0 --># To: <!-- @cortex-tms-version 2.6.0 -->
# Step 4: Validatecortex-tms validate# Upgrade templatescortex-tms migrate --apply
# Check healthcortex-tms validate
# View dashboardcortex-tms status# Initialize projectcortex-tms init --scope standard
# Later, when new version availablecortex-tms migrate --apply# Migrate templatescortex-tms migrate --apply
# Ensure no validation errorscortex-tms validate --strictcortex-tms init - Initialize TMS (creates files to migrate)cortex-tms validate - Verify health after migrationcortex-tms status - View project state post-migration