These are the 50 Claude prompts for coding I actually keep in a snippets file from shipping real code with Claude — organized into ten groups covering review, debugging, refactoring, tests, architecture, and more. Each group opens with a full copy-paste prompt and a note on why it works, followed by four variants you can adapt in seconds.
TL;DR:
• 50 prompts in 10 themed groups, from code review to DevOps.
• The recurring tricks: code inside XML tags, a senior-engineer role, the “why” behind the task, and an explicit “no invented problems” clause.
• Everything works in claude.ai, Claude Code, and the API — swap the bracketed placeholders and go.
How These Coding Prompts Are Built
Every prompt below leans on the Claude-specific techniques from our main Claude prompts library: code fenced in XML tags so instructions never blur into source, a role line that sets the quality bar, and a sentence of why — Claude writes different error handling once it knows the code runs in a payment path. For hard bugs, add a thinking trigger like “reason through the execution order before answering.” Over the Claude API, older models let you prefill the assistant’s reply to force raw code, but current models reject prefills — use structured outputs or an explicit “return only code, no preamble” instruction instead; in chat, “output only the code, starting with the first import” is the equivalent.
| Group | Prompts | Best model fit |
|---|---|---|
| Code review | 1–5 | Opus 4.8 / Sonnet 5 |
| Debugging | 6–10 | Opus 4.8 / Fable 5 |
| Refactoring | 11–15 | Sonnet 5 |
| New features & scaffolding | 16–20 | Sonnet 5 |
| Testing | 21–25 | Sonnet 5 |
| Documentation | 26–30 | Haiku 4.5 / Sonnet 5 |
| Architecture & design | 31–35 | Opus 4.8 / Fable 5 |
| Performance | 36–40 | Opus 4.8 |
| Learning & explanation | 41–45 | Sonnet 5 / Haiku 4.5 |
| SQL, shell & DevOps | 46–50 | Sonnet 5 |
The 50 Claude Prompts for Coding
Code review (prompts 1–5)
Prompt 1 — the review that finds real bugs:
You are a staff engineer reviewing a pull request.
<code>
[paste diff or files]
</code>
<context>
This code handles [what it does]. It runs [where / how often].
A bug here costs us [consequence].
</context>
Review for correctness bugs, unhandled edge cases, and concurrency
issues only — a linter handles style. Quote the exact line for each
finding and propose a fix. If you find nothing serious, say so
plainly. Do not invent problems to appear thorough.
The consequence line is the “give Claude the why” technique doing real work: reviews of payment-path code come back stricter than reviews of a throwaway script. The closing sentence suppresses filler findings.
- Review this code purely for security — injection, authz gaps, secrets handling. Rank findings by exploitability, worst first.
- Act as the most pedantic reviewer on our team. List everything you’d block this PR over, then everything you’d merely comment on. Two separate lists.
- Compare these two implementations of the same function. Which would you merge, and what would you steal from the loser? Be decisive.
- Review this diff as if you’ll be on call for it. What will page you at 3 a.m., and what logging is missing to debug it when it does?
Debugging (prompts 6–10)
Prompt 6 — the structured bug hunt:
Help me debug. Think through the execution flow step by step
before proposing anything.
<symptom>[exact error message or wrong behavior]</symptom>
<expected>[what should happen]</expected>
<code>[relevant code]</code>
<already_tried>[what you've ruled out]</already_tried>
Give me your top 3 hypotheses ranked by likelihood, and for each,
the single cheapest experiment that would confirm or kill it.
The <already_tried> tag saves round-trips, and asking for experiments instead of fixes keeps Claude honest when evidence is thin. Debugging is where the thinking trigger pays off most.
- Here’s a stack trace and the surrounding code. Walk the trace frame by frame and tell me the first frame where reality diverged from intent.
- This bug only happens in production, never locally. List the environmental differences that could cause it, ordered by how often each class bites in practice.
- Add targeted debug logging to this function — only at the points that would distinguish between my two suspected causes: [cause A] vs [cause B].
- I think this is a race condition. Map every shared piece of state in this code, who reads and writes it, and the interleaving that produces the bug.
Refactoring (prompts 11–15)
Prompt 11 — refactor without behavior change:
Refactor the code below for readability. Hard constraint: behavior
must be byte-for-byte identical — same outputs, same side effects,
same error cases. If any change risks altering behavior, list it
separately as "proposed but not applied" instead of applying it.
<code>[paste code]</code>
Output the refactored code first, then a bullet list of what
changed and why each change is safe.
Giving Claude a “proposed but not applied” escape hatch is the same anti-hallucination move as “say ‘not reported’ rather than guessing” — an explicit out beats a warning.
- This function is 180 lines. Split it into smaller functions with names so clear the original comments become unnecessary. Preserve the public signature.
- Modernize this code to idiomatic [language + version]. Flag any change that alters performance characteristics, not just syntax.
- Remove the duplication between these three functions by extracting shared logic — but stop and tell me if the duplication is coincidental rather than essential.
- Untangle this callback/promise chain into async-await. Keep error handling equivalent — show me a before/after table of every failure path.
New features and scaffolding (prompts 16–20)
Prompt 16 — the spec-first feature build:
You are pairing with me on a new feature.
<feature>[one-paragraph description]</feature>
<codebase_conventions>
[framework, patterns you follow, a representative existing file]
</codebase_conventions>
Before writing any code: restate the requirements as you understand
them, list your assumptions, and ask me up to 3 clarifying questions
if anything is ambiguous. Only after I confirm, write the code.
The restate-and-ask step is the cheapest quality gate there is, and one pasted example file teaches your conventions better than a paragraph describing them.
- Write a [language] CLI tool that [task]. Include argument parsing, helpful –help text, non-zero exit codes on failure, and no dependencies outside the standard library.
- Implement this API endpoint from the following request/response examples. Match the error format of the existing endpoint I’ve pasted below.
- Generate the boilerplate for [component/module] following the exact structure of the example file below. Only the domain logic should differ.
- Here’s my half-finished implementation and the spec. Complete it in my style — don’t rewrite what already works, and mark every line you added with a comment.
Testing (prompts 21–25)
Prompt 21 — tests that would have caught real bugs:
Write unit tests for the function below using [framework].
<code>[paste function]</code>
Prioritize: boundary values, empty/null inputs, error paths, and
one property that must always hold. Skip trivial happy-path tests
that only restate the implementation. Name each test after the
behavior it protects, not the method it calls.
- Here’s a bug that reached production, and the fix. Write the regression test that would have caught it, plus two tests for neighboring cases.
- Review my existing test file: which tests are testing the mock instead of the code? Which real behaviors have zero coverage? Don’t write code yet — just the gap list.
- Generate table-driven tests for this function covering the full input matrix: [dimensions]. Collapse equivalent cases and tell me why they’re equivalent.
- Write an integration test for this flow that uses real [database/queue] via test containers, with setup and teardown that leaves no state behind.
Documentation (prompts 26–30)
Prompt 26 — the README that answers real questions:
Write a README for the project below. Audience: a competent developer
seeing it for the first time who wants to run it locally within
10 minutes. Cover: what it does in two sentences, prerequisites with
versions, setup commands they can paste, and the three most likely
things to go wrong. Nothing else — no badges, no philosophy.
<project>[paste key files or describe the repo]</project>
- Add docstrings to every public function in this file. Document behavior, parameters, return values, and raised errors — never restate the function name in prose.
- Turn this Slack thread where we debugged a production incident into a runbook: symptoms, diagnosis steps, fix, and prevention.
- Write the API reference for these endpoints from the code below. Include one curl example per endpoint with realistic values, and document every error status actually returned.
- Explain what this module does in a comment block at the top — 5 lines max, aimed at the developer deciding whether they need to read further.
Architecture and design (prompts 31–35)
Prompt 31 — the design review with teeth:
You are a principal engineer who has seen this architecture fail
before. Think through failure modes carefully before responding.
<design>[paste your design doc or describe the system]</design>
<scale>[current load, expected growth, team size]</scale>
Give me: the 3 riskiest decisions in this design, what breaks first
under 10x load, and the simplification you'd make if you owned it.
Argue against the design, not for it — I have enough optimism.
“Argue against it” flips Claude out of agreeable-assistant mode, and the scale tag grounds the critique in your reality. This is Opus 4.8 or Fable 5 territory.
- I need to choose between [option A] and [option B] for [problem]. Build the comparison table for MY constraints below, then commit to a recommendation with your confidence level.
- Design the data model for [domain]. Start with the access patterns — list every query the app will run — and derive the schema from those, not from the nouns.
- Here’s our monolith’s module map. Propose the first single service to extract: lowest coupling, highest independent-deploy value, and the migration steps.
- Write an architecture decision record for the choice below: context, options considered, decision, and consequences — including the ugly ones we’re accepting.
Performance (prompts 36–40)
Prompt 36 — optimize from evidence, not vibes:
<code>[paste hot path]</code>
<profile>[paste profiler output or timings]</profile>
Using the profile as ground truth, identify the top bottleneck and
propose the smallest change that addresses it. Estimate the gain,
state the tradeoff, and refuse to micro-optimize anything the
profile shows is cheap.
- What’s the time and space complexity of this function? Then rewrite it one complexity class better, or prove to me it’s already optimal for this problem.
- This endpoint makes N+1 database queries. Find every one from the ORM code below and batch them — show the resulting SQL for each fix.
- Review this code for memory issues: leaks, unbounded growth, and allocations in loops. Rank by real-world impact given it processes [workload].
- Where in this request path should caching live, what’s the key, and what invalidates it? Reject caching entirely if the invalidation story is worse than the latency.
Learning and code explanation (prompts 41–45)
Prompt 41 — the layered explanation:
Explain this code in three passes:
1. One paragraph — what it does and why it exists.
2. A walkthrough of the flow, following one realistic input through.
3. The two most surprising or fragile parts, and why they're written
that way.
<code>[paste code]</code>
I know [languages you know] but not [what's new to you] — pitch
pass 2 accordingly.
- I’m a [language A] developer learning [language B]. Translate this snippet, then explain only the parts where B’s idiom genuinely differs from what I’d expect.
- Quiz me on the codebase file below: ask me 5 questions one at a time, wait for my answer, and correct my misconceptions before moving on.
- Explain [concept, e.g. database isolation levels] using only examples from the code I’ve pasted — no abstract definitions.
- Read this legacy file and reconstruct the requirements it was built to satisfy. List behaviors that look intentional vs accidental.
SQL, shell, and DevOps (prompts 46–50)
Prompt 46 — SQL with the schema in hand:
<schema>
[paste CREATE TABLE statements for relevant tables]
</schema>
Write a query that [question you're answering]. Use only columns
that exist in the schema above. Then explain the query plan risk:
which index it needs, and what happens on a table with 50M rows.
Pasting real DDL inside a schema tag eliminates the classic failure of invented column names — Claude grounds every reference in what you gave it.
- Explain what this shell one-liner does, flag anything destructive, then rewrite it as a readable script with error handling and a dry-run flag.
- Write the GitHub Actions workflow for this repo: lint, test, build on every PR; deploy on tag. Pin action versions and cache dependencies.
- Here’s my Dockerfile. Cut the image size and build time: multi-stage builds, layer ordering, and a .dockerignore — explain each saving.
- Diagnose this failing CI run from the log below. Separate the root cause from the cascade failures, and tell me the one line to fix first.
Common Mistakes When Prompting Claude for Code
- Pasting code without context. One sentence about what the code guards changes the entire review.
- Accepting the first draft. Follow up with “now attack your own solution — what breaks it?” The second pass catches what the first missed.
- Letting Claude guess your stack. “Python” and “Python 3.12 with FastAPI and SQLAlchemy 2” produce different code. Name versions or paste a representative file.
- One giant conversation for everything. Long chats accumulate stale constraints — start fresh per task, or move stable context into a Project.
If you’re running these inside an agentic workflow rather than a chat window, our Claude for coding workflow guide covers project setup, and the Claude Code vs Cursor comparison helps you pick the tool these prompts live in. Anthropic’s official prompt engineering docs are worth a read once these patterns feel natural.
FAQ
Which Claude model is best for coding prompts?
Sonnet 5 is the daily driver — near-Opus coding quality at a lower price and higher speed. Escalate to Opus 4.8 or Fable 5 for architecture reviews, hard debugging, and large-codebase reasoning; drop to Haiku 4.5 for quick explanations and doc generation.
Do these prompts work in Claude Code as well as claude.ai?
Yes. The techniques — XML tags, role framing, context, explicit constraints — carry over directly. In Claude Code you paste less because the agent reads files itself, so the prompts shift toward describing intent, constraints, and definition of done.
How much code can I paste into a Claude prompt?
Current Opus, Sonnet, and Fable models accept up to 1M tokens of context — roughly tens of thousands of lines of code. Haiku 4.5 takes 200K tokens. Practically, paste what’s relevant plus its immediate dependencies; precision beats volume.
How do I stop Claude from inventing APIs or column names?
Ground it: paste the real schema, the real function signatures, or the docs for the library version you use, inside XML tags. Then add an explicit out — tell it to write ‘not available in the provided code’ instead of guessing. Grounding plus an escape hatch eliminates most fabrication.
Should coding prompts ask Claude to think step by step?
For debugging, architecture, and concurrency questions, yes — a thinking trigger measurably improves the answer. For mechanical tasks like formatting, renaming, or doc generation, skip it; it adds latency without adding quality.
Next Steps
Save the five prompts you’ll use this week and adapt the placeholders to your stack once. When you’re ready to branch beyond code, the curated 100 best Claude prompts of 2026 covers every other category, and the prompts section is the index for it all.
