From refactor-pilot
Use this skill whenever the user wants to understand, analyze, or audit a codebase before refactoring. Triggers include: "analyze this project", "what does this codebase do", "give me an overview of the code", "audit dependencies", "map the file structure", "what are the code smells", "assess code quality", "review this project", "what needs refactoring", or any request to understand a codebase before changing it. Also triggers when a user shares a project folder and wants to know where to start. Do NOT use for actually writing refactored code — use refactor-code for that.
How this skill is triggered — by the user, by Claude, or both
Slash command
/refactor-pilot:analyze-codebaseThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are performing Phase 1 (Gather Insights) of the Refactor Pilot Framework. Your job is
You are performing Phase 1 (Gather Insights) of the Refactor Pilot Framework. Your job is to build a comprehensive understanding of the codebase before any changes are made.
Is this a new project you haven't analyzed?
├── YES → Start at Step 1
└── NO → Has the code changed since last analysis?
├── YES → Re-run steps 3-4 on changed files
└── NO → Skip to Phase 2 (generate-tests)
Is the codebase sensitive or proprietary?
├── YES → Use local models for code analysis, see references/anonymization.md
└── NO → Proceed normally
Is the codebase large (>500 files)?
├── YES → Scope to one module/feature area first
└── NO → Analyze the whole project
Execute these steps in order. Save all outputs to a refactor-notes/ directory in the
project root.
Read the project's manifest file (package.json, requirements.txt, Cargo.toml,
go.mod, pyproject.toml, or equivalent) and produce a report covering:
Save as refactor-notes/01-metadata.md.
Generate a categorized file manifest by running a directory listing (excluding
node_modules, .git, dist, build, __pycache__, .venv, and similar).
Categorize every file into: Components/Views/Pages, Utilities/Helpers, Services/API clients, State management, Types/Interfaces, Styles, Tests, Configuration, Data/Constants.
Flag orphaned files, naming inconsistencies, and structural concerns.
Save as refactor-notes/02-file-structure.md.
If a module directory contains a CONTEXT.md, read it first and validate it against the
code — flag stale or wrong entries. Note modules that lack one; creating them is a
Phase 3 deliverable (template in skills/refactor-code/references/deep-modules.md).
For each file in the target area (or the most important 10-20 files if the project is large), produce a summary. Use file-type-specific analysis:
See references/file-type-prompts.md for detailed analysis templates per file type.
Process files in batches. Save as refactor-notes/03-file-summaries.md.
Run a coverage report and assess refactoring risk by coverage level:
Save as refactor-notes/03b-coverage-analysis.md.
Run ./scripts/capture-baselines.sh against the project to capture quantitative
measurements (codebase size, build output, dependencies, code quality indicators).
Save as refactor-notes/baselines.md.
Review build config files (tsconfig.json, webpack.config.js, vite.config.ts,
Cargo.toml, pyproject.toml, or equivalent) for flags that affect refactoring:
strict mode (enabling strictness can be a refactoring goal)Use references/file-type-prompts.md (config section) for detailed analysis.
Note findings in refactor-notes/03-file-summaries.md alongside the config file analysis.
Scan the codebase for security concerns that should be addressed during refactoring:
Classify each issue as CRITICAL, HIGH, MEDIUM, or LOW. Include file, line, and suggested fix. Feed this into the refactor plan in Phase 2.
Save as refactor-notes/05-security-analysis.md.
Scan the analyzed code for structural issues that design patterns can solve. Use the smell → pattern mapping to identify candidates:
| Code Smell Found | Candidate Pattern(s) |
|---|---|
Giant if/else or switch on type | Strategy, State, Command |
| Copy-pasted logic with minor variations | Template Method, Strategy |
| Constructor with 5+ parameters | Builder |
new keyword scattered everywhere | Factory Method, Abstract Factory |
| God class doing too many things | Facade, Mediator, Command |
| Tight coupling between modules | Observer, Mediator, Bridge |
| Adding features requires modifying existing code | Decorator, Strategy, Visitor |
| Complex object creation logic | Builder, Factory Method, Prototype |
| Need to support undo/history | Memento, Command |
| Traversing complex structures | Iterator, Composite, Visitor |
| Different behavior for different states | State |
| Adapting incompatible interfaces | Adapter, Facade |
| Controlling access to expensive resources | Proxy, Flyweight |
Also scan for the inverse problem — over-abstraction (shallow modules). These cost AI agents tokens and navigation hops on every task, and collapsing them often pays more than adding patterns:
| Over-Abstraction Smell | Suggested Fix |
|---|---|
| Pass-through methods/classes that only relay calls | Inline the layer |
| Interface with a single implementation and no test seam | Remove the interface |
| Single-use helpers extracted from one call site | Inline back into the caller |
| Layer-per-technical-concern, each a few lines thick | Merge into one deep module per domain capability |
| Deep import chains (A→B→C→D to reach one behavior) | Flatten into a deeper module |
For each identified opportunity (pattern or collapse), note:
Apply the Depth Test from skills/refactor-code/references/deep-modules.md before
recommending any pattern: it must make modules deeper, not just add structure.
Save pattern opportunities to refactor-notes/03c-pattern-opportunities.md.
For detailed pattern descriptions and application guides, see the design-patterns skill
and its reference docs (skills/design-patterns/references/).
Produce a text-based architecture diagram from the analysis outputs showing how major modules connect. Use arrows for data flow and dependency direction. Group files by feature area or layer.
Include the diagram in the project summary.
Synthesize all outputs into a single document covering:
Save as refactor-notes/04-project-summary.md.
After completing all steps, present the user with:
references/anonymization.md for local model strategies.Provides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
npx claudepluginhub guilhermevozniak/refactor-pilot-framework --plugin refactor-pilot