10 prompts that actually improve code quality

A coding agent will happily hand you confident, plausible, wrong code. The fix isn't a smarter model — it's a better instruction. Every prompt below is a reusable "move" you can paste into Claude Code, Cursor or Codex to force method, guardrails and evidence. Steal them.

There's one meta-idea under all ten: good prompting for agents = method + guardrails + evidence. Tell it how to proceed, what not to do, and what proof to show. Everything below is a variation on those three. Stack two or three per task and the quality jump is immediate.

1. Plan-then-execute

The single highest-ROI habit. Separating thinking from doing stops the agent sprinting in the wrong direction.

"Give me a plan first — files you'll touch, approach, tests, and steps. Write no code until I approve the plan."

2. Reproduce-first

No fix is real until the bug is reproduced. This kills the "I think this should fix it" guess.

"Reproduce this with the smallest possible test or command before proposing any fix. If you can't reproduce it, tell me what you need and stop."

3. Root-cause only

Bans the band-aid. Agents love wrapping a symptom in a try/catch and calling it done.

"Find the root cause. No try/catch, retries or if (x) return that hides the symptom. Quote the exact lines responsible and explain why they're the cause."

4. Test-first (red/green)

A spec the agent can't argue with. A failing test is an unambiguous target; "make it pass" is a clear finish line.

"Write a failing test that captures this behavior first. Show it failing, then implement until it's green. Don't change the test to make it pass."

want the whole library?

100 AI Prompts for Developers

A categorized, paste-ready library for building, debugging, reviewing and shipping — the impulse-priced way to stop re-typing your best prompts. Works with any agent.

Get the prompts

5. Blast-radius limit

Stops the 20-file sprawl that turns a one-line fix into an unreviewable diff.

"Only edit files under src/payments/. If you think you need to touch anything outside it, stop and ask first."

6. Grep, don't guess

The cure for hallucinated APIs. Force the agent to verify a symbol exists before it leans on it.

"Before using any function or type, search the repo to confirm it exists and check its real signature. Don't invent APIs."

7. Smallest diff

Reviewability is a quality attribute. A minimal diff is easier to read, test and trust.

"Make the smallest change that fully solves this. Touch only relevant lines — no opportunistic reformatting or unrelated refactors."

8. Maker / checker

A second pass catches the first pass's mistakes. The cheapest code review you'll ever run.

"Now review your own change as a hostile senior reviewer. List everything wrong with it — edge cases, naming, tests, security — then fix the real issues."

9. Measure-then-optimize

Evidence over intuition. Most "performance fixes" optimize the wrong thing because nobody measured.

"Measure the baseline and name the actual bottleneck with numbers before changing anything. Then optimize only that, and show the before/after."

10. Stuck protocol

Fail loudly, not silently. This prevents the slow-motion disaster of an agent guessing its way deeper into a hole.

"If you're unsure or still stuck after two attempts, stop and ask me one specific question instead of guessing."

Stack them like a pro

The patterns get powerful when combined. A few field-tested recipes:

  • New feature: plan-then-execute + blast-radius + test-first + smallest-diff.
  • Bug fix: reproduce-first + root-cause-only + test-first + smallest-diff.
  • Refactor: test-first (to characterize current behavior) + smallest-diff + maker/checker.
  • Performance: measure-then-optimize + a spec-anchored target metric + smallest-diff.

Two ways to make this permanent: bake the defaults into your CLAUDE.md / .cursorrules file so they apply to every request automatically, or save the full versions as slash commands you can fire in one word. Either way, you stop relying on remembering to be a good prompter — and start operating the agent like a senior engineer who already knows the rules.