Reviewed by Jonathan West · Updated Jul 27, 2026

Claude Code Prompts: Templates and Examples

Write prompts that produce clean, reviewable changes instead of vague diffs you have to redo.

Reviewed by Jonathan West · Updated Jul 27, 2026

Prompting Claude Code is different from prompting a chatbot. You are giving instructions to an agent that can read your entire repo, edit files, and run commands. A vague prompt does not just give a bad answer. It gives a bad answer with file changes you have to clean up.

The best Claude Code prompts share three traits. They name specific files. They describe the expected output. They set constraints the agent must follow. Everything else is secondary.

This guide covers how to prompt Claude Code effectively, with real templates for the most common tasks: bug fixes, feature additions, refactoring, test writing, and code review.


How Claude Code prompts differ from chatbot prompts

A chatbot prompt asks for information or text. A Claude Code prompt asks for action. The agent will read files, make changes, run commands, and produce a diff. If your prompt is unclear, the diff will be unclear.

Claude Code also has persistent context. It reads your CLAUDE.md file, understands your project structure, and remembers earlier messages in the session. You do not need to re-explain your tech stack in every prompt.

The biggest difference is stakes. A chatbot gives you text you can ignore. Claude Code gives you file changes you must review. Bad prompts create review debt. Good prompts create reviewable, mergeable changes.

  • Claude Code acts on your repo, not just answers questions.
  • CLAUDE.md provides persistent context across prompts.
  • Bad prompts create review debt, not just bad answers.
  • You do not need to re-explain your project every time.

Need a Claude Code prompt library and CLAUDE.md configuration built for your specific codebase and workflows? We build it, test it, and hand it off ready to use.

Book a Consultation

CLAUDE.md as your persistent prompt

CLAUDE.md is the most important prompt you write. Claude Code reads it automatically at the start of every session. It sets the rules that every subsequent prompt inherits.

A strong CLAUDE.md includes your coding standards, architecture decisions, file naming conventions, test requirements, and anything the agent should always know. It replaces the context you would otherwise copy into every prompt.

Keep CLAUDE.md under 500 lines. Focus on rules the agent must follow, not background reading. Put architecture docs elsewhere and reference them. CLAUDE.md is for constraints and conventions, not a wiki.

  • Read automatically at session start. No manual loading needed.
  • Include coding standards, naming conventions, and test rules.
  • Keep it under 500 lines of actionable constraints.
  • Reference external docs rather than inlining long explanations.

The five-part Claude Code prompt structure

Every effective Claude Code prompt has five parts: goal, scope, constraints, verification, and output format. You do not need headers or labels. Just make sure all five are present.

Goal: what should change and why. Scope: which files or directories to touch. Constraints: what not to change, what patterns to follow, what to avoid. Verification: how to confirm the change works. Output format: what to report when done.

Example: Fix the race condition in src/api/orders.ts where concurrent checkout requests can double-charge a card. Only modify the checkout handler. Use the existing database transaction pattern from src/api/payments.ts. Run the checkout test suite after the fix. Summarize what changed and why the fix prevents the race.

  • Goal: what to change and why.
  • Scope: which files or directories to touch.
  • Constraints: what to avoid, what patterns to follow.
  • Verification: how to confirm the change works.
  • Output format: what to report when done.

Break big tasks into steps

Claude Code handles focused tasks better than monolithic ones. A prompt that says refactor the entire authentication system will produce an unreviable diff. A prompt that says extract the JWT validation logic from auth.ts into a separate jwt-validator.ts module produces a clean, testable change.

Use a chain of small prompts instead of one giant prompt. Each prompt builds on the previous result. You review each step before moving to the next. This catches mistakes early instead of finding them buried in a 500-line diff.

The /compact command helps manage context between steps. When your session gets long, /compact summarizes the conversation so Claude Code retains key decisions without running out of context window.

  • Small, focused prompts produce reviewable changes.
  • Chain prompts so each step builds on the last.
  • Review after each step to catch mistakes early.
  • Use /compact to manage context in long sessions.

Prompt template: bug fixes

Bug fix prompts should follow a reproduce-then-fix pattern. Tell Claude Code to confirm the bug exists before writing the fix. This prevents the agent from fixing a problem that is not actually there.

Template: There is a bug in [file] where [describe the incorrect behavior]. First, read the relevant code and confirm you can see the issue. Then make the smallest change that fixes it. Do not refactor surrounding code. Run [test command] to verify. Explain why the fix works.

The smallest change that fixes it constraint matters. Without it, Claude Code often refactors neighboring code while fixing the bug, making the diff harder to review and increasing the chance of regressions.

  • Ask Claude Code to confirm the bug before fixing it.
  • Constrain to the smallest change that fixes the issue.
  • Require a test run to verify the fix.
  • Ask for an explanation of why the fix works.

Prompt template: new features

Feature prompts need more structure than bug fixes because the agent is creating something new. Specify the input, the output, the file locations, and which existing patterns to follow.

Template: Add a [feature] endpoint to [directory]. It should accept [input format] and return [output format]. Follow the same controller/service/repository pattern used in [existing similar feature]. Add unit tests in [test directory]. Do not modify any existing endpoints.

Point Claude Code at an existing feature as a reference. This is more effective than describing the pattern from scratch. The agent reads the reference code and follows the same structure, naming, and error handling.

  • Specify input format, output format, and file locations.
  • Point to an existing feature as a structural reference.
  • Require tests alongside the new code.
  • Explicitly exclude changes to existing features.

Prompt template: refactoring

Refactor prompts must define what better means. Without a clear target, Claude Code will reorganize code based on general best practices, which may not match your project's conventions.

Template: Extract [specific logic] from [file] into a new module at [path]. Update all imports across the repo. Preserve the existing public API so no callers need to change. Run the full test suite to confirm nothing breaks. Do not change any behavior, only move code.

The do not change any behavior instruction is critical. Claude Code is eager to improve things. A refactor prompt that does not explicitly forbid behavior changes will often get behavior changes mixed into the structural move.

  • Define exactly what better means for this refactor.
  • Forbid behavior changes during structural moves.
  • Require a full test run to catch regressions.
  • Update all imports, not just the moved file.

Common Claude Code prompting mistakes

The vague goal: make this page better or improve the codebase. These prompts produce large diffs with unclear intent. Always name the specific change you want.

The missing scope: fix the bug without saying which file or function. Claude Code will search the entire repo and may fix the wrong thing. Always name the file or module.

The no-review prompt: make changes and deploy. Never give Claude Code deploy access without a human review step. Include a verification step in every prompt.

The context dump: pasting an entire design doc into the prompt. Claude Code already reads your repo. Tell it which file to read instead of pasting content. Use CLAUDE.md for persistent context.

  • Name the specific file, function, or module.
  • Describe the expected outcome, not just the problem.
  • Always include a verification step.
  • Reference files instead of pasting their contents.

Frequently Asked Questions

  • Start with the specific change you want. Name the file or module, describe the expected result, and set constraints. Avoid broad instructions like improve this or make it better.
  • Use CLAUDE.md for rules that apply to every task: coding standards, architecture, naming conventions. Use individual prompts for task-specific instructions. CLAUDE.md reduces repetition and keeps prompts focused.
  • Most effective prompts are three to eight sentences. Include the goal, scope, constraints, and verification step. Longer prompts often contain unnecessary context that Claude Code can find by reading the repo itself.
  • Yes. Save reusable prompts as Skills in ~/.claude/commands/ for personal use or .claude/commands/ for team use. Skills turn good prompts into slash commands that anyone on the team can run.
  • Start with a research prompt: read these files and explain how the current system works. Use the explanation to write a precise action prompt. Two focused prompts beat one vague one.

Want Custom Claude Code Prompt Templates for Your Team?

Layer3 Labs builds prompt libraries and CLAUDE.md configurations tailored to your codebase. We design the templates, test them against your repo, and train your team to use them.

Book a Free AI Workflow Audit