Skip to main content

CLI Reference

Commands

testpilot ships two commands:

CommandDescription
generate <target> (default)Generate tests for a file or directory
analyzeFind files that need tests, ranked by coverage

generate

testpilot generate [options] <target>
# or, since generate is the default:
testpilot [options] <target>

The target can be a single file or a directory. When pointing at a directory, testpilot walks the tree recursively and generates tests for every .ts, .tsx, .js, .jsx file (skipping .test.* / .spec.* files and conventional ignore directories: node_modules, dist, build, coverage, .git, .next, .nuxt, .svelte-kit, .cache, docs).

Options

FlagDescriptionDefault
-p, --provider <provider>LLM provider: openai, anthropic, google, ollama. Unknown values are rejected up-front.openai
-m, --model <model>Model to use (e.g. gpt-4o, claude-sonnet-4-20250514)Provider default
-k, --api-key <key>API key (or use environment variable)
-f, --framework <framework>Test framework: vitest, jest, mocha, nodeAuto-detected
-o, --out-dir <dir>Output directory for test filesSame as source
--overwriteOverwrite existing test filesfalse
--no-edge-casesSkip edge case testsEdge cases enabled
--no-error-handlingSkip error handling testsError handling enabled
--instructions <text>Additional instructions for the LLM
--max-tokens <n>Max tokens for LLM response4096
--temperature <n>Temperature for LLM0.2
--dry-runGenerate tests without writing filesfalse
-s, --streamStream LLM output in real-time (auto-disabled when --concurrency > 1)true
--verifyRun tests after generation and auto-fix failuresfalse
--fix-iterations <n>Max auto-fix iterations (with --verify)3
-c, --concurrency <n>Number of files to process in parallel1
--max-cost <usd>Abort the run if estimated cost exceeds this USD amount (uses a per-provider price table)
-V, --versionOutput the version number
-h, --helpDisplay help

Examples

# Generate tests for a single file
npx testpilot src/utils.ts

# Generate AND verify — auto-fix until all tests pass
npx testpilot src/utils.ts --verify

# Process an entire directory tree, 4 files in parallel, with a $1 cap
npx testpilot src/ --verify --concurrency 4 --max-cost 1

# Use Anthropic with Claude
npx testpilot src/utils.ts --provider anthropic --model claude-sonnet-4-20250514

# Generate Mocha or Node test-runner tests
npx testpilot src/utils.ts --framework mocha
npx testpilot src/utils.ts --framework node

# Dry run — preview without writing
npx testpilot src/utils.ts --dry-run

# Use local Ollama models (no API key, no cost)
npx testpilot src/utils.ts --provider ollama --model llama3

analyze

Find files that most need tests, ranked by lowest coverage first. Reads coverage/lcov.info or coverage/cobertura-coverage.xml if present; otherwise falls back to "source files without sibling test files."

testpilot analyze [options]

Options

FlagDescriptionDefault
-t, --target <rate>Coverage target (0–1)0.8
-l, --limit <n>Max files to show15

Example

# Get a ranked list of files below 80% coverage
npx vitest run --coverage --reporter=lcov
npx testpilot analyze

Output

generate displays:

  1. Header — provider, model, framework, file count, concurrency, verify status
  2. Cost estimate — when --max-cost is set
  3. Per-file progress — streaming LLM output (single file at a time) and verify/fix iteration logs
  4. File summary — test file path, test count, categories, duration, verify status
  5. Final summary — total tests, files, tokens, time