In this categoryClaude Code ยท 45
Claude CodeIntermediate

How to Give a Coding Agent a Clear Stop Condition

Define done up front so an agent finishes the task instead of looping, over-editing, or asking what to do next.

7 minIntermediate

A coding agent works best when it knows exactly when to stop. Without a stop condition it tends to keep polishing, expand the scope on its own, or pause to ask what to do next. Stating the finish line in your first message fixes all three. This guide shows how to write one.

What you need

  • An agent session open in your project
  • A single task you want done
  • About 5 minutes

Step 1: Name the finish line first

Open your request with the condition that means done. The agent reads it as the goal and works backward from it instead of guessing how far to go.

Agent - scoped request
You
Done means: the login form rejects empty emails and the existing tests still pass. Do not touch styling.
Agent
Understood. I'll add empty-email validation, run the test suite, and stop once it is green without changing any styles.
The stop condition leads the request.

Step 2: Make done verifiable

A good stop condition is something the agent can check itself. Tie it to a command that passes or fails so there is no ambiguity about whether the work is finished.

prompt
Finish when `npm test -- auth` passes and `npm run lint` reports no errors. Then summarize the diff and stop.

Step 3: Fence off the scope

List what is out of bounds. An explicit do-not list stops the agent from wandering into unrelated files while it chases the goal.

Three lines beat a paragraph
A request shaped as goal, check, and out-of-scope is easier for an agent to follow than prose. Keep each to one line.

Result: the agent runs to a defined finish, verifies it, and stops, instead of looping or quietly growing the change.

Watch related tutorials

Free weekly email

New guides in your inbox

Fresh step-by-step how-to guides as we publish them. One email a week, no more.

Tags
#agents#prompting#workflow#scope#tips