New: Credits are here. One balance for web and MCP. See pricing

    Tutorials
    claude code
    prompts
    productivity

    How to Write Better Prompts for Claude Code (2026)

    Write prompts that get Claude Code to produce exactly what you need. Patterns, examples, and common mistakes for coding prompts.

    May 14, 20265 min read
    Share:

    The quality of Claude Code's output depends directly on the quality of your prompt. A vague prompt gets generic code. A specific prompt gets code that fits your project. Here are the patterns that consistently produce better results.

    Quick Answer: To write better prompts for Claude Code, include context, task, and constraints. Use patterns like "like this one" to reference existing code, "read first, then do" to force understanding, and "options with tradeoffs" for design decisions. Avoid vague instructions, multiple tasks, or ignoring existing project patterns.

    The anatomy of a good coding prompt

    A good prompt has three parts: context, task, and constraints.

    Context — what Claude needs to know:

    "We have a Next.js 14 app with App Router, Prisma ORM, and PostgreSQL."

    Task — what you want done:

    "Add a password reset flow."

    Constraints — how you want it done:

    "Use the existing email service in src/lib/email.ts. Store the reset token in the password_resets table with a 1-hour expiry. Follow the same error handling pattern as the login endpoint."

    Combined:

    "We have a Next.js 14 app with App Router, Prisma ORM, and PostgreSQL. Add a password reset flow. Use the existing email service in src/lib/email.ts. Store the reset token in the password_resets table with a 1-hour expiry. Follow the same error handling pattern as the login endpoint."

    Recommended skills

    Patterns that work

    "Like this one"

    Reference existing code in your project:

    "Add a PATCH endpoint for products, following the same pattern as the PATCH endpoint in src/routes/users.ts."

    Claude reads the referenced file and copies the exact conventions.

    "Read first, then do"

    "Read src/services/payment.ts and explain how the refund flow works. Then add support for partial refunds."

    Forces Claude to understand before acting.

    "What would you change?"

    "Review src/components/Dashboard.tsx. What would you improve?"

    Gets suggestions before implementation. You choose which ones to apply.

    "Options with tradeoffs"

    "I need to add caching for the product catalog. Give me three approaches with pros and cons."

    Prevents Claude from committing to one solution before you've considered alternatives.

    "As if I'm a..."

    "Write tests for the auth module as if I'm a QA engineer who's never seen this codebase."

    Shifts the perspective and often produces more thorough output.

    Common mistakes

    Too vague

    ❌ "Fix the bug." ✅ "In src/routes/orders.ts, the POST endpoint returns 500 when the cart is empty instead of 400 with a validation error."

    Too many tasks at once

    ❌ "Add authentication, build the dashboard, create the admin panel, and deploy to AWS." ✅ "Add JWT authentication to the existing Express app. Use passport-jwt with a secret from the AUTH_SECRET environment variable."

    Not specifying the output location

    ❌ "Write a utility function for formatting dates." ✅ "Add a formatDate utility function in src/utils/date.ts that formats dates as 'Apr 11, 2026'."

    Ignoring existing patterns

    ❌ "Create a user service." ✅ "Create a user service following the same pattern as src/services/product.ts."

    When prompts aren't enough: use skills

    If you find yourself adding the same constraints to every prompt ("use TypeScript", "follow our error handling pattern", "test with Vitest"), that's a signal to create a SKILL.md skill instead. Skills apply automatically so you don't have to repeat yourself.

    "Use functional components with TypeScript. Always define props as interfaces."

    If you type this in every component prompt, it should be a skill. See SKILL.md Templates You Can Copy and Customize.


    Find skills that replace repetitive prompting at Agensi.

    Frequently Asked Questions