Test-first feature work with a coding agent
Have the agent write failing tests from the spec, confirm they fail, then write code until they pass, with a person checking the tests first.
The use case
Coding agents do their best work when they have a clear target to check against. Anthropic's Claude Code guidance recommends a test-driven loop: ask the agent to write tests from the expected behavior, run them to confirm they fail, commit them, then ask it to implement until they pass without editing the tests. This gives the developer a concrete checkpoint. The key human step is reading the tests before any implementation, because the tests now define what correct means. After that, the developer reviews the implementation for readability and edge cases the tests missed.
Example workflow
- Describe the behavior and ask the agent for tests only
- Run the tests and confirm they fail for the right reason
- Review and commit the tests
- Ask the agent to implement until tests pass without changing them
- Review the code and add tests for missed edge cases
Tools
- Claude Code
Risks and guardrails
- Weak tests let wrong code pass; review tests first
- Agent may try to edit tests to make them pass; tell it not to and check the diff
- Mocks can hide integration problems
Sources
Written by Agents Lookup. Credits and official pages for the tools this use case names:
- Claude Code docs: best practices: code.claude.com/docs/en/best-practices