Skip to main content
command CX Codex

add-tests — Claude Code command: tests and setup

The add-tests command adds tests for a chosen file or function, or targets recently changed code when no argument is given. It runs the tests afterward.

MIT ★ 1,424 updated 2026-10-06

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/add-tests.md
Open on GitHub

What add-tests does

add-tests identifies the requested target, locates a matching test file, and follows the project’s existing conventions. When no suitable file exists, it creates one. The command examines inputs, outputs, edge cases, and failure paths, then writes checks for the normal case, boundary behavior, and errors.

It builds context from git diff, the project root, existing test filenames, and directories such as test, tests, __tests__, or spec. Its allowed tools include Read, Write, plus git, npm, npx, yarn, bun, pytest, and go. It runs the tests after editing. With no target argument, it focuses on recently changed files lacking coverage, so a large repository calls for a specific path or function name.

What it helps with

  • add tests for a selected file
  • cover recently changed code
  • find a test file by project convention
  • check edge cases and failures
  • run tests after writing changes

Example prompts for the agent

  • Add tests for the parseConfig function in src/config.ts.
  • Find recently changed files without coverage and add their tests.
  • Run /add-tests for src/api/users.ts.

How to install add-tests

Manually: put the files in place

.claude/commands/add-tests.md

Call it with /add-tests. For all projects use ~/.claude/commands/

Questions about add-tests

How do I install add-tests in Claude Code?

Create .claude/commands/add-tests.md and place the add-tests command in that file.

What does add-tests do?

It finds a file or function to test, uses or creates a matching test file, covers normal behavior, edge cases, and errors, then runs the tests.

What happens when no target is provided?

The command focuses on recently modified files that lack test coverage.

Source text

add-tests.md · MIT
---
allowed-tools: Bash(git:*), Bash(npm:*), Bash(npx:*), Bash(yarn:*), Bash(bun:*), Bash(pytest:*), Bash(go:*), Read, Write
description: Add tests for recently changed files or specified code
argument-hint: "[file path or function name]"
---

## Context

- Recently modified files: !`git diff --name-only HEAD~3 2>/dev/null | head -10`
- Project root files (infer the test framework from these): !`ls -a`
- Existing test files: !`git ls-files 2>/dev/null | grep -i -e test -e spec | head -10`
- Test directory structure: !`ls -la tests/ test/ __tests__/ spec/ 2>/dev/null | head -20`

## Task

Add tests for the specified target:

1. Identify the file/function to test
2. Find the corresponding test file (or create one following project conventions)
3. Analyze the code to understand:
   - Input/output behavior
   - Edge cases
   - Error conditions
4. Write comprehensive tests covering:
   - Happy path
   - Edge cases
   - Error handling
5. Run the tests to verify they pass

Target: $ARGUMENTS

If no target specified, focus on recently modified files that lack test coverage.

© CloudAI-X · MIT · CloudAI-X/claude-workflow-v2

Similar slash commands

All slash commands for Testing and QA →

From the same set46

The whole set →

Project sponsors

Companies that keep this analytics open