Prompting

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.

Setuproll Team9 min read2026-06-20

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.

prompt.txt
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.
State the goal and the boundaries together
An agent will happily refactor half your app if you let it. Pair every task with explicit limits: which files it may touch, what it must not change, and whether it may add packages.

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.

zsh - agent run
$claude "add the rate limiter; run npm test before finishing"
● Plan: edit auth.ts, reuse limit.ts, add 2 tests
● Editing... 2 files changed
↳ npm test
✓ 38 passed
✓ done: rate limiter added, tests green
$

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.

  1. Explore: have it find the relevant files and report what it sees.
  2. Plan: have it list the changes it intends to make.
  3. Code: let it make the edits once the plan looks right.
  4. 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 promptStrong 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.
Review every diff
Autonomy is not a reason to stop reading the output. The agent can pass tests and still pick a design you would not. Treat its diff like a junior engineer's pull request.
Claude Code DocumentationHow the explore, plan, code, verify loop works, plus memory, hooks and subagents.code.claude.com
Claude Code Best Practices - The Ultimate Guide26:11
Claude Code Best Practices - The Ultimate Guide· IndyDevDan

The 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

Sign in to post

Loading discussion...