The refinement loop
- Clear targetexamples, test cases, a screenshot, the exact error
- Runnable checktests, build, linter, screenshot diff
- Claude attemptsdoes the work, then runs the check
- Read the resultpass → done; fail → specific fix
Each failure feeds a specific correction back in — not the same request, louder
Give Claude a way to check its own work
The Claude Code best-practices guide puts this first: Claude stops when the work looks done, and without a check it can run, looking done is the only signal available. Give it something that produces a pass or a fail — a test suite, a build exit code, a linter, a script that diffs output against a fixture, or a screenshot compared against a design — and Claude can do the work, run the check, read the result and iterate until it passes.
| Instead of | Refine to |
|---|---|
| “implement a function that validates email addresses” | “write validateEmail. user@example.com is valid, invalid is not, user@.com is not. Run the tests after implementing.” |
| “make the dashboard look better” | “[screenshot] implement this design, screenshot the result, list the differences and fix them” |
| “the build is failing” | “the build fails with this error: [error]. Fix the root cause, don’t suppress it, and confirm the build passes.” |
Ask for evidence, not assertions. The guide recommends having Claude show the test output, the command it ran and what it returned, or a screenshot of the result — reviewing evidence is faster than re-running the check yourself.
Tests first, then code
Tests are the most precise way to say what “correct” means. Writing them before the implementation turns an ambiguous request into a target that either passes or doesn’t, and every failure tells Claude exactly what is still wrong. The best-practices guide’s example prompt for a bug asks Claude to write a failing test that reproduces the issue, then fix it. For a larger change, it suggests having one Claude session write the tests and another write code to pass them.
Show, don’t describe: concrete examples
When Claude keeps misreading a transformation or format, more adjectives rarely help. A few concrete input-and-output pairs show the pattern directly, including the edge cases a description glosses over. Anthropic’s prompting guidance recommends examples that are relevant, diverse enough to cover edge cases, and clearly marked off from the instructions (few-shot prompting is covered in depth in 4.2).
Refining a request: description versus examples
Vague, repeated more firmlytext
Normalise the order dates so they
are consistent. Make sure they're
all in the same format!! Handle the
weird ones properly this time.Concrete input → output pairstext
Convert order_date to ISO 8601.
Examples:
"03/04/2025" (UK store) -> "2025-04-03"
"Apr 3 2025" -> "2025-04-03"
"" -> null, log it
Add these as test cases, then run
the tests.Let Claude ask before it builds
Some refinement should happen before any code exists. For larger features the best-practices guide suggests asking Claude to interview you in detail — about implementation, UI, edge cases, concerns and trade-offs — until everything is covered, then write a spec to a file. The interview surfaces questions you hadn’t considered, and a fresh session then implements against the finished spec with clean context.
Correcting course without drowning the context
Tight feedback loops beat long ones. Press Esc to stop Claude mid-action while keeping its context, so you can redirect. Press Esc twice or run /rewind to restore an earlier checkpoint of the conversation, the code or both. Ask Claude to undo a change. And when a line of attack has clearly failed, cut your losses.
Output isn’t right — what next?
- Format or pattern misreadGive examplesinput → output pairs, as tests
- Behaviour wrongGive a failing testor the exact error text
- Heading the wrong way
Escor/rewindredirect before it goes further - Two corrections failed
/clearand re-promptfold in what you learned
The documentation is specific about that last branch: if you have corrected Claude more than twice on the same issue in one session, the context is cluttered with failed approaches. Run /clear and start again with a better prompt that includes what you learned; a clean session with a better prompt almost always outperforms a long one with accumulated corrections.
How you batch feedback matters too. When several problems are connected — a schema change that breaks a query that breaks a report — describe them together in one message so the fix is designed as a whole. When problems are independent, fixing and verifying them one at a time keeps each change small and each failure easy to trace.
Traps the wrong answers are built from
| Tempting but wrong | Do this instead |
|---|---|
| Repeating a vague instruction more forcefully | Replace it with concrete input → output examples or a failing test. |
| Asking for a change with no way to check it | Give Claude tests, a build or a screenshot to verify against, and ask for the evidence. |
| Saying “it’s broken” or “the build fails” | Paste the exact error or failing assertion and ask for the root cause. |
| Correcting the same issue again and again in one long session | After two failed corrections, /clear and restart with a better prompt. |
| Letting Claude special-case the test inputs | Ask for a general solution and for Claude to flag tests it thinks are wrong. |
You should now be able to
- Give Claude a runnable check and ask for evidence of the result.
- Use a test-first loop, feeding failing tests back as feedback.
- Replace ambiguous descriptions with concrete input and output examples.
- Use an interview to surface requirements before implementing a larger feature.
- Choose between
Esc,/rewindand/clearto course-correct. - Decide whether related issues should be fixed together or one at a time.