refactor-safely — Claude Code skill: what it does, how to install
Plans a refactor from a dependency graph, lists edits before a rename and checks the impact radius before large changes.
npx skills add tirth8205/code-review-graph --skill refactor-safely -a claude-codeWhat refactor-safely does
The skill drives a set of dependency-graph tools. refactor_tool with mode="suggest" surfaces refactoring candidates, mode="dead_code" finds unreferenced code, and mode="rename" prepares a rename with an edit list that gets reviewed before apply_refactor_tool applies it. Before a large refactor it calls get_impact_radius_tool and get_affected_flows_tool to show dependents and critical paths, and find_large_functions_tool points to functions worth splitting. After the change, detect_changes_tool checks that the actual impact matches the plan.
A token-efficiency section sets the order: get_minimal_context_tool runs before any other graph tool, detail_level="minimal" is used wherever a tool accepts it, and a targeted query_graph_tool call beats a broad listing. The budget is about five tool calls and 800 tokens of graph output per task. The instructions are explicit that the graph only narrows scope, so reading the implementation and its tests before changing code stays on the checklist.
What it helps with
- find unreferenced code in a codebase
- plan a function or variable rename with an edit list reviewed before applying it
- check the impact radius before a large refactor
- find large functions worth splitting
- confirm a change matches the planned impact
Example prompts for the agent
- Find dead code in the auth module and suggest what to remove
- Show the impact radius before renaming getUserData
- Rename getUserData to fetchUserProfile and show the edit list before applying it
How to install refactor-safely
1Skills CLI (Vercel)
npx skills add tirth8205/code-review-graph --skill refactor-safely -a claude-code2Manually: put the files in place
~/.claude/skills/refactor-safely/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/refactor-safely/
1Skills CLI (Vercel)
npx skills add tirth8205/code-review-graph --skill refactor-safely -a codex2Manually: put the files in place
.agents/skills/refactor-safely/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add tirth8205/code-review-graph --skill refactor-safely -a cursor2Manually: put the files in place
.cursor/skills/refactor-safely/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install tirth8205/code-review-graph refactor-safely2Manually: put the files in place
.github/skills/refactor-safely/SKILL.md1Skills CLI (Vercel)
npx skills add tirth8205/code-review-graph --skill refactor-safely -a gemini-cli2Platform CLI
gemini skills install https://github.com/tirth8205/code-review-graph --path skills/refactor-safelyManually: put the files in place
.devin/skills/refactor-safely/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add tirth8205/code-review-graph --skill refactor-safely -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set7
The whole set →Similar
Questions about refactor-safely
How to install refactor-safely in Claude Code?
Run npx skills add tirth8205/code-review-graph --skill refactor-safely -a claude-code. The skill then lands in ~/.claude/skills/refactor-safely/SKILL.md.
What does refactor-safely do?
It plans a refactor from a dependency graph: finds candidates and dead code, prepares renames with a preview of edits, and shows affected modules before changes get applied.
Do you still need to read the code by hand with this skill?
Yes, the instructions require reading the implementation and its tests before changing code, since the graph narrows scope but does not replace the source.
Source text
SKILL.md · MIT
--- name: refactor-safely description: Plan and execute safe refactoring using dependency analysis --- ## Refactor Safely Plan a refactor from the dependency graph and apply renames from a preview. ### Steps 1. Call `refactor_tool` with `mode="suggest"` for refactoring candidates, or `mode="dead_code"` for unreferenced code. 2. For a rename, call `refactor_tool` with `mode="rename"`, `old_name` and `new_name`. Check the returned edit list before applying. 3. Call `apply_refactor_tool` with the returned `refactor_id` to apply the rename. 4. Before a large refactor, call `get_impact_radius_tool` and `get_affected_flows_tool` to see the dependents and critical paths involved. 5. Call `find_large_functions_tool` to find functions worth splitting. 6. After the change, call `detect_changes_tool` to confirm the impact matches the plan. ## Token Efficiency Rules - Call `get_minimal_context_tool(task="<your task>")` before any other graph tool. - Pass `detail_level="minimal"` wherever a tool accepts it. Use "standard" only when minimal is not enough. - Prefer a targeted `query_graph_tool` call over a broad listing call. - Budget: about five tool calls and 800 tokens of graph output per task. - Read the implementation and its tests before changing code. The graph narrows scope; it does not replace the source.
© tirth8205 · MIT · tirth8205/code-review-graph