Tips & Tricks

5 Prompt Techniques to Get Better Results from Claude Code [With Examples]

Dramatically improve Claude Code's output quality with these 5 proven prompt techniques. Includes Before/After examples and practical code snippets you can use today.

Introduction

The quality of Claude Code’s output is directly tied to how you write your prompts. With the right technique, the same task can go from producing “unusable code” to “production-ready code.”

In this article, we’ll walk through five practical prompt techniques with Before/After examples that you can start using immediately. If you’re new to Claude Code, check out our getting started guide first.

1. Provide Specific Context

The most impactful technique is communicating the background and purpose of your task clearly. Claude Code can read your project files, but it can’t read your mind. Tell it not just what you want, but why you want it, and output accuracy improves dramatically.

Before (weak prompt):

Make a login feature

After (strong prompt):

Add email/password authentication login to this Next.js 14 App Router project.
API routes already exist in src/app/api/, and the user table is defined via Prisma + PostgreSQL.
Use NextAuth.js v5 as the auth library.

Before (weak prompt):

Fix the bug

After (strong prompt):

Fix the bug in src/components/UserList.tsx where setState is called after
the component unmounts during the user list fetch in useEffect.
Please add cleanup logic using AbortController.

2. Break Tasks into Steps

When you hand Claude Code a massive task all at once, it can lose sight of the big picture. Intentionally split complex work into stages and confirm each step is complete before moving on.

Before (weak prompt):

Build a full product management system. I need listing, detail, create, edit, delete,
image upload, category management, inventory management, and search filtering.

After (strong prompt):

Let's build product management in stages. For Step 1, create the
product CRUD API:

- POST /api/products (create)
- GET /api/products (list with pagination)
- GET /api/products/:id (detail)
- PUT /api/products/:id (update)
- DELETE /api/products/:id (delete)

Use zod for validation and the existing Prisma client in src/lib/db.ts.

Before (weak prompt):

Write all the tests

After (strong prompt):

Write unit tests for src/utils/calculatePrice.ts.
Start with happy-path cases covering:
- Base price calculation
- Discount rates (10%, 20%, 50%)
- Tax-inclusive calculation (10% tax rate)
Use Vitest and follow the existing patterns in the tests/ directory.

3. Specify the Expected Output Format

Explicitly stating the programming language, framework, coding style, and other format expectations significantly reduces rework. Be especially clear about TypeScript type definitions and error-handling patterns.

Before (weak prompt):

Create an API client

After (strong prompt):

Create a client class for an external payment API in src/lib/api-client.ts.

Requirements:
- TypeScript with strict mode-compatible type definitions
- fetch-based (no axios)
- Custom error class (PaymentApiError) for error handling
- Retry logic (max 3 attempts, exponential backoff)
- Generic response types
- JSDoc comments on all public methods

Before (weak prompt):

Make a React component

After (strong prompt):

Create a reusable table component in src/components/DataTable.tsx.

- Client component ("use client"), not a React Server Component
- Props typed with generics to accept column definitions
- Sorting and pagination support
- Styled with Tailwind CSS, matching design tokens in src/components/Button.tsx
- Accessibility: proper WAI-ARIA table roles

4. Reference the Existing Codebase

One of Claude Code’s greatest strengths is understanding your entire project. Maximize this by explicitly instructing it to follow existing code. Pointing to specific file paths makes this even more effective.

Before (weak prompt):

Add a new API endpoint

After (strong prompt):

Following the same pattern as src/app/api/users/route.ts,
create an order management API endpoint at src/app/api/orders/route.ts.

Match the existing users API for:
- Zod schema validation
- try-catch error handling pattern
- NextResponse return style
- Prisma query approach

Before (weak prompt):

Build a settings page

After (strong prompt):

Using src/app/dashboard/profile/page.tsx as a reference,
create src/app/dashboard/settings/page.tsx.

Keep the same layout structure (DashboardLayout component, Breadcrumb,
PageHeader usage) while adding notification settings and security settings forms.
Use react-hook-form + zod for form management, same as the profile page.

5. Iterate with a Feedback Loop

Don’t expect perfection on the first try. Use conversation with Claude Code to incrementally improve quality. Treat the initial output as a foundation and provide specific, actionable feedback.

Before (weak prompt):

That's not right, redo it

After (strong prompt):

Thanks. Two changes please:
1. In the handleSubmit function, differentiate between network errors and
   validation errors when displaying messages to the user
2. Replace the simple spinner loading state with the skeleton UI
   from src/components/Skeleton.tsx

Before (weak prompt):

Make it better

After (strong prompt):

I'd like performance improvements. Specifically:
1. Apply React.memo to the product list rendering to prevent unnecessary re-renders
2. Add debounce (300ms) to the search input
3. Implement lazy loading for images
Please add comments at each change point so I can assess the Lighthouse score impact.

Conclusion

Let’s recap the five techniques:

  1. Provide specific context so Claude Code accurately understands your intent
  2. Break tasks into steps to keep the scope of each interaction manageable
  3. Specify the output format to minimize rework
  4. Reference existing code to maintain project consistency
  5. Iterate with feedback to incrementally raise quality

Each technique is effective on its own, but they truly shine when combined. Writing project rules in a CLAUDE.md file reduces how much context you need to include in every prompt, boosting efficiency further.

For more advanced usage, see our Claude Code productivity tips.

For foundational prompt engineering concepts, also read Anthropic’s official prompt engineering guide.

#prompts #techniques #productivity #Claude Code #prompt engineering