Claude Code prompts: the patterns that get working code

TL;DR: Good Claude Code prompts tell Claude what it can't see in the repo: the symptom, the files, the approach you prefer and what done means. Give it a test or command to run so it can check its own work, plan first for big changes, keep CLAUDE.md short, and move repeated procedures into skills.

How Claude Code reads your prompt

Claude Code reads your repository before it acts, and it is good at it. Anthropic's best-practices page says current models find your file layout, conventions, test framework and existing patterns, usually faster than you could explain them. So the job of a Claude Code prompt is not to describe your codebase. It is to supply what was never in the code.

That is a short list: the symptom you saw, where you think the problem is, which of two reasonable approaches you prefer, how big a change you want, and how to tell when it is done. Anthropic's own test for whether to write something down is two questions: could Claude find this by reading the code, and would it actually go and look? If both answers are yes, leave it out.

The docs also list the usual reasons a session goes wrong. Claude built something different from what you meant (missing information), said it was done when it wasn't (no way to check), or did something that must never happen in the repo (a rule a prompt can't guarantee). Each section below fixes one of those.

Write a specific task prompt

Name the file, describe the symptom, and say what fixed looks like. It usually saves a round of corrections.

Vague Claude Code prompts and specific rewrites
Instead ofTry
fix the checkout bugcheckout fails with a 500 when the cart has a discounted item and a gift card. look at applyDiscounts in src/checkout/. write a failing test that reproduces it, then fix it
add paginationadd cursor pagination to GET /orders, following the pattern in src/api/customers.ts. no new dependencies. update the OpenAPI spec
clean up this modulesplit src/billing/invoice.ts into calculation and rendering. behavior must not change: the existing tests in tests/billing must pass unchanged
why is this slowthe /reports page takes 8 seconds to load in dev. profile the request, find the slowest query, and tell me the cause before changing anything

Hand over what you already have instead of describing it. Type @ and a path to include a file in your message, paste a screenshot of the error or the design, or pipe output in from your shell.

Pipe output straight into Claude Code
cat error.log | claude -p "explain what is failing here and which file is the most likely cause"

Scope is the other thing only you know. Anthropic notes that Claude tends to read a request conservatively and build the smallest thing that satisfies it. When you want the fuller version, say so. The docs suggest the phrase "be ambitious" for this.

Ask for the full scope explicitly
build the account settings page from the mockup in @designs/settings.png. be ambitious: empty and error states, the save flow wired to the API, keyboard navigation and loading states, not just the layout. follow the form patterns in src/components/forms/.

Plan first for anything big

For changes you want to review before they touch disk, use plan mode. Claude reads files and proposes a plan, but makes no edits until you approve. Press Shift+Tab in a session until the status bar shows plan mode, or start with claude --permission-mode plan.

When you don't yet know what you want, let Claude interview you first. This pattern comes straight from Anthropic's docs: it asks about the parts you haven't pinned down until the answers add up to a spec.

Interview me, then write the spec
I want to add [feature, for example: rate limiting to the public API] but haven't thought it through yet. Interview me until you could write the spec. Ask about scope, edge cases and what is out of scope. Then write it to SPEC.md.

Once SPEC.md exists, start a fresh session to build from it, so the build begins with a clean context and a written definition of done. The same file becomes the checklist for review later.

Plan from the spec before writing code
read SPEC.md. propose an implementation plan: the files you will change, the order, and the tests you will add for each requirement. flag any requirement that is ambiguous. don't write code until I approve the plan.

Give Claude a check to run

This is the single biggest improvement to most Claude Code prompts. Claude stops when the work looks done. If it has nothing to run that says pass or fail, "looks done" is all it has, and you become the test suite. Give it a test file, a build, a linter, a script that diffs output against a fixture, or a screenshot to compare with the mockup.

Test first, fix, and show the evidence
fix the date parsing bug in src/utils/dates.ts. first write a failing test in tests/dates.test.ts that reproduces it with the input "2026-03-29T02:30" in Europe/London. then fix it. run the dates tests and the typecheck after, and keep going until both pass. show me the commands you ran and their output.

The last line matters. Anthropic advises asking for evidence (the command and its output, or the screenshot), because "all tests pass" on its own tells you little, and reading the output is faster than rerunning it.

Write the solution you want, not just the green tick. Anthropic's general prompting guide warns that Claude can focus too hard on passing tests, and suggests saying so:

Keep the fix honest
implement a general solution that works for all valid inputs, not just the test cases. don't hard-code values or special-case the tests. if a test looks wrong, tell me instead of working around it.

Review the change

Ask for a review from something that didn't write the code. In the terminal, the bundled /code-review skill reviews the diff in a fresh subagent that never saw your conversation. To review against your plan rather than hunt for bugs in general, write the prompt yourself:

Review against the spec
use a subagent to review the diff on this branch against SPEC.md. check every requirement is implemented and every listed edge case has a test. report gaps that affect correctness and skip style.

Anthropic's docs make a point of the words "skip style": a reviewer asked to find problems will always find something, and fixing every nitpick leaves you with extra abstraction and tests for cases that can't happen.

Write the PR description
summarize what changed on this branch for a PR description: what and why in two sentences, then the main changes as a list, then anything a reviewer should look at closely and why. don't list every file.

CLAUDE.md: the prompt Claude reads every session

Claude Code loads CLAUDE.md into every session, so every line in it costs a little attention on every task, relevant or not. Anthropic recommends keeping it to what Claude can't work out from the code, and the memory docs suggest staying under 200 lines per file.

  • How to confirm work: the exact test, typecheck and lint commands, and how to run a single test file.
  • Places where the code misleads: an old pattern that is everywhere but must not be copied, a directory that looks unused but isn't.
  • Decisions that aren't in the repo: which error helper the team chose, how deploys work.
  • Anything you have corrected twice.
A short CLAUDE.md that passes the test
# Commands
- Install: [pnpm install]
- Run one test file: [pnpm vitest run path/to/file.test.ts]
- Typecheck: [pnpm tsc --noEmit]
- Lint: [pnpm lint]

# Conventions
- [Use the error helpers in src/lib/errors.ts, never throw raw strings]
- [src/legacy/ is still live, but don't copy its patterns into new code]

# Gotchas
- [Integration tests need DATABASE_URL set, see .env.example]

Run /init to generate a first version from your codebase, then mostly delete. Personal preferences go in CLAUDE.local.md, which you add to .gitignore. A rule that only matters in one part of the code can go in .claude/rules/ with a paths: filter, so it loads only when Claude works on those files.

If Claude keeps missing a line in CLAUDE.md, capital letters won't fix it. Anthropic's advice: either the file is too long and the line gets lost, or it's a rule that can't have exceptions. Rules like that belong in a hook or a permission deny rule, which Claude Code enforces every time, rather than in text Claude reads.

Skills: prompts you save and reuse

When you keep pasting the same instructions or checklist, make it a skill. A skill is a SKILL.md file in .claude/skills/<name>/ (or ~/.claude/skills/ for all your projects). The folder name becomes a command you can type, like /fix-issue, and the description tells Claude when to load it on its own. Custom slash commands have been merged into skills, and old .claude/commands/ files keep working.

Skills are lighter than CLAUDE.md for procedures: for a skill it can start on its own, Claude sees the name and description in every session but reads the full file only when the task calls for it. For anything with side effects, add disable-model-invocation: true so it only runs when you type the command. Text after the command arrives in $ARGUMENTS.

Skill file: .claude/skills/fix-issue/SKILL.md
---
name: fix-issue
description: Fix a GitHub issue by number, with a failing test first.
disable-model-invocation: true
---

Fix GitHub issue $ARGUMENTS.

1. Read the issue with `gh issue view $ARGUMENTS`, including comments.
2. Write a failing test that reproduces the problem.
3. Make the smallest change that fixes it.
4. Run [your test command] and [your typecheck command]. Keep going until both pass.
5. Commit with a message that references the issue. Don't push.
6. Reply with the test you added, the commands you ran and their output.

Typing /fix-issue 482 now runs the whole procedure. The steps carry the same habits as the prompts above: a failing test, a small change, a check, and evidence.

Steer the session

Watch the first minute. Anthropic's docs list a few controls worth knowing by heart.

  • Esc stops Claude mid-action and keeps the work so far, so you can redirect.
  • /rewind (or Esc twice on an empty prompt) rolls the code, the conversation or both back to an earlier point. Checkpoints track edits made with Claude's file tools, not changes made by shell commands, so keep using git.
  • /clear between unrelated tasks. After two failed corrections, Anthropic suggests clearing and writing one better prompt that folds in what you learned, rather than a third correction.
  • /effort sets how hard Claude thinks. Raise it for tricky bugs in code you didn't write; lower it for quick back-and-forth. For one hard question, put ultrathink in that prompt.

Prompting habits you can drop

Anthropic's best-practices page ends with a list of advice that current models have made unnecessary. These are the ones that touch how you write prompts.

Old Claude Code prompting advice and what changed
Old habitWhy you can drop it
IMPORTANT or ALL CAPS on lines Claude missesCurrent models follow a plainly worded line, and emphasis mostly makes them over-apply the rule. Shorten the file or use a hook.
"think hard", "think harder", "be thorough"These are ordinary text that nudges Claude within its effort setting. Effort is the real control; ultrathink still works for one turn.
"keep going, don't be lazy, loop until done"Current models carry an agreed task through, and lines like these cause over-work. Give it a check to pass instead.
Describing your architecture and file layout in CLAUDE.mdClaude reads the repo itself. Write down only what isn't in there.
Delegating to a subagent for a better answerDelegation doesn't improve the answer. A fresh reviewer does, because it hasn't seen your reasoning.

The common thread: give Claude Code information and checks, not pressure. The same thinking applies to any model, and our Claude prompting guide covers it outside the terminal. For how CLAUDE.md, skills and tools fit into what a model sees, read about context engineering.

Let the right experts write your prompt

Prompt Expert is an AI prompt generator that brings the right experts to every job. They ask a few questions, read your website and files, and write the prompt for ChatGPT, Claude or Gemini with your real facts, working together when a job needs more than one.

See how it works

Questions

What makes a good Claude Code prompt?

A good Claude Code prompt names the file or area, describes the symptom, states any approach you prefer, and says what done looks like, ideally as a test or command Claude can run. It skips what Claude can learn by reading the repo.

What should I put in CLAUDE.md?

Only what Claude can't work out from the code: the exact test, typecheck and lint commands, misleading parts of the codebase, team decisions that aren't written down, and anything you have had to correct twice. Anthropic suggests keeping each file under 200 lines.

How do I make Claude Code plan before coding?

Switch to plan mode with Shift+Tab, or start Claude Code with --permission-mode plan. Claude reads the code and proposes a plan but edits nothing until you approve it. You can also ask it to interview you and write a spec first.

Do I need to tell Claude Code to think hard?

No. Phrases like "think hard" are ordinary prompt text. The effort setting, changed with /effort, controls how much Claude thinks. For a single difficult question, include ultrathink in that prompt.

What happened to custom slash commands in Claude Code?

They were merged into skills. Existing files in .claude/commands/ still work, and new ones go in .claude/skills//SKILL.md, where the folder name becomes the command you type.

Sources