Migrate
Perform systematic codebase migrations — upgrading dependencies, swapping libraries, adopting new APIs, or modernizing patterns.
Instructions
Perform the migration described in $ARGUMENTS. The argument should indicate what to migrate (e.g., "upgrade React from 17 to 18", "swap moment.js with date-fns", "adopt the new config API").
Step 1: Understand the migration scope
Identify the migration type:
- upgrade — Bump a dependency to a new major/minor version and update breaking changes
- swap — Replace one library/tool with another that serves the same purpose
- adopt — Move from an old pattern/API to a new one across the codebase
- modernize — Update legacy code to use current language features or idioms
Research the migration:
Use the Agent tool to launch 2 research agents in parallel:
Agent 1: Current usage scan (subagent_type: Explore, thoroughness: very thorough)
Find every usage of [the library/pattern/API being migrated away from] in this codebase.
Search for:
- Import/require statements
- Direct API calls and method usage
- Type references and interface implementations
- Configuration entries (build config, lint config, etc.)
- Usage in tests and test fixtures
- References in documentation, comments, and scripts
- Transitive usage through wrapper modules
For each usage, report: file:line, the specific API/pattern used, and surrounding context.
Group by file, sort by frequency of usage.
Report total count of usages and number of files affected.
Agent 2: Migration guide research (subagent_type: general-purpose)
Research the migration from [source] to [target].
Find:
- Official migration guide or changelog (search the web)
- Breaking changes between versions (if an upgrade)
- API mapping: old API → new API equivalents
- Known gotchas, edge cases, or compatibility issues
- Codemods or automated migration tools available
- Required peer dependency changes
Summarize as a concise mapping table: old pattern → new pattern.
Flag any changes that require manual judgment (not a 1:1 swap).
Step 2: Create the migration plan
Present the plan to the user:
## Migration Plan
**Type:** [upgrade | swap | adopt | modernize]
**From:** [current library/version/pattern]
**To:** [target library/version/pattern]
### Scope
- **Files affected:** N
- **Total usages:** N
- **Automated:** N (1:1 mappings that can be mechanically replaced)
- **Manual review:** N (changes requiring judgment)
### API Mapping
| Old | New | Notes |
|-----|-----|-------|
| ... | ... | ... |
### Migration steps
1. [Ordered list of steps]
### Risks
- [Breaking changes, behavioral differences, or edge cases]
Wait for user confirmation before proceeding.
Step 3: Execute the migration
Apply changes in a safe order:
- Update dependencies first — bump versions in package manifests, update lockfile
- Apply mechanical replacements — 1:1 API swaps that don't require judgment, working file by file
- Handle complex migrations — changes that require understanding context or choosing between alternatives
- Update types — adjust type imports, interfaces, and generics to match the new API
- Update configuration — build config, lint rules, babel/bundler plugins
- Update tests — adapt test code, update mocks/stubs, fix broken assertions
- Clean up — remove old library imports, delete compatibility shims, remove unused polyfills
Guidelines
- Work file by file — complete all changes in one file before moving to the next
- Preserve behavior — the migration should not change what the code does, only how it does it
- Don't mix refactoring with migration — resist the urge to "improve" code while migrating; that makes it harder to verify the migration is correct
- Flag ambiguous cases — when the old and new APIs aren't equivalent, flag it for the user rather than guessing
- Keep the old dependency until done — don't remove the old library from the manifest until all usages are migrated
Step 4: Verify
After applying changes:
- Search for any remaining references to the old library/API/pattern
- Check that no old imports or require statements remain
- If a codemod was available, compare its output against manual changes for consistency
- List all files modified for the user to review
- Suggest running tests and the build to verify nothing is broken
- If any usages couldn't be migrated automatically, list them with explanations
1---2name: migrate3description: Perform codebase migrations: upgrade dependencies, swap libraries, adopt new APIs or patterns, and modernize legacy code. Use when the user wants to migrate, upgrade, swap a library, adopt a new pattern, or modernize code.4---56# Migrate78Perform systematic codebase migrations — upgrading dependencies, swapping libraries, adopting new APIs, or modernizing patterns.910## Instructions1112Perform the migration described in `$ARGUMENTS`. The argument should indicate what to migrate (e.g., "upgrade React from 17 to 18", "swap moment.js with date-fns", "adopt the new config API").1314### Step 1: Understand the migration scope15161. **Identify the migration type:**17 - **upgrade** — Bump a dependency to a new major/minor version and update breaking changes18 - **swap** — Replace one library/tool with another that serves the same purpose19 - **adopt** — Move from an old pattern/API to a new one across the codebase20 - **modernize** — Update legacy code to use current language features or idioms21222. **Research the migration:**2324 Use the **Agent tool** to launch 2 research agents in parallel:2526 **Agent 1: Current usage scan** (subagent_type: Explore, thoroughness: very thorough)27 ```28 Find every usage of [the library/pattern/API being migrated away from] in this codebase.2930 Search for:31 - Import/require statements32 - Direct API calls and method usage33 - Type references and interface implementations34 - Configuration entries (build config, lint config, etc.)35 - Usage in tests and test fixtures36 - References in documentation, comments, and scripts37 - Transitive usage through wrapper modules3839 For each usage, report: file:line, the specific API/pattern used, and surrounding context.40 Group by file, sort by frequency of usage.41 Report total count of usages and number of files affected.42 ```4344 **Agent 2: Migration guide research** (subagent_type: general-purpose)45 ```46 Research the migration from [source] to [target].4748 Find:49 - Official migration guide or changelog (search the web)50 - Breaking changes between versions (if an upgrade)51 - API mapping: old API → new API equivalents52 - Known gotchas, edge cases, or compatibility issues53 - Codemods or automated migration tools available54 - Required peer dependency changes5556 Summarize as a concise mapping table: old pattern → new pattern.57 Flag any changes that require manual judgment (not a 1:1 swap).58 ```5960### Step 2: Create the migration plan6162Present the plan to the user:6364```markdown65## Migration Plan6667**Type:** [upgrade | swap | adopt | modernize]68**From:** [current library/version/pattern]69**To:** [target library/version/pattern]7071### Scope72- **Files affected:** N73- **Total usages:** N74- **Automated:** N (1:1 mappings that can be mechanically replaced)75- **Manual review:** N (changes requiring judgment)7677### API Mapping78| Old | New | Notes |79|-----|-----|-------|80| ... | ... | ... |8182### Migration steps831. [Ordered list of steps]8485### Risks86- [Breaking changes, behavioral differences, or edge cases]87```8889Wait for user confirmation before proceeding.9091### Step 3: Execute the migration9293Apply changes in a safe order:94951. **Update dependencies first** — bump versions in package manifests, update lockfile962. **Apply mechanical replacements** — 1:1 API swaps that don't require judgment, working file by file973. **Handle complex migrations** — changes that require understanding context or choosing between alternatives984. **Update types** — adjust type imports, interfaces, and generics to match the new API995. **Update configuration** — build config, lint rules, babel/bundler plugins1006. **Update tests** — adapt test code, update mocks/stubs, fix broken assertions1017. **Clean up** — remove old library imports, delete compatibility shims, remove unused polyfills102103#### Guidelines104105- **Work file by file** — complete all changes in one file before moving to the next106- **Preserve behavior** — the migration should not change what the code does, only how it does it107- **Don't mix refactoring with migration** — resist the urge to "improve" code while migrating; that makes it harder to verify the migration is correct108- **Flag ambiguous cases** — when the old and new APIs aren't equivalent, flag it for the user rather than guessing109- **Keep the old dependency until done** — don't remove the old library from the manifest until all usages are migrated110111### Step 4: Verify112113After applying changes:1141151. Search for any remaining references to the old library/API/pattern1162. Check that no old imports or require statements remain1173. If a codemod was available, compare its output against manual changes for consistency1184. List all files modified for the user to review1195. Suggest running tests and the build to verify nothing is broken1206. If any usages couldn't be migrated automatically, list them with explanations