AI Coding Technique: Change One File, Migrate the Entire Codebase
AI Coding Technique: Change One File, Migrate the Entire Codebase
Here is a technique that saves hours on large codebases: make the change you want in one file manually, then tell Claude to migrate the rest of the codebase to match. It works shockingly well.
The Pattern
We had a SwiftUI codebase with 1,500+ hardcoded font calls scattered across hundreds of files. The old system used raw font names and sizes everywhere. The new system used a centralized font configuration.
Instead of writing a migration script or doing it by hand, we changed one file to use the new font system. Then we told Claude Code: "This file shows the new pattern. Migrate every other file to match."
That is it. 1,500+ font calls migrated in one session.
Why This Works Better Than a Script
A regex-based find-and-replace breaks on edge cases. A migration script requires you to enumerate every variation of the old pattern. Claude Code just looks at the example, understands the intent, and handles the variations.
It catches things a script would miss - like places where the font was constructed dynamically, or where the old pattern was used with slightly different parameters. The model understands what you mean, not just what you typed.
How to Apply This Technique
- Pick one representative file and make the change manually
- Make sure the change is clean and demonstrates the full pattern
- Tell Claude Code to migrate the rest of the codebase to match
- Review the diff - Claude will occasionally get creative in ways you did not intend
- Run your tests to catch any regressions
This technique works for any codebase-wide change: API patterns, error handling, logging conventions, naming schemes. The key is giving Claude a clear before-and-after example in a single file.
When It Does Not Work
This technique struggles when the old pattern has too many unrelated variations, or when the migration requires understanding business logic that is not visible in the code. For those cases, you still need to write more detailed specs.
- AI Coding Skill Is Decomposing Problems, Not Prompting
- Multi-Codebase Claude Code Workflow
- Writing Code to Reviewing Code - The AI Shift
Fazm is an open source macOS AI agent. Open source on GitHub.