How to Write Prompts for Coding Agents
Claude Code, Cursor and the rest are not autocomplete. Give them context, hard constraints and a way to check their work, then let them iterate.
A coding agent runs a loop: it reads, plans, edits, checks, and repeats. That means your prompt is not a one-shot request, it is the brief for an autonomous run. The agents that succeed get four things from you: context about the codebase, constraints on what they may do, a way to verify the result, and room to iterate.
Give it context, not a blank slate
Most agent failures are missing-context failures. Point it at the relevant files, name the conventions, and let your memory file (CLAUDE.md or AGENTS.md) carry the standing rules so you do not repeat them every time.
Add rate limiting to the login route.
Context:
- The route is in src/routes/auth.ts.
- We use the existing limiter helper in src/lib/limit.ts.
- Follow the ApiResponse<T> envelope like the other routes.
Do not add a new dependency.Make success checkable
The single biggest upgrade to agent output is giving it a test or command to run. When the agent can verify its own work, it self-corrects instead of handing you a broken diff. Tell it the command and tell it not to claim done until it passes.
Ask for a plan first on big tasks
For anything that spans several files, have the agent propose a plan before it writes code. You catch a wrong approach in ten seconds of reading instead of after a sprawling diff. Approve or correct the plan, then let it execute.
- Explore: have it find the relevant files and report what it sees.
- Plan: have it list the changes it intends to make.
- Code: let it make the edits once the plan looks right.
- Verify: have it run tests or a build and report the result.
Iterate in tight loops
Do not write one giant prompt and hope. Give a scoped task, review the diff, then steer with a short follow-up. Small, verifiable steps keep the agent on track and keep you in control of the direction.
| Weak prompt | Strong prompt |
|---|---|
| Improve the auth code. | Extract the token check into a guard, no behavior change, run tests. |
| Fix the bug. | The login returns 500 on empty body; add validation and a test for it. |
| Make it faster. | Profile the list endpoint, then cache the user lookup if it is the hot path. |
26:11The pattern is the same across tools: context in, constraints set, a check defined, iterate in small steps. A good build, with a memory file and a test command wired up, does most of this for you on every run.
0 Comments
Loading discussion...