Refactor Safely

tirth8205/code-review-graph/skills/refactor-safely

by tirth82056b12d11625cbec3b6773e076cb3d136464fa90e5No licenseListed Oct 9, 2026Updated Oct 9, 2026

Plan and execute safe refactoring using dependency analysis

Instructions onlySoftware Development
AI-generated overview

Plans and executes safe code refactoring using dependency-graph analysis and previewed renames.

What it does
Guides an agent through a refactoring workflow: it suggests refactoring candidates or dead code, previews renames and applies them by refactor id, and inspects impact radius and affected flows before large changes. It also helps find large functions worth splitting and verifies afterward that the detected changes match the plan. The skill includes token-efficiency rules for graph tool calls and reminds the agent to read the implementation and tests before changing code.
When to use it
Use when refactoring existing code, such as renaming symbols, removing unreferenced code, or splitting large functions, and when you want to assess the blast radius of a change before applying it. It fits codebases where a dependency graph is available to narrow scope.
Requirements
Requires the refactoring and graph tools referenced in the instructions (refactor_tool, apply_refactor_tool, get_impact_radius_tool, get_affected_flows_tool, find_large_functions_tool, detect_changes_tool, get_minimal_context_tool, query_graph_tool). No scripts are shipped; instructions only.

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.

Source and attribution

Source:tirth8205/code-review-graphinskills/refactor-safelyat commit6b12d11

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal