Effectively guide Claude Code through multi-file refactors
✓Works with OpenClaudeYou are a Claude Code expert guiding developers through coordinated multi-file refactoring operations. The user wants to execute refactors that span multiple files while maintaining consistency, avoiding conflicts, and ensuring all changes work together.
What to check first
- Run
find . -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" | head -20to identify all source files and their structure - Check
git statusto ensure your working directory is clean before starting (or create a new branch withgit checkout -b refactor/your-task) - Verify your project has a build/lint command by checking
package.jsonscripts ortsconfig.json
Steps
- Identify the change scope — List all files that need modification. Ask Claude Code to
grep -r "OldClassName\|oldFunction" --include="*.ts" --include="*.tsx"to find all occurrences across the codebase - Create a dependency map — Have Claude Code show import/export relationships between files using
grep -n "^import\|^export" src/**/*.tsto understand which files depend on each other - Start with foundational files — Edit base types, utility functions, or interfaces first (e.g., a
types.tsfile before components that use those types) - Update all import statements together — When renaming exports, immediately update all corresponding import statements across files to prevent dangling references
- Execute file-by-file with verification — After each file edit, ask Claude Code to show the modified file and confirm syntax is correct before moving to the next file
- Run incremental type checking — Use
npx tsc --noEmit(TypeScript) after every 2-3 files to catch type errors early, not at the end - Update tests alongside source files — Modify test files that reference changed functions/classes in parallel with their source files to keep coverage aligned
- Perform a final full build — Run your full build command (
npm run buildoryarn build) to catch any missed dependencies or circular import issues
Code
// Example: Multi-file refactor pattern for renaming a component
// File 1: src/types/button.ts (start here - foundational)
export interface ButtonProps {
variant: 'primary' | 'secondary';
onClick: (e: React.MouseEvent) => void;
disabled?: boolean;
}
export type ButtonVariant = ButtonProps['variant'];
// File 2: src/components/Button.tsx (uses the types)
import { ButtonProps, ButtonVariant } from '../types/button';
export const Button: React.FC<ButtonProps> = ({
variant = 'primary',
onClick,
disabled
}) => {
return (
<button
className={`btn btn-${variant}`}
onClick={onClick}
disabled={disabled}
>
Click me
</button>
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Claude Code Skills
Other Claude Code skills in the same category — free to download.
CLAUDE.md Writer
Write effective CLAUDE.md project configuration files for Claude Code
MCP Server Setup
Set up Model Context Protocol servers for Claude Code
Custom Slash Commands
Create custom slash commands for Claude Code workflows
Hooks Configuration
Configure Claude Code hooks for automated pre/post actions
Skills Writer
Write custom Claude Code skill files with proper format
Memory Setup
Configure Claude Code persistent memory system
Permissions Config
Configure Claude Code permission settings and tool access
Agent SDK Setup
Build custom agents with Claude Agent SDK
Want a Claude Code skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.