tdd-refactor

A command for the refactor stage of test-driven development (TDD), a method where tests guide implementation. It improves code after the tests are passing, using project notes and earlier implementation documents.

In plain words
What is it for?
Use it to refactor an implemented feature, review its requirements and test cases, and record the refactor work in the project’s implementation documents.
Why use it?
It gives the cleanup stage a defined place after working code has been written. This helps developers improve code quality while keeping the documented requirements and tests in view.

Command

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 commands/classmethod/tsumiki/tdd-refactor
Clone the repo
git clone --depth 1 https://github.com/classmethod/tsumiki
Per session 39 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,990 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.00039 $0.04990
Opus 5 $0.00019 $0.02495
Sonnet 5 $0.00008 $0.00998
Haiku 4.5 $0.00004 $0.00499

Measured 2d ago against content hash 2d2423f3c009, 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 2d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

legacy/commands/tdd-refactor.md · 409 lines

How it starts

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

TDDのRefactorフェーズを実行し、Greenフェーズで作成した実装コードの品質を改善します。

context

出力ディレクトリ="./docs/implements" 機能名={{feature_name}} タスクID={{task_id}} 要件名={{requirement_name}} 信頼性評価=[] メモファイル=./docs/implements/{要件名}/{{task_id}}/{feature_name}-memo.md 要件定義ファイル=./docs/implements/{要件名}/{{task_id}}/{feature_name}-requirements.md テストケースファイル=./docs/implements/{要件名}/{{task_id}}/{feature_name}-testcases.md Greenフェーズファイル=./docs/implements/{要件名}/{{task_id}}/{feature_name}-green-phase.md Refactorフェーズファイル=./docs/implements/{要件名}/{{task_id}}/{feature_name}-refactor-phase.md

step

  • $ARGUMENTS がない場合、「引数に要件名とTASK-IDを指定してください(例: ユーザー認証機能 TASK-0001)」と言って終了する
  • $ARGUMENTS の内容と context の内容をまとめてユーザに宣言する
  • step2 を実行する

step2: コンテキスト準備

開発コンテキストの準備を実行する:

  1. タスクノートの読み込み(唯一のコンテキストソース)

    • ./docs/implements/{要件名}/{{task_id}}/note.md を読み込み
    • 存在しない場合: @task で /tsumiki-legacy:tdd-tasknote {要件名} {{task_id}} を実行して生成
    • note.mdには技術スタック、開発ルール、関連実装、設計文書、テスト関連情報、注意事項が集約済み
  2. 直前フェーズの出力を読み込み

    • ./docs/implements/{要件名}/{{task_id}}/{feature_name}-requirements.md - 要件定義
    • ./docs/implements/{要件名}/{{task_id}}/{feature_name}-testcases.md - テストケース定義
    • ./docs/implements/{要件名}/{{task_id}}/{feature_name}-green-phase.md - Greenフェーズの実装記録
    • ./docs/implements/{要件名}/{{task_id}}/{feature_name}-refactor-phase.md - 既存のRefactorフェーズ記録(存在する場合)
    • ./docs/implements/{要件名}/{{task_id}}/{feature_name}-memo.md - 開発履歴メモ(存在する場合)

読み込み完了後、step3 を実行する

step3: テスト実行とコード品質確認

  • 現在のテストが全て通ることを確認

    • 【品質保証】: リファクタ前の動作確認
    • 【安全性確保】: 変更による機能破綻の防止
    • 【実行方法】: Taskツールを使用してテストを実行し、結果を詳細に分析
  • テスト実行時間のチェック

    • 【長時間テストの検出】: 2秒以上かかるテストがないか確認
    • 【警告表示】: 遅いテストが見つかった場合は以下を表示
      ⚠️ 遅いテストが検出されました(2秒以上)
      
      詳細な分析とリファクタリング提案が必要な場合:
      `/tsumiki:dcs:test-performance-analysis` を実行してください
      
      テスト実行速度の改善パターン:
      `/tsumiki:test-optimization-patterns` を実行してください
      
  • コード・テスト除外チェック

    • 【.gitignore確認】: 本来確認対象のコードファイルが除外されていないかチェック
    • 【テスト除外確認】: describe.skip, it.skip, test.skip等でテストが無効化されていないかチェック
    • 【jest設定確認】: jest.config.jspackage.jsontestPathIgnorePatterns等でテストファイルが除外されていないかチェック
    • 【実行対象確認】: 実際に実行されるべきテストとコードが適切に対象に含まれているかチェック

Read the full file on GitHub · 409 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. 2d ago First seen · 409 lines · 39 tokens per session scan A 2d2423f3c009

Subscribe to this mod's changes

tdd-refactor is a command published in the GitHub repository classmethod/tsumiki (974 stars, last pushed 25d ago), licensed MIT. It adds 39 tokens to every session and 4,990 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-30.