DEV Community

Zac
Zac

Posted on

The Claude Code prompt structure that consistently works

After hundreds of sessions, one prompt structure produces the best results consistently. It's not magic — it just gives Claude everything it needs.

The structure

TASK: [one sentence — what needs to exist after this is done]

CONTEXT: [what exists now, what's relevant, what I've already tried]

SCOPE: [which files are in play, what must not change]

DONE WHEN: [specific, checkable criteria — tests pass, behavior works, types clean]

CONSTRAINTS: [hard rules — don't change the API, use the existing pattern, no new dependencies]
Enter fullscreen mode Exit fullscreen mode

Why each section matters

TASK in one sentence forces you to clarify what you actually want before you start. Vague tasks produce vague results.

CONTEXT prevents Claude from re-reading the whole codebase. You're giving it the relevant starting state explicitly.

SCOPE is the single most effective quality improvement. Claude changes what it's told to change. Without scope, it decides scope, and its judgment differs from yours.

DONE WHEN replaces "looks good" with a checklist. Claude can verify against it.

CONSTRAINTS are the no-goes. Things that look improvable but must not be changed.

The short version

For smaller tasks I collapse this to two sentences:

"[What to do] in [which files]. Done when [criterion]."

Example: "Add null check before the database call in src/users.ts line 47. Done when tsc passes and the function returns early with a 400 if userId is null."

That's the minimum. Task + scope + done criterion. Skipping any of the three is where sessions go sideways.

Top comments (0)