---
title: Recipe: Agent fixes the failing test · Agent Playground docs
description: Claude reads the code, runs the tests and edits until they pass, with your key and inside the sandbox only. What it does, when to use it, how to make it yours, and what a run costs.
url: https://www.quietrobot.ai/docs/playground/recipes/agent-fix-test
---

# Recipe: Agent fixes the failing test

Claude reads the code, runs the tests and edits until they pass, with your key and inside the sandbox only. What it does, when to use it, how to make it yours, and what a run costs.

Hands a failing test to Claude. The agent reads the code, runs the tests, edits the file and runs them again, turn by turn, until a check passes. You don't draw the loop: the agent loops by itself, inside the limits you set.

| At a glance | |
|---|---|
| **Category** | Coding |
| **Shape** | An agent with a check |
| **Plan** | Free and up |
| **Needs a Claude key** | Yes |
| **Limits it comes with** | 2 loops, 600 seconds, $0.75 |

```flow
{"title": "Agent fixes the failing test, as it is on the canvas.", "nodes": [["setup", "run", "Set up project", "go back here"], ["agent", "agent", "Agent fixes it", "12 turns · check"], ["show", "run", "Show the fix"], ["done", "end", "Fixed"]], "edges": [["setup", "agent"], ["agent", "show"], ["show", "done"]]}
```

<figure class="shot">
  <img class="art-light" src="/docs/playground/recipes/agent-fix-test-light.webp" alt="The Agent fixes the failing test recipe open in the builder, ready to run." width="1440" height="900" loading="lazy">
  <img class="art-dark" src="/docs/playground/recipes/agent-fix-test-dark.webp" alt="" width="1440" height="900" loading="lazy">
  <figcaption>The recipe in the builder. It needs your Claude key before it can run.</figcaption>
</figure>

## When to use it

* A bug, a broken build or a failing test that needs someone to read the code and try fixes.
* Any job where "done" can be checked by a command: the tests pass, the script runs, the file is valid.
* You want to see what an AI agent does, step by step, before you trust it with more.

## Run it

1. Open **Agent Playground** in the dashboard and find **Agent fixes the failing test** under **Start from a recipe**. In the builder, **Recipes** in the toolbar lists them too.
2. Choose **Use this recipe**. It becomes a flow of your own, so changing it never changes the recipe.
3. If you haven't yet, [save your Claude key](https://www.quietrobot.ai/docs/playground/ai-steps#add-your-claude-key) under **Policies → Secrets**. The builder offers **Go to Secrets** if it's missing.
4. Choose **Simulate** to see the forecast, then **Run**.

**What you'll see:** Open **Agent fixes it** in the run to replay it. Typically Claude runs the tests, reads `slugify.py`, writes a fix, runs the tests again, and stops once the check passes, in a handful of turns. The step shows the tokens it used and what they cost. **Show the fix** runs the tests once more and prints the fixed file.

## Make it yours

1. Change **Set up project** to clone your code and install what it needs.
2. Edit the agent's **Goal**. Say what's wrong, what done looks like, and what not to touch, like `Fix the failing tests in proj. Don't change the tests or add new libraries.`
3. Set **Check that it worked** to your test command. The agent only counts as done when it passes.
4. Under **Rules for this step**, tick **No internet for this step** if the fix shouldn't need the internet, and **Ask a person first** to approve each command while you get to know it.
5. Keep the agent's own limits (**Turns** and **Spend on the model**) and the run's limits in step. The recipe allows up to 12 turns and $0.50 for the agent, inside a $0.75 run.

## What a run costs

These are the builder's own forecast for the recipe as it comes, with its limits, rounded. **Simulate** shows the same numbers for your version, and they change as you change the flow.

| | Typical | 1 in 10 runs | At most |
|---|---|---|---|
| **Sandbox time** | $0.0010 | $0.0016 | $0.86 |
| **Claude, on your key** | $0.06 | $0.13 | the run's spend limit |
| **How long it takes** | 82 seconds | about 2 minutes | 600 seconds |

A typical run uses $0.0010 of sandbox time, so about 970 runs cost $1, and every plan includes $5 of usage a month. Claude is billed by Anthropic to your own key, at their usual prices. The run counts it toward its spend limit, so it can't overspend, but we don't charge you for it. **At most** is the most a run could cost with these limits: it stops at $0.75 or 600 seconds, whichever comes first.

## Related

* [Tutorial 5: Add AI to a flow](https://www.quietrobot.ai/docs/playground/tutorials/ai-steps)
* [Fix until tests pass](https://www.quietrobot.ai/docs/playground/recipes/fix-until-pass)
* [AI steps and agents](https://www.quietrobot.ai/docs/playground/ai-steps)
* [Coding recipes](https://www.quietrobot.ai/docs/playground/recipes/coding)
* [All recipes](https://www.quietrobot.ai/docs/playground/recipes)
