/lattice:refactor-safelyfrom lattice
Restructures existing code safely without changing externally observable behavior. Composes context, design, architecture, code quality, and testing guardrails into a characterization-first refactoring workflow.
Ships in lattice. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Load these skills based on refactor scope (see Steps 3, 5, 6 for conditional use):
framework:knowledge-priming -- Load project context so the refactor grounds in the real codebase. (always)framework:context-anchoring -- Find and load the feature's context doc; capture approved plans and decisions in it. (always)framework:learning-harvest -- Load prior operational learnings at session start; harvest new ones at session end. (always)framework:collaborative-judgment -- Surface trade-offs in structure, seams, and migration sequence instead of silently assuming. (always)framework:clean-code -- Readability, responsibility boundaries, local craft. (always)framework:test-quality -- Characterization tests and the safety net. (always)framework:design-first -- Target-structure planning for significant structural changes. (conditional: Step 3)framework:architecture -- Layer placement and dependency direction. (conditional: responsibilities move across layers in Steps 5/6)framework:domain-driven-design -- Aggregate boundaries and domain behavior. (conditional: domain rules move or sharpen in Step 6)framework:secure-coding -- Trust bounds, authorization, sensitive data handling. (conditional: security-sensitive code touched in Step 6)STOP: Before Step 1, read additional_instructions.refactor_safely (one line or a list) from .lattice/config.yaml. No file or no key → skip silently.
When lines are found:
Start from the current pain, not from a preferred abstraction.
framework:learning-harvest Load behavior. Focus hint: "refactoring session — focus: structural health, quality signals".framework:context-anchoring Document Discovery to check for an existing context doc covering the affected feature/module:
End the step by summarizing the intent in one sentence:
"Refactor X to improve Y while preserving Z."
STOP: If you cannot state both the improvement target and the preservation target that clearly, continue clarifying with the user before planning any changes.
Persistence check:
framework:context-anchoring, then use it as the source of truth for the approved plan.Refactoring changes structure, not behavior. Make the preservation contract explicit before proposing any structural edits.
List the behaviors that must remain unchanged:
Also list explicit out-of-scope changes:
If the desired outcome requires changing preserved behavior, stop and discuss what the task actually is — a bug fix (/bug-fix), a feature change (/design-blueprint), or a broader redesign. STOP: Never proceed as a refactor after making one of those determinations.
Zero Refactor Rule: make no structural code changes until the user approves both the target structure and the transition plan.
For small refactors the plan may be brief. For larger ones, use framework:design-first selectively:
Present:
End the step with an explicit gate:
"Does this refactor plan look correct? Should I proceed to Step 4: characterization tests?"
STOP: Do not write any refactoring code until the user explicitly approves this plan.
If persistence is enabled, use framework:context-anchoring Enrich to capture the approved preservation boundaries, target structure, movement plan, and out-of-scope items. STOP: When persistence is enabled, do not proceed to Step 4 until the approved plan is written.
Before changing any structure, lock in current behavior with tests.
framework:test-quality inline while writing them.Stopping rule:
End the step with an explicit gate:
"Characterization tests in place and passing. Ready to discuss refactor strategy and pacing?"
STOP: Do not proceed to strategy selection until the safety net is verified green — or the user has explicitly accepted an unverified safety net per the stopping rule above.
With the high-level plan approved and the safety net green, choose the implementation approach.
Preferred strategies:
framework:architecture.Ask the user to choose a pacing mode:
"How would you like to review the refactor?"
- Slice-by-slice (recommended) -- refactor one safe slice at a time, pausing after each slice. Best for risky legacy code.
- Layer-by-layer -- complete the refactor for one structural layer or concern, then pause for review. Best for broader architectural cleanup.
- Full autonomy -- execute the approved refactor end-to-end and present the complete result at the end. Best for tightly scoped, low-risk refactors. (Still pause immediately if any slice reveals the approved plan unsafe or invalid — see the Deviation Rule in Step 6.)
Default to slice-by-slice when the user expresses no preference.
Implement only within the approved preservation boundaries and the approved target structure.
For each slice:
framework:collaborative-judgment and surface them before presenting the slice's code. Do not interrupt mid-slice unless the approved plan becomes unsafe or invalid.Always apply:
framework:clean-code -- better boundaries, simpler control flow, smaller focused units, clearer naming.framework:test-quality -- maintain strong characterization tests and nearby supporting tests.Conditionally apply:
framework:architecture.framework:domain-driven-design.framework:secure-coding.Deviation rule: if the implementation reveals the approved plan incomplete, unsafe, or requiring changes to preserved behavior → STOP: pause immediately and discuss before continuing.
The refactor succeeds only if both are true:
Verify preservation:
Verify structural improvement:
When reporting completion, be explicit about both sides:
Use framework:context-anchoring Enrich to preserve the important parts of the refactor:
No context doc exists and the refactor involved non-trivial structural reasoning → suggest creating one so the decisions are not lost across sessions.
Harvest learnings: run framework:learning-harvest Harvest behavior. Session context: "refactoring session — structural restructuring and debt resolution". Synthesize and propose cross-cutting patterns from this session — structural debt that accumulated, migration strategies that worked, characterization test gaps discovered. The user confirms what enters the document. STOP: run this before recommending /review below.
After the refactor is complete, recommend /review when the change:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub techygarg/lattice --plugin lattice27 skills in this plugin
/architectureEnforce architectural rules when generating or modifying code, and validate proposed designs before approval (design mode). Defaults to clean architecture; supports any architecture style via the architecture-refiner. Validates layer responsibilities, dependency direction, and structural constraints using the loaded architecture rules. Use when generating code, reviewing architecture, creating new files, or when the user mentions 'architecture', 'layers', 'structure', 'dependency rules', 'hexagonal architecture', 'ports and adapters', 'modular monolith', or 'onion architecture'. Also use when reviewing generated code for structural compliance./architecture-compassArchitectural thinking partner for an existing repository — scans the codebase, conducts a structured interview, agrees on current architectural state and recommended direction, and produces a shareable insights document. Scoped to one repository, module, or folder. Does not execute transformation — it orients. Use when the user says 'assess my codebase architecture', 'what direction should my codebase go', 'architecture compass', 'understand my architecture', 'audit architecture drift', 'architectural assessment', or 'help me understand what is wrong with my codebase'./architecture-refinerFacilitate a structured conversation to define architecture principles for a repository. Supports multiple architecture styles: clean architecture (default), hexagonal / ports & adapters, modular monolith, or custom. Produces a formal architecture document that the corresponding atom will use. Use when setting up a new project, defining architecture standards, or when the user says 'setup architecture', 'define layers', 'architecture principles', 'help me define my architecture', 'hexagonal architecture', 'modular monolith', 'ports and adapters', or 'define my architecture style'./bug-fixInvestigate, reproduce, and safely fix a bug with regression protection. Composes context, diagnosis, architecture, code quality, and testing guardrails into a reproduce-first repair workflow. Use when the user says 'fix this bug', 'debug this', 'investigate this failure', 'patch this regression', 'repair this issue', or 'why is this broken'./clean-codeApply clean code principles when generating or modifying implementation code. Enforces function focus, naming clarity, complexity management, error handling, and self-documenting style. Use when the user mentions 'clean code', 'code quality', 'coding guidelines', or 'implementation quality'. Loaded automatically by the code-generating molecules (code-forge, refactor-safely, bug-fix). This skill governs the craft of writing individual code units -- not architecture (see architecture), not security posture (see secure-coding), not test structure (see test-quality), and not refactoring workflows (see refactor-safely)./clean-code-refinerFacilitate a structured conversation to define clean code principles for a repository. Produces a formal clean-code.md document that the clean-code atom will use as its override. Use when setting up coding standards, defining code quality rules, or when the user says 'setup clean code', 'define coding standards', 'code quality principles', 'coding guidelines', or 'help me define my code standards'.Other plugins' skills for the same job