refactor-safely

refactor-safely is a skill for Claude Code, Codex from techygarg/lattice. It costs 82 tokens per session (2,634 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 CodeCodex

Part of the lattice plugin — 33 skills, 2 agents shipped together

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.

agentmods
npx agentmods add skills/techygarg/lattice/refactor-safely
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, Codex.

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

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.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.svg" alt="Measured on agentmods" 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,634 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00082 $0.02634
Opus 5 $0.00041 $0.01317
Sonnet 5 $0.00016 $0.00527
Haiku 4.5 $0.00008 $0.00263

Measured 5d ago against content hash 6206df716793, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 5d 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.

plugins/lattice/skills/refactor-safely/SKILL.md · 221 lines

How it starts

The opening of the file, as written. The whole thing — 221 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)

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 · 221 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. 5d 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 (183 stars, last pushed 6d ago), licensed MIT. It adds 82 tokens to every session and 2,634 once invoked, about $0.0004 per session on Opus 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

name-your-business

Generate, refine, compare, and when needed validate distinctive names for startups, AI products, developer tools, protocols, open-source projects, apps, product families, local businesses, services, companies, nonprofits, and other organizations. Use when asked to name or rename a business, brand, product, venture…

tamdogood/builder-essential-skills · 156 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

async-learning-teacher

Transform saved links, papers, articles, posts, videos, and reference collections into approachable AI teaching artifacts for later study. Use when a user wants to queue learning material, create a readable explanation from a source, teach a paper or post step by step, or run an interactive tutor that validates…

tamdogood/builder-essential-skills · 68 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

plan-create

Create structured implementation plans for autonomous TDD development. Use for new features, multi-file changes, or anything requiring multiple steps or tests. Triggers on aspirational openers ("let's build", "let's start building", "I want to make", "I want an app that", "help me build"), capability lists ("users…

markshust/hcf · 171 tokens

forge

Plan, execute, and validate complex multi-step tasks with automatic retry and memory.

TT-Wang/forge · 17 tokens