// 54 tips tagged "refactoring"
Every language evolves — callbacks become async/await, class components become hooks, jQuery becomes vanilla JS, and var becomes const. Tell Claude to read your legacy code and upgrade it to modern patterns, one module at a time, while keeping the behavior identical and the tests passing.
When you need to make the same change to 20 files — add a trait to every model, wrap all API responses in a consistent format, add logging to every controller, or update an import path everywhere — describe the change once and tell Claude to apply it across every matching file. One prompt, twenty edits, zero copy-paste.
Before refactoring code that looks wrong or unnecessary, tell Claude to check git blame and the commit history to understand why it was written that way. What looks like a bug might be a deliberate workaround — and Claude can find the original commit message that explains the reasoning before you accidentally undo it.
Major version upgrades are scary — deprecated methods, renamed classes, changed signatures, removed features. Tell Claude which dependency to upgrade and it reads the upgrade guide, bumps the version, then systematically finds and fixes every breaking change across your entire codebase.
Internationalizing an existing app means finding every hardcoded string in every template, moving it to a translation file, and replacing it with a translation function call. Tell Claude to do it — it scans your views, extracts every user-facing string, and wires up the translation keys automatically.
Point Claude at untyped code and tell it to add types — TypeScript annotations to JavaScript, type hints to Python, PHPDoc blocks to PHP, or generics to Java. Claude reads the actual usage, infers the correct types from context, and adds them without changing any behavior.
For complex tasks — big refactors, architectural changes, multi-file features — switch to plan mode so Claude researches and proposes a step-by-step approach before touching any code. Review the plan, adjust it, then let Claude execute with confidence.
Every codebase has inconsistencies — some controllers return responses one way, others differently; some services throw exceptions, others return null. Tell Claude to pick the best pattern and apply it everywhere so the codebase reads like it was written by one developer.
Tell Claude which design pattern to use — Repository, Strategy, Observer, Decorator — and it applies it to your actual codebase, not a textbook example. It reads your existing code, identifies where the pattern fits, and refactors to implement it properly.
Tell Claude to trace every import and dependency across your codebase, then show you which modules depend on which — spotting circular dependencies, God modules everything imports, and tightly coupled layers that should be independent.
Tell Claude to scan your codebase for dead code — unused functions, orphaned files, unreachable branches, imports with no references, and config for features that were removed — then safely delete what's confirmed dead so your project stays lean.
When a file has grown too large — a 1,000-line controller, a God object, or a component that does everything — tell Claude to break it apart into smaller, focused modules, moving each responsibility into its own file while keeping everything wired together and working.