Prompting Techniques
Craft clear, effective prompts that consistently deliver the results you need. Good prompting is the foundation of all Claude Code interactions.
For comprehensive prompting principles and advanced techniques, see promptingguide.ai. This guide focuses on patterns specific to Claude Code workflows.
What You Get
- Better outputs with clear, specific requests
- Faster results through proper context provision
- Consistent quality using proven prompt patterns
- Effective iteration with structured refinement approaches
How to Use Effective Prompting
1. Be Clear and Specific
The clearest prompt gets the best result. Specify location, problem, and expected outcome.
Vague: "Fix the auth"
Clear: "Fix the JWT token validation in auth.js - tokens are expiring 1 hour early"
Vague: "Make it faster"
Clear: "Optimize the database query in getUserData() - it's taking 3+ seconds with 1000 records"
2. Provide Context
Claude performs better with relevant context. Include what's broken, what you've tried, and project constraints:
The ImageUpload component crashes when users upload files larger than 5MB.
Error: "Uncaught RangeError: Maximum call stack size exceeded"
Location: src/components/ImageUpload.jsx line 45
Expected: Show friendly error for files > 5MB, suggest compression
Constraints: Must work on mobile Safari, keep under 100KB bundle impact3. Break Down Complex Tasks
Split complex requests into manageable steps:
Instead of: "Build a complete user management system"
Try:
1. "Create the user database schema"
2. "Implement user registration endpoint"
3. "Add email verification"
4. "Create login with JWT tokens"4. Use Action-Oriented Language
Start with verbs to make intent clear:
- ✅ "Create a function that..."
- ✅ "Refactor the code to..."
- ✅ "Debug the issue where..."
- ✅ "Optimize the performance of..."
5. Specify Constraints and Requirements
Always include relevant limitations:
"Create a React component for user profiles that:
- Uses functional components with hooks
- Includes TypeScript types
- Is mobile-responsive
- Lazy loads profile images"Examples in Action
File Operation
Create a utility function that reads a JSON config file and merges it with default values.
Use TypeScript, handle missing files gracefully, and return typed results.Result: Complete, typed utility with error handling
Why it works: Specifies language, behavior, and error requirements
Complex Refactoring
Refactor the PaymentProcessor class to use dependency injection:
1. Extract external services (Stripe, PayPal) into interfaces
2. Use constructor injection for dependencies
3. Maintain backward compatibility with existing code
4. Add unit tests for the refactored version
Current code is in src/payments/processor.tsResult: Systematic refactoring preserving functionality
Why it works: Step-by-step instructions with clear constraints
Debugging with Context
Getting "TypeError: Cannot read property 'id' of undefined" in UserList component.
Error happens when filtering users:
const activeUsers = users.filter(u => u.status.id === 'active')
Users array comes from API endpoint /api/users
Sometimes the status field is missing in the API responseResult: Claude identifies root cause and provides defensive solution
Why it works: Includes error, code context, and data source information
Common Patterns
Progressive Enhancement
Build complexity incrementally:
First: "Create a basic todo list component"
Then: "Add ability to mark items complete"
Then: "Add local storage persistence"
Then: "Add drag-and-drop reordering"Format Examples
When requesting specific formats, show examples:
"Format the error messages like this:
[ERROR_CODE] Component: Brief description
Example: [AUTH_001] LoginForm: Invalid credentials provided"Anti-Patterns
Don't Assume Context
Wrong: "Fix the bug" (What bug? Where?)
Right: "Fix the null reference error in calculateTotal() when orderItems is empty"
Don't Mix Multiple Tasks
Wrong: "Fix auth, add logging, and update the README"
Right: Separate prompts for each distinct task
Don't Use Contradictory Requirements
Wrong: "Make it simple but handle all edge cases"
Right: "Create a simple version first, we'll add advanced features later"
Don't Forget Environment Details
Wrong: "Install the necessary packages"
Right: "Install packages using npm (not yarn) compatible with Node 18+"
Quick Templates
Feature Request:
Create [feature] that [core functionality].
Requirements:
- [Requirement 1]
- [Requirement 2]
Constraints: [Any limitations]
Tech stack: [Languages/frameworks]Bug Fix:
Error: [Error message]
Location: [File/function]
When: [Conditions that trigger]
Expected: [What should happen]
Current code: [Relevant snippet]Code Review:
Review [file/component] for:
- [Aspect 1, e.g., security]
- [Aspect 2, e.g., performance]
- [Aspect 3, e.g., best practices]
Suggest improvements with examples.Related
- Thinking Modes - Control Claude's reasoning approach
- Output Styles - Customize response format
- CLAUDE.md Files - Set persistent project context