Refactoring With Anvien
Use this skill for behavior-preserving renames, extractions, moves, splits, and shared-code cleanup.
This skill is a workflow gate for refactoring work. It is not a command router. When a concrete Anvien command is needed, choose it directly from the generated Command Selection Guide.
Command Choices
| Need |
Use |
| Understand current ownership |
MCP/CLI context; prefer context file or context symbol once target type is known |
| Check callers and flows before editing |
MCP/CLI impact --direction upstream; prefer impact file or impact symbol once target type is known |
| Rename a symbol |
MCP rename or CLI anvien rename <symbol> <newName> --repo <repo> |
| Check API route/contract consumers |
MCP api_impact or CLI anvien api impact [route] --repo <repo> |
| Check route/tool blast radius |
anvien impact route <route> --repo <repo> or anvien impact tool <tool> --repo <repo> |
| Verify changed scope before commit |
MCP detect_changes or CLI anvien detect-changes --repo <repo> --scope all |
Workflow
- Refresh the graph with
anvien analyze --force before graph-based refactoring.
- Use
context to inspect the exact target. If multiple candidates exist, use UID/file disambiguation.
- Run upstream impact and report the blast radius. HIGH/CRITICAL means proceed carefully, not stop automatically.
- For renames, start with a graph-guided dry run. Do not use find-and-replace for symbols.
- Make behavior-preserving changes first. Defer unrelated cleanup unless required.
- Run focused tests, broader tests when shared contracts are touched, and
detect-changes.
Rename Flow
anvien rename oldName newName --repo <repo> --json
- Inspect files, edit counts, graph edits, text-search edits, and ambiguity warnings.
- Use
--uid or --file if the dry run is ambiguous.
- Apply with
--apply only when the edit list matches the intended scope.
Extract, Split, Or Move Flow
- Use
context to identify callers/callees and nearby contracts.
- Use
impact to identify consumers that must remain compatible.
- Move code in a small slice, update imports deliberately, and preserve behavior.
- Re-run tests that cover affected flows and any API shape tests if contracts moved.
Current Limitations
Graph-guided rename is safer than text replacement, but generated files, dynamic references, string-based APIs, and external integrations still need source review and tests.
1---2name: refactoring3description: Use when the user asks to refactor code.4---56# Refactoring With Anvien78Use this skill for behavior-preserving renames, extractions, moves, splits, and shared-code cleanup.910This skill is a workflow gate for refactoring work. It is not a command router. When a concrete Anvien command is needed, choose it directly from the generated Command Selection Guide.1112## Command Choices1314| Need | Use |15|---|---|16| Understand current ownership | MCP/CLI `context`; prefer `context file` or `context symbol` once target type is known |17| Check callers and flows before editing | MCP/CLI `impact --direction upstream`; prefer `impact file` or `impact symbol` once target type is known |18| Rename a symbol | MCP `rename` or CLI `anvien rename <symbol> <newName> --repo <repo>` |19| Check API route/contract consumers | MCP `api_impact` or CLI `anvien api impact [route] --repo <repo>` |20| Check route/tool blast radius | `anvien impact route <route> --repo <repo>` or `anvien impact tool <tool> --repo <repo>` |21| Verify changed scope before commit | MCP `detect_changes` or CLI `anvien detect-changes --repo <repo> --scope all` |2223## Workflow24251. Refresh the graph with `anvien analyze --force` before graph-based refactoring.262. Use `context` to inspect the exact target. If multiple candidates exist, use UID/file disambiguation.273. Run upstream impact and report the blast radius. HIGH/CRITICAL means proceed carefully, not stop automatically.284. For renames, start with a graph-guided dry run. Do not use find-and-replace for symbols.295. Make behavior-preserving changes first. Defer unrelated cleanup unless required.306. Run focused tests, broader tests when shared contracts are touched, and `detect-changes`.3132## Rename Flow33341. `anvien rename oldName newName --repo <repo> --json`352. Inspect files, edit counts, graph edits, text-search edits, and ambiguity warnings.363. Use `--uid` or `--file` if the dry run is ambiguous.374. Apply with `--apply` only when the edit list matches the intended scope.3839## Extract, Split, Or Move Flow4041- Use `context` to identify callers/callees and nearby contracts.42- Use `impact` to identify consumers that must remain compatible.43- Move code in a small slice, update imports deliberately, and preserve behavior.44- Re-run tests that cover affected flows and any API shape tests if contracts moved.4546## Current Limitations4748Graph-guided rename is safer than text replacement, but generated files, dynamic references, string-based APIs, and external integrations still need source review and tests.