Reference

Prompt Patterns Library

Effective patterns for getting better results from Claude Code

Pattern 1: The Specification Prompt

When to use: Starting any significant task

Structure

Context:
- [Technology stack]
- [Relevant constraints]
- [Existing patterns to follow]

Task: [Clear description of what to build]

Requirements:
- [Specific requirement 1]
- [Specific requirement 2]
- [Specific requirement 3]

Output:
- [What files to create]
- [What format to use]

Example

Context:
- React 18 with TypeScript
- Tailwind CSS for styling
- Components go in src/components/

Task: Create a Modal component

Requirements:
- Accepts title, children, and onClose props
- Has animated entrance/exit
- Closes on backdrop click and Escape key
- Is accessible (focus trap, aria labels)

Output:
- Component file with types
- Unit tests
- Storybook story

Pattern 2: The Critique Prompt

When to use: After initial generation, before committing

Structure

Now review the code you just wrote. Check for:
- [Concern 1]
- [Concern 2]
- [Concern 3]
- [Concern 4]

Then fix any issues you find.

Example

Now review the code you just wrote. Check for:
- Security vulnerabilities
- Edge cases not handled
- Performance issues
- Accessibility problems
- TypeScript strictness

Then fix any issues you find.

Pattern 3: The Three Experts

When to use: Design decisions, architecture choices

Structure

Approach this problem as three experts would:
1. [Expert perspective 1]
2. [Expert perspective 2]
3. [Expert perspective 3]

What would each prioritize? Where do they disagree?

Example

Approach this problem as three experts would:
1. A senior security engineer
2. A performance optimization specialist
3. A UX-focused developer

What would each prioritize? Where do they disagree?

Pattern 4: The Incremental Build

When to use: Complex features, large tasks

Structure

Build this in stages. After each stage, stop and let me review.

Stage 1: [Foundation]
Stage 2: [Core functionality]
Stage 3: [Secondary features]
Stage 4: [Polish and edge cases]
Stage 5: [Tests and documentation]

Example

Build the checkout flow in stages:

Stage 1: Create the data model and types
Stage 2: Add the API layer
Stage 3: Build the UI components
Stage 4: Connect everything and add error handling
Stage 5: Write tests for the critical paths

Pattern 5: The Constraint Prompt

When to use: Focused tasks, avoiding scope creep

Structure

Implement ONLY [specific scope]. Do not:
- [Thing to avoid 1]
- [Thing to avoid 2]
- [Thing to avoid 3]

I'll handle those separately.

Example

Implement ONLY the login form. Do not:
- Add routing
- Create the API client
- Set up state management

I'll handle those separately.

Pattern 6: Best of N

When to use: Architecture decisions, multiple valid approaches

Structure

Generate [N] different approaches to [problem].
For each, explain the tradeoffs.

Example

Generate 3 different approaches to this authentication flow:
1. Session-based with cookies
2. JWT with refresh tokens
3. OAuth with external provider

For each, explain the tradeoffs for our use case.

Pattern 7: The Comparison

When to use: Evaluating options, making decisions

Structure

Compare [Option A] vs [Option B] for our use case:

Criteria:
- [Criterion 1]
- [Criterion 2]
- [Criterion 3]

Give a recommendation with reasoning.

Pattern 8: The Debug Assist

When to use: Troubleshooting issues

Structure

I'm seeing [problem]. Here's what I know:
- [Symptom 1]
- [Symptom 2]
- [What I've tried]

The error message is:
[exact error]

Help me diagnose and fix this.

Pattern 9: The Refactor Request

When to use: Improving existing code

Structure

Refactor [file/function] to:
- [Improvement 1]
- [Improvement 2]
- [Improvement 3]

Maintain:
- [Constraint 1]
- [Constraint 2]

Show me the before/after diff.

Pattern 10: The Documentation Generator

When to use: Creating docs for existing code

Structure

Create documentation for [target]:

Include:
- Overview and purpose
- Usage examples
- API reference
- Edge cases and gotchas

Format: [markdown/JSDoc/README]

Anti-Patterns to Avoid

Too Vague
Make it better
No Context
Write a function to process data
Micromanaging
Open file X, go to line 42, change 'foo' to 'bar'
Kitchen Sink
Build me a complete e-commerce platform with auth,
payments, inventory, shipping, reviews, recommendations,
admin panel, analytics, and mobile app.

Quick Reference

Situation Pattern
Starting a taskSpecification
After generationCritique
Design decisionThree Experts or Best of N
Large featureIncremental Build
Focused workConstraint
DebuggingDebug Assist
Improving codeRefactor Request
Creating docsDocumentation Generator