TDD Guard
TDD Guard is an npm package providing automated Test-Driven Development enforcement for AI agents, specifically within the Claude Code environment. It is currently at version 1.6.3 and exhibits a rapid release cadence, with frequent updates addressing bugs, introducing new features, and enhancing refactoring capabilities. Its primary function is to ensure AI agents adhere strictly to TDD principles by proactively blocking actions that violate test-first or minimal implementation rules, such as adding code without accompanying failing tests or implementing beyond the scope of current test requirements. Key differentiators include its broad multi-language support (e.g., JavaScript, TypeScript, Ruby, Python, Go, Rust, PHP) and integration with numerous test frameworks (including Vitest, Jest, RSpec, and PHPUnit). The package also offers customizable validation rules, lint integration for automated refactoring support, and granular control over validation models and session management.
Common errors
-
Plugin blocked action: Premature implementation. Add a failing test first.
cause Attempting to add or modify implementation code before a corresponding failing test exists, or engaging in certain refactor patterns not recognized by older validator versions.fixEnsure a failing test is present that requires the new code. If refactoring, ensure you are on TDD Guard v1.6.3+ which has improved refactor recognition. Consider the 'adjusting an implementation's signature' or 'tidying existing tests' patterns now allowed. -
Error: Node.js version is too old. TDD Guard requires Node.js >=22.0.0.
cause The system's Node.js version does not meet the minimum requirement specified in the package's `engines` field.fixUpdate your Node.js installation to version 22.0.0 or later. Use a Node.js version manager like `nvm` (`nvm install 22 && nvm use 22`) for easier management. -
Custom validation rules in .claude/tdd-guard/data/instructions.md are not working or outdated.
cause After updating TDD Guard, the custom `instructions.md` file was not refreshed or merged with new default rules, leading to unexpected validation behavior.fixBackup your custom `instructions.md` file. Delete the original `.claude/tdd-guard/data/instructions.md`. Start a new Claude Code session to let TDD Guard regenerate the latest default instructions. Then, manually re-apply your specific customizations to the new file.
Warnings
- breaking The `VitestReporter` constructor signature changed in `tdd-guard-vitest` v0.2.0. It now expects a single options object `{ projectRoot: string }` instead of a direct path string or `Storage` instance.
- gotcha Customized validation rules in `.claude/tdd-guard/data/instructions.md` are not automatically updated when the plugin is upgraded. This means new improvements or bug fixes to the core validation logic may not apply.
- gotcha Older versions of TDD Guard (pre-1.6.x) frequently blocked legitimate refactoring activities, such as moving type declarations, extracting functions, or tidying tests, as 'premature implementation'.
- gotcha TDD Guard requires Node.js version 22 or higher to run. Using older Node.js versions will result in installation or runtime errors.
- security A Time-of-Check to Time-of-Use (TOCTOU) race condition in file content reading (CodeQL `js/file-system-race`) was identified and patched.
Install
-
npm install tdd-guard -
yarn add tdd-guard -
pnpm add tdd-guard
Imports
- VitestReporter
import { VitestReporter } from 'tdd-guard'; const VitestReporter = require('tdd-guard/vitest');import { VitestReporter } from 'tdd-guard/vitest'; - RspecReporter
const RspecReporter = require('tdd-guard/rspec');import { RspecReporter } from 'tdd-guard/rspec'; - MinitestReporter
import MinitestReporter from 'tdd-guard/minitest';
import { MinitestReporter } from 'tdd-guard/minitest';
Quickstart
/plugin marketplace add nizos/tdd-guard /plugin install tdd-guard@tdd-guard /tdd-guard:setup # After installation, you might need to restart your terminal session or IDE extension for the setup skill to appear. # You can then start a Claude Code session, and TDD Guard will begin enforcing TDD principles. # Example: If you try to write code without a failing test, it will block the action.