refactor-safely

refactor-safely is a skill for Claude Code from techygarg/lattice. It costs 82 tokens per session (2,755 once invoked), scanned A, original, MIT.

A workflow for restructuring existing code while keeping its observable behavior unchanged. It starts by recording how the current code behaves and uses tests as a safety net.

In plain words
What is it for?
Use it when refactoring, cleaning up, or relocating code, with project context, design decisions, architecture guidance, code-quality checks, and characterization tests.
Why use it?
It reduces the risk of breaking users or dependent code while untangling modules, moving responsibilities, or improving structure.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the lattice plugin — 33 skills, 1 agent shipped together

Good fit Use it when refactoring, cleaning up, or relocating code, with project context, design decisions, architecture guidance, code-quality checks, and characterization tests.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/techygarg/lattice/refactor-safely
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add techygarg/lattice --skill refactor-safely
Clone the repo
git clone --depth 1 https://github.com/techygarg/lattice

Made for: Claude Code.

Or install lattice, the plugin that ships this one along with the rest of its 33 skills, 1 agent.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor-safely

README.md
[![agentmods](https://agentmods.dev/badge/skills/techygarg/lattice/refactor-safely/github.svg)](https://agentmods.dev/skills/techygarg/lattice/refactor-safely)
Your own site
<a href="https://agentmods.dev/skills/techygarg/lattice/refactor-safely"><img src="https://agentmods.dev/badge/skills/techygarg/lattice/refactor-safely/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-safely

Your own site · 80×15
<a href="https://agentmods.dev/skills/techygarg/lattice/refactor-safely"><img src="https://agentmods.dev/badge/skills/techygarg/lattice/refactor-safely.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 82 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,755 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00082 $0.02755
Opus 5.5 $0.00033 $0.01102
Sonnet 5.5 $0.00016 $0.00551
Haiku 4.5 $0.00008 $0.00276

Measured 12d ago against content hash 2c15e97df45b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor-safely scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/refactor-safely/SKILL.md · 230 lines

How it starts

The opening of the file, as written. The whole thing — 230 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactor Safely

Required Skills

Load these skills based on refactor scope (see Steps 3, 5, 6 for conditional use):

  1. framework:knowledge-priming -- Load project context so the refactor grounds in the real codebase. (always)
  2. framework:context-anchoring -- Find and load the feature's context doc; capture approved plans and decisions in it. (always)
  3. framework:learning-harvest -- Load prior operational learnings at session start; harvest new ones at session end. (always)
  4. framework:collaborative-judgment -- Surface trade-offs in structure, seams, and migration sequence instead of silently assuming. (always)
  5. framework:clean-code -- Readability, responsibility boundaries, local craft. (always)
  6. framework:test-quality -- Characterization tests and the safety net. (always)
  7. framework:design-first -- Target-structure planning for significant structural changes. (conditional: Step 3)
  8. framework:architecture -- Layer placement and dependency direction. (conditional: responsibilities move across layers in Steps 5/6)
  9. framework:domain-driven-design -- Aggregate boundaries and domain behavior. (conditional: domain rules move or sharpen in Step 6)
  10. framework:secure-coding -- Trust bounds, authorization, sensitive data handling. (conditional: security-sensitive code touched in Step 6)

Additional Instructions

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:

  1. Show them verbatim under "Additional instructions (from config):".
  2. Highest priority — apply them for the whole session, including on resume. On any conflict with anything else in this skill — steps, gates, STOP rules — or with its Required Skills, standards documents, or operational learnings, the config line wins.

Workflow

Step 1: Establish Refactor Context

Start from the current pain, not from a preferred abstraction.

  • Identify the target area: a module, service, aggregate, endpoint path, or subsystem.
  • Clarify why the refactor is needed: mixed responsibilities, duplication, wrong-layer logic, coupling, poor testability, or unreadable control flow.
  • Clarify what the user expects to improve: simpler structure, correct layer placement, smaller units, clearer domain behavior, easier testing, or safer extension points.
  • Run framework:learning-harvest Load behavior. Focus hint: "refactoring session — focus: structural health, quality signals".
  • Run framework:context-anchoring Document Discovery to check for an existing context doc covering the affected feature/module:
    • Found → Load behavior. Honor every logged decision and constraint as an active commitment while planning the refactor. The doc already contains an approved refactor plan (preservation boundaries + target structure) → confirm it still matches the user's intent, then resume at Step 4 unless the user wants to revisit the plan first.
    • Not found → Proceed from the conversation and the current code. Do not block planning on a missing context doc.

Read the full file on GitHub · 230 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago Changed · +9 lines 2c15e97df45b
  2. 1mo ago First seen · 221 lines · 82 tokens per session scan A 6206df716793

Subscribe to this mod's changes

refactor-safely is a skill published in the GitHub repository techygarg/lattice (207 stars, last pushed 13d ago), licensed MIT. It adds 82 tokens to every session and 2,755 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

verify

Verify Elixir/Phoenix changes — compile, format, and test in one loop. Use after implementation, before PRs, or after fixing bugs.

oliver-kriska/claude-elixir-phoenix · 33 tokens

build-scenario-tests

Inspect an unfamiliar repository, turn a focused Markdown behavior scenario into a deterministic test in the repository's native test stack, run it, and preserve traceability between intent and code. Use when asked to add scenario tests, compile acceptance criteria or Given/When/Then Markdown into executable tests…

tamdogood/builder-essential-skills · 104 tokens

run-smoke-tests

Inspect an unfamiliar repository, interpret a broad Markdown user journey at runtime, operate the real product through its supported web, API, CLI, desktop, or mobile surface, and produce an auditable pass, fail, or blocked judgment with screenshots, logs, recordings, and a step timeline when available. Use when asked…

tamdogood/builder-essential-skills · 122 tokens

session-profiler

Profile and debug Hermes sessions from their JSONL transcripts. Find a session and its subagents, build a queryable event table, summarize the work as a hierarchical table of contents, break down wall time, inference, tools, tokens, and estimated cost per agent, identify errors and improvement opportunities, and…

tamdogood/builder-essential-skills · 117 tokens

code-standards

Apply a disciplined engineering workflow to any code change. Use whenever implementing a feature, fixing a bug, or refactoring — before writing code, not after. Walks orient → baseline → smallest change → test → verify → self-review, and enforces language-agnostic hard gates (don't mass-reformat, keep the linter and…

tamdogood/builder-essential-skills · 94 tokens

debug

Investigate a bug to its root cause systematically — reproduce, trace the data flow, test one hypothesis at a time — then fix it with a regression test. Use when something is broken and the user has a symptom or error message to chase down.

bromso/metapowers · 52 tokens