cj-ways/arcana/refactor-plan
Claude Code and agent skill by cj-ways/arcana
- community
Checking that the SKILL.md file is still in the repository.
Plans and executes safe multi-file refactoring — maps dependency graph, batches changes into atomic commits, runs tests between batches. Prevents the cascading-breakage pattern where agents make sweeping changes that fail halfway. Use for renames, extractions, moves, or structural changes across multiple files. Manual via /refactor-plan.
Install
npx vskill@latest install cj-ways/arcana/refactor-planSKILL.md
The same SKILL.md was published earlier as cj-ways/arcana/refactor-plan.
Refactor Plan — Safe Multi-File Refactoring
Breaks a refactoring request into a dependency-aware execution plan with atomic batches and test gates. Prevents the most dangerous AI agent failure mode: sweeping multi-file changes that leave the codebase in a broken intermediate state.
Input: $ARGUMENTS (what to refactor — rename, extract, move, restructure, etc.)
Gotchas
- Editing files before mapping the dependency graph. Renaming a function used in 30 files without first finding all 30 call sites guarantees broken imports. ALWAYS map before modifying.
- Making all changes in one commit. If a 15-file refactor breaks at file 8, the developer has to revert everything or debug a half-refactored codebase. Batch into atomic commits that each leave the codebase in a working state.
- Forgetting transitive dependents. File A imports from File B, File C imports from File A. If File B's export changes, File C breaks indirectly. Trace at least 2 levels deep.
- Not running tests between batches. Each batch must pass tests before proceeding to the next. A failing test in batch 2 is cheap to fix. A failing test discovered after batch 5 is expensive.
- Refactoring and improving simultaneously. The refactoring should change structure, not behavior. Do not fix bugs, add features, or "improve" code in the same batch. Behavior-preserving changes are verifiable. Mixed changes are not.
Step 1: Understand the Request
Parse $ARGUMENTS to determine:
- Refactoring type: classify as one of:
- Rename — symbol, file, or directory rename
- Extract — pull code into a new function, module, or package
- Move — relocate files or modules to a different directory
- Inline — collapse an abstraction back into its callers
- Restructure — change module boundaries, split/merge modules
- Signature change — modify function parameters, return types, or interfaces
- Scope: estimate number of files affected (read the codebase first — do not guess)
- Risk level:
- Low: <5 files, single module, no public API changes
- Medium: 5-20 files, cross-module, internal API changes
- High: 20+ files, public API changes, or database schema involved
If risk is High, present the scope assessment and ask for confirmation before proceeding.
Step 2: Map the Dependency Graph
Before touching any code, build a complete map of what depends on what.
2a. Identify the refactoring target
- Read the file(s) or symbol(s) being refactored
- Extract: exported names, types, interfaces, class methods
2b. Find all direct dependents
For each exported symbol being changed:
- Grep for import statements referencing the target file/module
- Grep for direct usage of the symbol name across the codebase
- Check barrel files (index.ts/index.js) that re-export the target
- Check import aliases defined in tsconfig.json paths, webpack aliases, package.json imports
2c. Find transitive dependents (one level)
For each direct dependent found in 2b:
- Check if IT re-exports the changed symbol
- If yes, find dependents of that re-export
2d. Check non-code references
- Config files that reference the target (webpack config, jest config, CI files)
- Documentation that references the target (README, CLAUDE.md, JSDoc)
- Test files that import or reference the target
- Scripts and Makefiles
2e. Produce the dependency map
Step 3: Design the Batch Plan
Split the refactoring into ordered batches. Each batch must leave the codebase in a compilable, test-passing state.
Batch design principles:
- Infrastructure first — new files, directories, or config changes that don't break anything
- Dual-write / backward-compatible changes — add the new path while keeping the old one working (re-exports, aliases, deprecation wrappers)
- Migrate dependents — update consumers to use the new path/name, one logical group at a time
- Remove the old — delete deprecated re-exports, old files, old aliases
- Clean up — remove backward-compatibility shims, update docs
Batch plan format:
Present the batch plan to the user. Wait for confirmation before executing.
Step 4: Execute Batches
For each batch:
- Apply the changes listed in the batch
- Run the test gate — the specified test command
- If tests pass: commit with message
refactor: [batch title]and proceed to next batch - If tests fail:
- Read the failure output
- Identify what broke — is it a missed dependent? A transitive import? A type mismatch?
- Fix within this batch (do not proceed to next batch with failures)
- Re-run tests
- If the fix requires changing the plan for later batches, update the plan and inform the user
Commit message format per batch:
Step 5: Verify
After all batches complete:
- Run the full test suite — not just the targeted test gate, the full suite
- Run the build — if a build command exists (TypeScript compilation, Go build, etc.)
- Run the linter — if configured (ESLint, golangci-lint, etc.)
- Diff review — run
git diff [start-commit]..HEAD --statto verify total scope matches the plan
If any step fails, identify which batch introduced the issue and fix it.
Step 6: Report
If the refactoring revealed code quality issues, mention: "Consider running /quick-review to verify the refactored code for correctness."
If the refactoring was large and touched critical paths, mention: "Consider running /deep-review for a full security and architecture check on the changed files."
Rules
- NEVER modify code without completing the dependency map (Step 2)
- NEVER proceed to the next batch with failing tests
- NEVER mix behavior changes with structural changes in the same batch
- ALWAYS present the batch plan for user confirmation before executing
- ALWAYS commit after each successful batch — atomic commits enable easy revert
- If the scope exceeds 50 files, strongly recommend splitting into multiple refactoring sessions
- Match existing code style — a refactoring that changes indentation or formatting alongside structural changes is harder to review
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/refactor-plan/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cj-ways/arcana/refactor-plan)