tdd

tdd is a command for Claude Code from cfrs2005/claude-init. It costs 37 tokens per session (2,640 once invoked), scanned A, original, MIT.

A command that follows test-driven development (TDD), a method where you write tests before the code they check. It moves through writing a failing test, adding the smallest implementation, and then improving the code.

In plain words
What is it for?
Use it when building functions or components, reproducing bugs with tests, refactoring code, or implementing important business logic.
Why use it?
It gives new features, bug fixes, and refactors a clear testing process. It also checks that test coverage reaches at least 80%.

Command for Claude Code

Written for Claude Code: installed under .claude/. Also seen: reads .claude/ paths.

Good fit Use it when building functions or components, reproducing bugs with tests, refactoring code, or implementing important business logic.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/cfrs2005/claude-init/tdd
About the project

claude-init is an archived project template for initializing Claude Code development environments, with Chinese-localized configuration and workflows. Developers on macOS or Linux use it to set up agents, skills, commands, rules, hooks, and development contexts for Claude Code. Its catalogue entries provide the included commands, agents, hooks, and skills.

cfrs2005/claude-init · 1,361 stars · on GitHub

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.

Clone the repo
git clone --depth 1 https://github.com/cfrs2005/claude-init

Made for: Claude Code.

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/cfrs2005/claude-init/tdd/github.svg)](https://agentmods.dev/commands/cfrs2005/claude-init/tdd)
Your own site
<a href="https://agentmods.dev/commands/cfrs2005/claude-init/tdd"><img src="https://agentmods.dev/badge/commands/cfrs2005/claude-init/tdd/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

Your own site · 80×15
<a href="https://agentmods.dev/commands/cfrs2005/claude-init/tdd"><img src="https://agentmods.dev/badge/commands/cfrs2005/claude-init/tdd.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 37 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,640 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.00037 $0.02640
Opus 5.5 $0.00015 $0.01056
Sonnet 5.5 $0.00007 $0.00528
Haiku 4.5 $0.00004 $0.00264

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

Security

Grade A, and why

tdd 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.

Origin

Copies of this mod

2 near-identical copies found in the catalogue:

  • tdd — 88% identical, 154 lines differ
  • tdd — 81% identical, 162 lines differ
templates/.claude/commands/tdd.md · 329 lines

How it starts

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

TDD 指令 (TDD Command)

此指令调用 TDD 向导 (tdd-guide) 智能体,以强制执行测试驱动开发 (TDD) 方法论。

此指令的功能

  1. 搭建接口 - 首先定义类型/接口
  2. 先写测试 - 编写会失败的测试 (红)
  3. 实现最小代码 - 编写刚好能通过测试的代码 (绿)
  4. 重构 - 在保持测试通过的前提下改进代码 (重构)
  5. 验证覆盖率 - 确保 80% 以上的测试覆盖率

何时使用

在以下情况使用 /tdd:

  • 实现新功能时
  • 添加新函数/组件时
  • 修复 Bug 时 (先写一个能复现 Bug 的测试)
  • 重构现有代码时
  • 构建关键业务逻辑时

工作原理

TDD 向导智能体将:

  1. 定义接口 用于输入/输出
  2. 编写会失败的测试 (因为代码还不存在)
  3. 运行测试 并验证它们因正确的原因而失败
  4. 编写最小实现 以通过测试
  5. 运行测试 并验证它们通过
  6. 重构 代码,同时保持测试通过
  7. 检查覆盖率 如果低于 80%,则添加更多测试

TDD 循环

红 (RED) → 绿 (GREEN) → 重构 (REFACTOR) → 重复 (REPEAT)

红 (RED):      编写一个失败的测试
绿 (GREEN):    编写最小代码以通过测试
重构 (REFACTOR): 改进代码,保持测试通过
重复 (REPEAT):   处理下一个功能/场景

使用示例

User: /tdd I need a function to calculate market liquidity score
(用户:/tdd 我需要一个计算市场流动性得分的函数)

Agent (tdd-guide):
# TDD Session: Market Liquidity Score Calculator
(TDD 会话:市场流动性得分计算器)

## Step 1: Define Interface (SCAFFOLD) (步骤 1:定义接口)

```typescript
// lib/liquidity.ts
export interface MarketData {
  totalVolume: number
  bidAskSpread: number
  activeTraders: number
  lastTradeTime: Date
}

export function calculateLiquidityScore(market: MarketData): number {
  // TODO: Implementation (待实现)
  throw new Error('Not implemented')
}

Step 2: Write Failing Test (RED) (步骤 2:编写失败测试 - 红)

// lib/liquidity.test.ts
import { calculateLiquidityScore } from './liquidity'

describe('calculateLiquidityScore', () => {
  it('should return high score for liquid market', () => {
    const market = {
      totalVolume: 100000,
      bidAskSpread: 0.01,
      activeTraders: 500,
      lastTradeTime: new Date()
    }

    const score = calculateLiquidityScore(market)

    expect(score).toBeGreaterThan(80)
    expect(score).toBeLessThanOrEqual(100)
  })

  it('should return low score for illiquid market', () => {
    const market = {
      totalVolume: 100,
      bidAskSpread: 0.5,
      activeTraders: 2,
      lastTradeTime: new Date(Date.now() - 86400000) // 1 day ago
    }

Read the full file on GitHub · 329 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 · 329 lines · 37 tokens per session scan A 13540a980560

Subscribe to this mod's changes

tdd is a command published in the GitHub repository cfrs2005/claude-init (1,361 stars, last pushed 7mo ago), licensed MIT. It adds 37 tokens to every session and 2,640 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-08-30.