safe-refactor-code
Safe Refactor Code
Refactor code in small verified slices, then update the repo's continuity files so future agents can resume without rereading the whole session.
Core Rules
- Treat
AGENTS.mdat repo root as the main long-term repo memory. Preserve existing content and update it carefully instead of rewriting blindly. - Keep agent-local
MEMORY.mdshort. It is a working summary for the repo, not a replacement for any shared or tool-managed memory system. - Keep
safe-refactor-code.mdfocused on the repo's refactor rules, guardrails, and recurring cleanup workflow. - Update
CHANGELOG.mdon real code changes using today's section:## [YYYY-MM-DD]. - Prefer additive or scoped edits to docs. Do not wipe user-written history unless the user explicitly asks.
- After refactors, scan for obvious dead code, unused imports, stale helpers, and outdated doc references before finishing.
- Use code-review graph tools when available. Fall back to direct source search and verification when graph tools are unavailable or empty.
Graph-Aware Refactor Rules
- Start graph-assisted refactors with
get_minimal_context_tool(task="<refactor goal>"). - Update stale graphs with
build_or_update_graph_tool()before broad refactors. - For symbol renames, use
refactor_tool(mode="rename", old_name=<old>, new_name=<new>)and inspect the preview before applying.
More from afu-it/safe-code
safe-code
Full repo hygiene in one pass. Uses /safe-code for first-time setup, /safe-code --continue for context-safe resume, and /safe-code --save for handoff + local commit. Detects the active agent, initializes all continuity docs inside the current project only, audits and removes dead code in safe slices, refactors in place, and keeps docs in sync. /safe-code --save creates or uses a local git repo and commits locally only — it never pushes to a remote. Universal git remote detection is informational only. Use when asked to do a full cleanup, full hygiene pass, /safe-code, or maintain a repo in one go.
9codebase-pruner
Scan an entire codebase to detect and safely remove dead code such as unused functions, orphaned modules, unreferenced exports, stale configs, dead routes, and leftover workflow artifacts. Use when asked to clean up dead code, remove unused code, prune stale files, find orphaned modules, audit codebase bloat, or delete code left behind after a workflow or architecture change.
7build-graph
Build or update the code review knowledge graph. Use before safe-code audits, refactors, reviews, debugging, or when the graph may be stale.
1review-changes
Review working-tree, branch, or PR changes using graph change detection, blast-radius analysis, affected flows, and test coverage checks.
1explore-codebase
Navigate and understand codebase structure using the code-review graph. Use for repo orientation, AGENTS.md authoring, architecture mapping, or finding relevant code.
1debug-issue
Systematically debug issues using graph-powered code navigation, recent-change detection, affected flows, and targeted verification.
1