tdd-refactor-guard

tdd-refactor-guard is a skill for Claude Code from rshankras/claude-code-apple-skills. It costs 33 tokens per session (1,725 once invoked), scanned A, original, MIT.

A safety check run before changing existing code: it confirms that tests cover the area being refactored and creates basic behavior tests when they do not. Refactoring means changing code structure without intending to change what it does.

In plain words
What is it for?
It helps prepare code for renaming, extraction, simplification, reorganizing, or migrations between design patterns and storage technologies.
Why use it?
Restructuring code without tests can introduce regressions that are difficult to notice. This check provides evidence of the old behavior before the change begins.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: names the AskUserQuestion tool.

Part of the apple-skills plugin — 182 skills shipped together , and of apple-skills

Good fit It helps prepare code for renaming, extraction, simplification, reorganizing, or migrations between design patterns and storage technologies.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rshankras/claude-code-apple-skills/tdd-refactor-guard
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 rshankras/claude-code-apple-skills --skill tdd-refactor-guard
Clone the repo
git clone --depth 1 https://github.com/rshankras/claude-code-apple-skills

Made for: Claude Code.

Or install apple-skills, the plugin that ships this one along with the rest of its 182 skills.

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 tdd-refactor-guard

README.md
[![agentmods](https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard/github.svg)](https://agentmods.dev/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard)
Your own site
<a href="https://agentmods.dev/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard"><img src="https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard/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 tdd-refactor-guard

Your own site · 80×15
<a href="https://agentmods.dev/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard"><img src="https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/tdd-refactor-guard.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,725 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.
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.00033 $0.01725
Opus 5.5 $0.00013 $0.00690
Sonnet 5.5 $0.00007 $0.00345
Haiku 4.5 $0.00003 $0.00172

Measured 1mo ago against content hash 341e4dd2aa5a, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

tdd-refactor-guard 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 1mo 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/testing/tdd-refactor-guard/SKILL.md · 248 lines

How it starts

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

TDD Refactor Guard

A safety gate that runs before any AI-assisted refactoring. Ensures tests exist to catch regressions. If coverage is insufficient, generates characterization tests first.

When This Skill Activates

Use this skill when the user:

  • Says "refactor this" or "clean this up"
  • Wants AI to "restructure" or "reorganize" code
  • Asks to "extract", "inline", "rename", or "simplify" existing code
  • Plans to migrate between patterns (e.g., MVC → MVVM, CoreData → SwiftData)
  • Wants AI to "improve" or "modernize" existing code

Why This Guard Exists

Without guard:               With guard:
"Claude, refactor this"      "Claude, refactor this"
  → AI rewrites code           → Guard checks for tests
  → Something breaks           → Tests missing → generate them
  → You don't know what        → Tests pass → proceed with refactor
  → Debugging nightmare         → Tests fail → exact regression found

Process

Step 1: Identify Scope

What code is being refactored?

Ask user: "Which files/classes are you planning to refactor?"

Or detect from context:

Glob: [files mentioned in conversation]
Read: each file to understand scope

Determine:

  • Files involved
  • Public API surface (methods, properties)
  • Dependencies (what calls this code, what it calls)
  • Side effects (network, disk, notifications, UI updates)

Step 2: Check Existing Test Coverage

Grep: "class.*Tests.*XCTestCase|@Suite.*Tests|struct.*Tests" in test targets
Grep: "@Test|func test" that reference the classes being refactored
Coverage Assessment
Level Criteria Action
Good (> 80%) Most public methods have tests for happy + error paths Proceed with refactoring
Partial (40-80%) Some methods tested, missing edge cases Add characterization tests for uncovered methods
Minimal (< 40%) Few or no tests Generate full characterization test suite first
None (0%) No test file exists STOP — create characterization tests before any refactoring

Read the full file on GitHub · 248 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. 1mo ago First seen · 248 lines · 33 tokens per session scan A 341e4dd2aa5a

Subscribe to this mod's changes

tdd-refactor-guard is a skill published in the GitHub repository rshankras/claude-code-apple-skills (927 stars, last pushed 26d ago), licensed MIT. It adds 33 tokens to every session and 1,725 once invoked, about $0.0001 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-11-05.

Related

tdd-refactor-guard compared with skills from other repositories

tdd-refactor-guard next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
tdd-refactor-guardrshankras/claude-code-apple-skillsSkill92726d agoMITA33Claude Code
kotlin-testingaffaan-m/ECCSkill317k3d agoMITA38Claude Code, Kiro
cpp-testingaffaan-m/ECCSkill317k3d agoMITA34Claude Code, Kiro
image-crop-rotateinstavm/coderunnerSkill903yesterdayApache-2.0A50Claude Code, Codex
triage-issuesoftspark/ai-toolkitSkill1802d agoApache-2.0A39Claude Code
tddsoftspark/ai-toolkitSkill1802d agoApache-2.0A33Claude Code
tdd-workflowFlorianBruniaux/claude-code-ultimate-guideSkill7.6k2d agoCC-BY-SA-4.0A44Claude Code