Back/Engineering/Claude Code
IntermediateEngineering

How to Fix Bugs Using an AI-Powered Test-Driven Development (TDD) Workflow

Leverage an AI coding assistant like Claude Code to implement a Test-Driven Development (TDD) process. This workflow allows you to reproduce, fix, and verify bug fixes with incredible speed and accuracy.

How to Fix Bugs Using an AI-Powered Test-Driven Development (TDD) Workflow

From 36:26 to 39:38, Eddie Kim demonstrates fixing a payroll bug in Claude Code by first creating an evaluation that reproduces the failure, then changing the code until it passes. Clip range: 36:26 to 39:38.

Before you start

What you need

  • GitHub issue describing the bug
  • AI coding assistant with repository access
  • Existing automated test framework
  • Permission to create pull requests
  • Target repository branch for the fix

What you’ll make

A pull request containing a failing regression test, the implemented fix, and passing test results.

Tools used

Step by step

The workflow

Follow the sequence once, then adapt the prompts, checks, and handoffs to your own setup.

6 steps

Step01

Identify the Bug and Context

Select a specific bug, usually from a bug report or a GitHub issue. This document should clearly describe the failure and provide enough detail for the AI to understand the problem.

Step02

Craft a Detailed TDD Prompt

In your AI coding assistant, provide a prompt that points to the GitHub issue. Instruct the AI to follow a test-driven development (TDD) process: first, write a test that reproduces the bug and fails; second, propose a fix; and third, prove the fix works by showing the test now passes.

Example prompt
There's a customer issue that is outlined in this GitHub issue... Can you please read this issue and come up with a fix for the problem that's outlined here? I'd love for you to first write an eval that fails to show that you can reproduce this issue, then come up with a solution, and then prove that the solution works by showing that the eval now passes.
Step03

AI Writes a Failing Test

The AI reads the issue and generates a test case, or evaluation, designed to fail. This failing test serves as confirmation that the AI can successfully reproduce the bug as described.

Step04

AI Proposes and Tests the Fix

The AI then proposes a solution, which could be a code change or a modified prompt. It runs the same evaluation again, this time expecting it to pass. The passing test is the proof that the proposed fix works.

Step05

Conduct a Human Review

Review the AI's proposed code change and the test case. Use your judgment to verify that the fix is correct, high quality, and does not introduce any unintended side effects.

Step06

Commit the Fix

Once you approve the solution, instruct the AI to open a pull request. This prepares the change for team review and merging into the main codebase.

Example prompt
This looks correct. Please open a pull request with the title "[PR Title]" and the following description: [Describe the fix and link to the original issue].

What good looks like

  • New test reproduces the reported bug before the fix
  • Updated tests pass after the fix is applied
  • Pull request references the original GitHub issue
  • Human reviewer approves the code and regression coverage

Build your next product with ChatPRD

Turn an idea into a PRD, user stories, and a plan.

Try ChatPRD free

After the steps

Runbook notes

How to recover when the loop fails and where human judgment helps.

Recover

If it goes sideways

Regression test does not accurately reproduce the customer issue
Match the test inputs and environment to the issue report details
Fix passes the new test but breaks unrelated functionality
Run the full repository test suite and inspect failing areas
AI changes unrelated files while implementing the fix
Restrict the PR scope to files connected to the failing test

Start shipping
better products.

Join 100,000+ product managers who use ChatPRD to write better docs, align teams faster, and build products users love.

Free to start
No credit card
SOC 2 certified
Enterprise ready