Prompt Engineering for Coding Agents
Write prompts that coding agents act on: clear goals, the right context, output contracts, examples, structured thinking, shorter answers and a tiny eval set.
8 chapters · about 21 min · free
Who it is for: Developers who use Cursor, Claude Code or ChatGPT for code and want fewer re-tries, more predictable output and lower token costs.
What you will learn
- Write a task prompt with goal, context, constraints and a done-when check
- Choose which files and facts to include, and which to leave out
- Specify an output contract the agent follows (format, length, structure)
- Use one or two examples to teach a format without over-fitting
- Ask for structured reasoning (pre-mortem, tradeoffs, six hats) when a decision needs it
- Cut answer length and token cost without losing accuracy
- Build a 10-case eval set to compare prompt versions
- Recognise when a prompt should become a reusable skill
Before you start
- Regular use of an AI coding assistant
- No ML background needed
Chapters
- 01The anatomy of an actionable prompt3 min
- 02Context: what to include and what to leave out2 min
- 03Output contracts: get the shape you need2 min
- 04Examples that teach (without over-fitting)3 min
- 05Structured thinking prompts for decisions2 min
- 06Shorter answers, lower token cost3 min
- 07A tiny eval set: test prompts like code3 min
- 08When a prompt should become a skill3 min
Frequently asked questions
What is prompt engineering for coding agents?
Writing task instructions that an agent such as Cursor or Claude Code can act on without guessing: a clear outcome, the context only you know, constraints, an output contract and a check for when the work is done.
What is the single most useful thing to add to a coding prompt?
A 'done when' check the agent can run itself, such as a test command or a script with an expected result. It turns 'I think this works' into verified work.
Should I paste whole files into the prompt?
Usually not. Agents can open files. Give pointers to where to start, plus facts and decisions that are not in the repo. Paste errors and commands verbatim.
How do I get JSON back reliably?
Give an explicit schema with types, say what to return when there is nothing to report, and when you call the model from code, use your provider's structured output or JSON schema feature so the shape is enforced.
How many examples should a prompt include?
One or two: a typical case and an edge case that differ on the surface. More examples increase cost and the risk that the model copies them too literally.
How can I reduce token costs without hurting quality?
Ask for the answer first with numeric length limits, keep code and errors verbatim, trim rules files that load every turn, and measure with a token counter and a small eval set before and after.
What is an eval set and do I need one?
A small list of real inputs with pass/fail checks that you re-run after changing a prompt or model. Ten cases are enough to catch most regressions in a prompt you rely on.
When should a prompt become a skill?
When you have pasted it several times, its shape is stable, teammates need it, it needs supporting files, or it should trigger automatically on matching requests.
Do these techniques work with ChatGPT and other chat tools?
Yes. The structure (goal, context, constraints, output, done-when) applies to any model. Agent-specific parts, such as self-checking with commands, need a tool that can run them.






