How to Write Claude Code Prompts

Step-by-step guide to writing Claude Code prompts that produce specific, actionable output. Pattern + worked examples + common mistakes + how to debug a bad response.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

Writing a good Claude Code prompt is a craft skill — not a trick. The same five elements appear in every prompt that works. Once you internalise them, you can write a usable prompt in 60 seconds.

The five elements

  1. Role — who Claude is for this task
  2. Task — what to do, specifically
  3. Constraints — what NOT to do (often the most important part)
  4. Output shape — exact format of the response
  5. Budget — limits on length, count, or scope

Worked example 1: from vague to good

Vague (bad):

Review this code and tell me what's wrong with it.

What you get: Five paragraphs of prose covering "consider adding type hints", "you might want to extract that into a function", "this could be more pythonic". Nothing you can ship.

Good:

Review the diff in this branch as a skeptical senior engineer.

For each issue:
- file:line
- severity 1 (nit) to 5 (production-breaking)
- category: correctness | security | performance | readability | testing
- one-line minimal fix

Output as a markdown table sorted by severity descending.

Constraints:
- Max 12 issues — pick the highest-value
- Do NOT propose new features
- Do NOT recommend refactors larger than 10 lines
- If the diff is fine, say so in one sentence and stop

Read: git diff main...HEAD

What you get: A 12-row table you can work through line by line.

Worked example 2: scope creep prevention

Vague (bad):

Refactor src/api/users.py to be cleaner.

Failure mode: Claude renames variables, reformats imports, splits a 30-line function into four files, and updates 12 unrelated tests. Now your diff is unreviewable.

Good:

In src/api/users.py, the function create_user() has cyclomatic complexity
12. Reduce it to under 10.

Constraints:
- No renames (functions, variables, anything)
- No formatting changes (no reordering imports, no quote style changes)
- No new files
- No new dependencies
- No changes to files other than src/api/users.py
- Preserve exact behaviour — same inputs produce same outputs/raises

Approach order:
1. Early returns / guard clauses
2. Extract one helper function (in same file) for the validation block
3. Only if 1+2 doesn't suffice, split into multiple functions

After: run `pytest tests/test_users.py -x` and confirm green.

Show me the diff before applying.

Worked example 3: getting a planning answer (not implementation)

Vague (bad):

I want to add real-time notifications to this app. Build it.

Failure mode: Claude builds the wrong thing. Or the right thing on the wrong stack. Or both.

Good:

I want to add real-time notifications to this app. Before any code,
propose 3 approaches:

1. Polling — clients poll an endpoint every N seconds
2. Server-Sent Events
3. WebSockets

For each:
- 3-sentence description of how it works in THIS codebase
- Files that would change (list with file:line ranges)
- Infrastructure changes needed (Redis? a queue? a sticky-session LB?)
- The biggest risk
- A rough estimate of work in T-shirt sizes (S/M/L)

Then recommend one with a one-paragraph justification.

Do NOT write code yet. Wait for "go with approach N".

The negative-constraint catalogue

Most "prompt engineering" advice focuses on positive instructions. The bigger lift in Claude Code is negative constraints — Claude is biased toward doing more than asked. Add these as needed:

Failure modeConstraint that prevents it
Sneaky reformatting"No formatting changes. No import reordering. No quote-style changes."
"Helpful" renames"No renames. Preserve all existing function/variable/file names."
Suggesting refactors during a bugfix"Fix the bug only. No 'while I'm here' refactors."
Adding dependencies"No new dependencies. Use only what's already in package.json/pyproject.toml."
Splitting into too many files"All changes in [FILE]. No new files."
Skipping tests"After changes, run [TEST COMMAND]. Confirm green before reporting done."
Implementing before planning"Output the plan. Do NOT write code. Wait for go-ahead."
Padding with low-value findings"Max N findings. Pick the highest-value."

Output shapes: pick one and demand it

Debugging a bad response

When the response isn't what you wanted, ask: which of the five elements was missing or weak?

The "save it when it works three times" rule

When a prompt produces the right output three sessions in a row without manual edits, it's ready to live in CLAUDE.md. Below three uses, it's still a draft — keep refining the bracketed slots.

Start from working templates

You don't have to invent these prompts from scratch. The Claude Code Power Prompts PDF has 30 production-tested prompts across six workflows. Each has been through the three-session test. Paste them into CLAUDE.md and they become part of your standard kit. £3 tonight (first 10 buyers), £5 standard, instant PDF after Stripe checkout.

Grab the 30-prompt PDF →

Frequently asked questions

What's the difference between a Claude Code prompt and a regular Claude prompt?
A Claude Code prompt assumes Claude can read files, run shell commands, edit code, and iterate. Regular Claude prompts have to include the code inline. Claude Code prompts can say 'read src/api/users.py, find the bug, run the tests after fixing it' — three actions in one prompt.
Why does Claude Code sometimes do too much (refactor, rename, reformat)?
Because the prompt didn't bound the scope. Claude is biased toward 'while I'm in here, let me also...' improvements. Counter with explicit negative constraints: 'do not refactor', 'no renames', 'no formatting changes', 'do not touch files outside [DIR]'.
How do I know when my prompt is good enough to save in CLAUDE.md?
When you've used it three times and it produced the right output every time without manual tweaks. If it needs adjustment per use, it's still a draft — refine the bracketed slots until the template handles every variation you encounter.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript