Guide
What you get: A test writer that adds focused tests for changed code, runs them, and reports bugs it finds instead of changing the code. Best for Developers who just wrote or changed a function and want tests for it..
Before you start
- The code to test is committed or staged (step 1 uses `git diff --name-only HEAD`)
- A test command; with no test framework installed, Node's built-in `node --test` works on Node 22.18+/24 for .ts files
- Fill in project_name, test_framework and test_command
Worked example (Oct 17, 2026, Claude Code 2.1.296; Codex 0.151.0 (gpt-5.6-sol))
Input
New pure function src/lib/truncate.ts (staged, no tests). The project has no test runner, so blanks were filled with test_framework = "node:test (Node's built-in test runner; no test framework is installed)" and test_command = `node --test "src/**/*.test.ts"`. Request: "Use the test-writer subagent to write tests for src/lib/truncate.ts."
Result
Claude Code: the test-writer subagent added src/lib/truncate.test.ts with 30 node:test tests, installed nothing and left truncate.ts unchanged. My run: 28 pass, 2 fail, and both failures are real bugs it reported: truncate("hello world foo", 12) returns "hello…" although "hello world…" fits, and emoji can be split in half. Codex: the test-writer agent added 9 tests; my run: 8 pass, 1 fail (the same emoji bug); truncate.ts unchanged.Test project: fresh create-next-app (Next.js 16.4.2, TypeScript), Node 24.14.1. Blanks filled with project_name = "demo-app (Next.js 16 + TypeScript)". Claude Code: body saved as .claude/agents/<name>.md, run headless with `claude -p "Use the <name> subagent to ..." --permission-mode acceptEdits`. Codex: converted to .codex/agents/<name>.toml (name, description, developer_instructions) and run with `codex exec -m gpt-5.6-sol -s workspace-write "Use the <name> agent to ..."`. Subagent use was confirmed from Claude Code's stream-json log (Agent call with subagent_type) and from Codex session logs (spawn_agent with agent_type, and the agent's instructions present in the child session). Claude Code allowed tools: Bash(node *), Bash(git diff *), Bash(git status *). The failing tests are intentional: the template says to report code bugs, not change the code. `npx tsc --noEmit` rejects the test's `./truncate.ts` import (TS5097) because tsconfig lacks allowImportingTsExtensions; Claude's subagent warned about this, and I confirmed it. After this test step 1 also checks git status for new files, and it asks before adding a test runner.
How to check it worked
- Run the test command yourself and read any failures: decide whether the test or the code is wrong
- Check `git diff` shows no change to the code under test
- Check there is at least one test per error path
Common problems
- With node:test and TypeScript, importing `./file.ts` works in Node but fails `tsc`/`next build` type checks unless tsconfig allows it or excludes test files
- A brand-new file that is not staged or committed is invisible to step 1 (`git diff --name-only HEAD`), so name the file in your request
- Coverage depth varies: one run wrote 30 tests, the other 9
Log in to join the discussion.