| diataxis_type | how-to |
|---|---|
| diataxis_goal | Choose effective refactoring scopes for different project sizes and situations |
This guide shows you how to choose the right refactoring scope to get the best results without wasting time on overly broad runs.
- Refactor plugin installed and working (see Tutorial)
- Familiarity with your project's directory structure
For your first refactor on a project, pick a single module or directory:
/refactor src/utils/This lets you evaluate the agents' output quality and understand the iteration cycle before committing to a full-codebase run.
If you know exactly which files need attention:
/refactor src/auth/handler.tsSingle-file refactors complete faster and produce focused improvements.
If the code you want to refactor spans multiple directories, describe it:
/refactor "error handling logic"The architect agent will identify relevant files across the codebase.
For small scopes (1--3 files), fewer iterations are sufficient:
/refactor --iterations=2 src/config.tsFor large scopes (entire modules), use the default 3 or increase to 5:
/refactor --iterations=5 src/If you only need a specific type of analysis, use --focus to skip unnecessary agents:
/refactor --focus=security src/auth/
/refactor --focus=architecture src/api/
/refactor --focus=simplification src/utils/Focus mode pairs well with scope narrowing — a focused, narrow run completes much faster than a full-scope, full-discipline run.
For detailed guidance on all focus options, see How to Run Focused Refactoring.
For a monorepo or large project, run multiple focused refactors rather than one broad pass:
/refactor src/auth/
/refactor src/api/
/refactor src/models/Review and commit after each run. This gives you finer control over changes and keeps each run's scope manageable.
- No test framework — The test agent can write tests, but it needs a test runner. Set up a testing framework first.
- Prototype or experimental code — Refactoring code that may be thrown away wastes effort.
- During incidents — Focus on the fix, refactor later.
- Code scheduled for deletion — Not worth improving.
- Configuration Reference —
iterationsfield - How to Configure Commit Strategies — automate commits between runs
- Troubleshooting — when refactors take too long