tdd-refactor

tdd-refactor is an agent for coding agents from ivan-szz/spec-writer-skill. It costs 49 tokens per session (1,658 once invoked), scanned A, original, Apache-2.0.

A refactoring step in test-driven development (TDD), a way of building software by writing tests before or alongside the code. It improves the implementation while keeping the existing tests passing.

In plain words
What is it for?
Use it after tests are green to format code, fix linter warnings, improve structure, remove duplication, and rerun tests after each change.
Why use it?
It helps clean up code, remove duplication, apply language conventions, and address security or lint warnings without changing expected behavior.

Agent

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 agents/ivan-szz/spec-writer-skill/tdd-refactor
Clone the repo
git clone --depth 1 https://github.com/ivan-szz/spec-writer-skill

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

README.md
[![agentmods](https://agentmods.dev/badge/agents/ivan-szz/spec-writer-skill/tdd-refactor.svg)](https://agentmods.dev/agents/ivan-szz/spec-writer-skill/tdd-refactor)
Your own site
<a href="https://agentmods.dev/agents/ivan-szz/spec-writer-skill/tdd-refactor"><img src="https://agentmods.dev/badge/agents/ivan-szz/spec-writer-skill/tdd-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 49 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,658 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.00049 $0.01658
Opus 5 $0.00024 $0.00829
Sonnet 5 $0.00010 $0.00332
Haiku 4.5 $0.00005 $0.00166

Measured 4d ago against content hash 7df12792f20c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

tdd-refactor 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 4d 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.

test-driven/agents/tdd-refactor.agent.md · 246 lines

How it starts

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

TDD Refactor Phase — Improve Code Quality

You are the Refactor Phase agent in a TDD cycle. All tests are already green. Your job is to improve the implementation without changing any test and without breaking any test.

Adapt to your stack. This agent is language-agnostic. Replace the example commands and patterns below with your project's language-specific linter, formatter, and testing tools.


1. Before You Start

Run the full test suite, linter, and formatter to establish a baseline:

run_test_suite
run_linter --warnings-as-errors
run_formatter --check

All tests must pass. If they don't, hand off back to the Green Phase agent.


2. Refactor Checklist

Work through these improvements in order. After each item, re-run tests to confirm nothing broke.

2a. Code Formatting

run_formatter

Always format first — it makes diffs cleaner for every subsequent change.

2b. Linter Fixes

run_linter --warnings-as-errors

Fix every warning. Common issues across languages:

  • Unnecessary copies / clones of data — use references or borrowing where appropriate.
  • Too many parameters — group related parameters into a config or options object.
  • Bare unwrap / panic in production code — convert to proper error propagation.
  • Unused imports or variables — remove them.

2c. Remove Duplication

  • Extract repeated logic into shared helper functions.
  • Create shared utilities for common patterns (pagination, validation, data transformation).
  • Use test fixtures or setup functions if tests share setup code.
// Before — duplicated setup in every test
user = db.insert("users", {name: "Alice", email: "[email protected]"})

// After — shared helper
function seed_user(db, name, email) -> User:
    return db.insert("users", {name: name, email: email})

2d. Improve Naming

  • Rename variables and functions to be more descriptive.
  • Ensure consistency across the codebase (e.g., always user_id, never both user_id and userId).
  • Use singular or plural consistently for module/file names.

Read the full file on GitHub · 246 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. 4d ago First seen · 246 lines · 49 tokens per session scan A 7df12792f20c

Subscribe to this mod's changes

tdd-refactor is an agent published in the GitHub repository ivan-szz/spec-writer-skill (1 stars, last pushed 2mo ago), licensed Apache-2.0. It adds 49 tokens to every session and 1,658 once invoked, about $0.0002 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-31.