How to write prompts for AI coding agents

A simple template for prompting Claude Code, Codex or any coding agent: the goal, where to look, what done means and what not to touch. Real before-and-after examples and a copy-paste prompt.

By Shakir Sajad & Claude (AI by Anthropic) · 3 min read · Updated 2026-11-19

blueprint sketch illustration

Chapter three of the agentic coding learning path, and step 06 in detail.

What the agent already knows

Current agents are very good at reading code. Anthropic's best practices say Claude finds your file layout, conventions and test setup "usually faster than you could explain them".

So don't explain the code. Explain what isn't in it:

  • What you're trying to achieve, and for whom
  • A decision you already made
  • What "fixed" or "done" looks like
  • What it must not touch

Before and after

These two examples come straight from Anthropic's docs:

Instead ofTry
fix the login bugusers report login fails after the session times out. look at token refresh in src/auth/, write a failing test that reproduces it, then fix it
add a calendar widgetfollow the pattern in HotDogWidget.php and build a calendar widget that lets you pick a month and page between years. no new libraries

The second version of each names the file, the symptom, a check (the failing test) and a limit (no new libraries). That saves a round of corrections.

The brief template

Use this for any task bigger than a one-line fix:

Prompt
Goal: {what you want, in one sentence, and who it's for}

Context: {what the agent can't see: a decision, a user complaint, a deadline}

Where to look: {files or folders, e.g. @src/pages/Pricing.jsx}

Done when: {how we both know it works, e.g. the build passes and the page shows 3 plans on mobile}

Don't: {limits, e.g. no new libraries, don't touch the checkout code, don't push}

You won't need every line every time. "Done when" is the one people skip and the one that matters most. More on that in make the agent prove it.

Hand it over, don't describe it

If you have the thing, give it:

  • A file: type @ and the path, and Claude Code includes the file in your message.
  • A screenshot: paste the design or the error straight into the prompt.
  • An error log: paste the exact text. Never "it shows some error".

When I fix the layout of this site, I paste a phone screenshot and say what looks wrong. That beats three paragraphs of description.

Say how big you want it

Agents tend to build the smallest thing that satisfies the request. If you want the full version, say so. Anthropic's docs suggest the phrase be ambitious:

Prompt
build the settings page from the mockup. be ambitious: empty and error states, the save flow wired up, keyboard navigation, not just the layout

The reverse works too: "smallest change that fixes it, nothing else".

Not sure what you want? Let it interview you

When the idea is still fuzzy, don't guess. Ask the agent to ask you:

Prompt
I want to add {feature} but haven't thought it through yet. Interview me until you could write the spec, then write it to SPEC.md.

Then start a fresh session and build from SPEC.md. More in plan before you code.

What to stop doing

  • "Think step by step", "be thorough". The docs say these are ordinary text, not magic words. The effort setting controls how hard it thinks.
  • ALL CAPS and IMPORTANT. Current models follow plain words. If a rule must never break, it belongs in settings, not in shouting.
  • The third correction. After two failed fixes, run /clear and write one better prompt. A conversation full of failed attempts drags the next one down.

What's next

Save the prompts that work: build a prompt library. Then set up project memory, so you stop repeating yourself.

Do this now

  1. Rewrite your last vague prompt Add the goal, the file, what done looks like and one limit. (10 min)
  2. Try the brief template on a small task Copy the template below, fill the blanks, send it. (15 min)
  3. Hand over, don't describe Next time, @ the file or paste the screenshot instead of explaining it. (5 min)
  4. Use 'interview me' on a fuzzy idea Let the agent ask you questions until it can write the spec. (15 min)
  5. Save the best prompt you wrote today Start a prompt library. See the prompt library guide. (5 min)

Frequently asked questions

What makes a good prompt for a coding agent?

It tells the agent what it can't find in the code: the goal, where to look, what 'done' means and any limits. Name the file, describe the symptom and say how to check it.

Do phrases like 'think step by step' still help?

Not much. Anthropic's Claude Code docs say those are ordinary prompt text, not keywords; the effort setting controls how hard Claude thinks. One phrase that still helps is 'be ambitious', when you want the fuller version of a feature.

Should prompts be long?

As long as needed to say what the agent can't see, and no longer. A short, specific prompt beats a long, vague one.

What if the agent gets it wrong twice?

Stop correcting. Start a fresh session and write one better prompt that includes what you learned. Claude Code's docs recommend exactly this after two failed corrections.

Sources