31Practices

Test-first development

Write the tests first and confirm they fail; the agent then works until they pass.

Also called Red/green TDD, Test-driven development

Taylor et al., Cursor, Anthropic, Simon Willison, Kent Beck

writes firstruns themPersonYouCodeTestsAgentAgent
How to read this

The problem

An agent may write code that does not work or is never used, and stops when the work only looks done.

A significant risk with coding agents is that they might write code that doesn't work, or build code that is unnecessary and never gets used, or both.
Simon WillisonRed/green TDD - Agentic Engineering Patterns
Claude stops when the work looks done. If it has nothing to run that tells it whether the work actually is done, “looks done” is all it has to go on.
AnthropicBest practices for Claude Code

Therefore

Agents perform best when they have a clear target to iterate against. Tests allow the agent to make changes, evaluate results, and incrementally improve until it succeeds.
CursorBest practices for coding with agentsJan 9, 2026
Ask Claude to create tests before starting work
AnthropicPrompting best practices
The most disciplined form of TDD is test-first development. You write the automated tests first, confirm that they fail, then iterate on the implementation until the tests pass.
Simon WillisonRed/green TDD - Agentic Engineering Patterns

In use

Kent Beck

You can see from the first commits that I was trying to get the genie to use TDD.
Kent BeckAugmented Coding: Beyond the VibesJun 25, 2025

Simon Willison

If an agent finds something that doesn't work through their manual testing, I like to tell them to fix it with red/green TDD.
Simon WillisonAgentic manual testing - Agentic Engineering Patterns

Anthropic's Security Engineering team

The Security Engineering team transformed their workflow from "design doc → janky code → refactor → give up on tests" to asking Claude for pseudocode, guiding it through test-driven development, and checking in periodically.
AnthropicHow Anthropic teams use Claude CodeJul 24, 2025

Where it breaks

The agent can bend code to pass the tests or tamper with the tests, or write mock implementations unless told the work is test-first.

Claude can sometimes focus too heavily on making tests pass at the expense of more general solutions, or might use workarounds such as helper scripts for complex refactoring instead of using standard tools directly.
AnthropicPrompting best practices
Be explicit that you're doing TDD so it avoids creating mock implementations for functionality that doesn't exist yet.
CursorBest practices for coding with agentsJan 9, 2026
Reward hacking has been observed in real training runs, with coding agents learning to overwrite or tamper with test cases rather than write correct code.
Taylor et al.School of Reward Hacks: Hacking harmless tasks generalizes to misaligned behavior in LLMs

Sources

  1. School of Reward Hacks: Hacking harmless tasks generalizes to misaligned behavior in LLMsMia Taylor, James Chua, Jan Betley, Johannes Treutlein, Owain Evans, Taylor et al.
  2. Best practices for coding with agentsLee Robinson, Cursor, Jan 9, 2026
  3. How Anthropic teams use Claude CodeAnthropic, Jul 24, 2025
  4. Prompting best practicesAnthropic
  5. Best practices for Claude CodeAnthropic
  6. Red/green TDD - Agentic Engineering PatternsSimon Willison
    Every good model understands "red/green TDD" as a shorthand for the much longer "use test driven development, write the tests first, confirm that the tests fail before you implement the change that gets them to pass".
  7. Augmented Coding: Beyond the VibesKent Beck, Jun 25, 2025
  8. Agentic manual testing - Agentic Engineering PatternsSimon Willison

Added Nov 14, 2026