You type a request, the agent writes two hundred lines, and half of it solves a problem you never asked about. You reword it, try again, and get a different wrong answer. The fix is not a magic phrase. This chapter gives you the four habits that make an agent build the thing you actually meant.
5.3.1Context beats clever wording
An agent is not a search box waiting for the right keyword. It writes what your words plus everything it can see add up to, so the highest-leverage move is handing it context, not hunting for a magic phrase. Anthropic's prompt engineering guidance says the same thing: be clear and direct, and give the model what it needs.
These two prompts ask for the same feature. Only one works.
Make the login better.
Our login is in src/auth/. Users sign in with email and
password against the users table. Add a "remember me"
checkbox that keeps them signed in for 30 days. Match
the session code already in that folder.
The rules file you set up earlier is context the agent reads on its own. A good prompt adds the rest: the files, the constraint, the definition of done. Keeping the right context in front of the agent is a skill of its own, and the next chapter is about the window it all has to fit inside.
5.3.2One task per prompt
Ask for three things in one message and the agent spreads its attention across all three, doing each one half-well. Give it one task, let it finish, then give the next. A small finished change is easier to check and easier to undo than one sprawling one.
Rule of thumb: If your prompt joins two jobs with an "and," it is two prompts.
5.3.3Show it an example
The fastest way to remove ambiguity is to show the agent what "done" looks like. Paste one concrete example: an input and the output you expect, or a sample of the shape you want. Something the agent can pattern-match against beats a paragraph describing the same thing.
Given { "email": "[email protected]" }, the endpoint should return
{ "id": 42, "email": "[email protected]" }. Match that shape.
5.3.4Ask for a plan before code
Before the agent writes anything, ask it to lay out a plan: which files it will touch, the approach, and what it is unsure about. Reading a five-line plan takes seconds; reviewing two hundred lines of wrong code takes an hour. If the plan is wrong, you caught the misunderstanding for free, then approve it and let it build.
5.3.5Keep the prompts that work
A prompt that produced good work is an asset, not a throwaway line. Save it as a prompt template: the instructions fixed at the top, one blank slot at the bottom where you drop today's specifics. Over a few weeks you build a small library of prompts your project already trusts, and you stop rewriting the same setup every session.
This template bakes all four habits into one block you paste before any feature:
Act as a senior engineer pairing with me. Before you
write any code, do these in order:
1. Restate the one task you think I am asking for. If it
is really two tasks, say so and stop.
2. Read the project's rules file and the files this
touches, then list what you found that matters.
3. Propose a short plan: the files you will change, the
approach, and anything you are unsure about.
4. Wait for my go-ahead. Only then write the code.
Also show me one example of the result you expect, an
input and the output, so we agree on done first.
The feature I want built:
Do this now: save the prompt above, paste it before your next feature, and make the agent plan before it writes a single line.