Asking Questions Effectively¶
Master the art of prompting Claude Code to get the best results.
What You'll Learn¶
- How to structure prompts
- Providing context
- Iterative refinement
- Common prompt patterns
The Anatomy of a Good Prompt¶
Good prompts have three elements:
- Context - What Claude needs to know
- Task - What you want done
- Constraints - Any requirements or limitations
Example Breakdown¶
Context: "I'm building a REST API with Express"
Task: "Create an endpoint for user registration"
Constraints: "Use bcrypt for passwords, return JWT on success"
Full prompt:
> I'm building a REST API with Express. Create an endpoint for user
registration that uses bcrypt for passwords and returns a JWT on success.
Context Strategies¶
Let Claude Explore¶
Claude examines files and builds understanding.
Point to Specific Files¶
Then follow up:
Provide Background¶
> This is a legacy app migrating from JavaScript to TypeScript.
Help me convert the utils folder while maintaining backward compatibility.
Reference Previous Work¶
Task Clarity¶
Vague vs Clear¶
| Vague | Clear |
|---|---|
| "Fix this" | "The login function returns null when password is wrong. It should throw an InvalidCredentialsError" |
| "Make it better" | "Refactor this function to use async/await instead of callbacks" |
| "Add tests" | "Add unit tests for the validateEmail function covering valid emails, invalid formats, and empty strings" |
Action Verbs¶
Use specific verbs: - Create - Make something new - Modify - Change existing code - Explain - Describe how something works - Debug - Find and fix a problem - Refactor - Restructure without changing behavior - Review - Analyze for issues
Examples¶
> Explain how authentication works in this app
> Debug why the tests in user.test.js are failing
> Refactor the handleSubmit function to be more readable
> Review this PR for potential issues
Iterative Refinement¶
Don't try to get everything perfect in one prompt. Iterate:
Round 1: Start Broad¶
Round 2: Refine¶
Round 3: Adjust¶
> Actually, MX lookup is too slow. Just check the format
and that it's not a disposable email domain.
Round 4: Polish¶
Prompt Patterns¶
Pattern: Show and Tell¶
> Here's an example of what I want:
Input: "hello world"
Output: "Hello World"
Create a function that does this for any string.
Pattern: Constraints First¶
> Requirements:
- Must work in Node.js 16
- No external dependencies
- Must handle Unicode
Create a slug generator function.
Pattern: Problem Description¶
> When I run npm test, I get "Cannot find module './config'"
but the file exists. Help me debug this.
Pattern: Learning Mode¶
Pattern: Comparison¶
Pattern: Step by Step¶
> Walk me through implementing OAuth2 login:
1. What files do I need?
2. What's the flow?
3. Let's implement each piece.
Working with Errors¶
Provide the Full Error¶
> I get this error when running the app:
TypeError: Cannot read property 'map' of undefined
at UserList (src/components/UserList.jsx:15:23)
at renderWithHooks (node_modules/react-dom/...)
What's wrong?
Describe What You Expected¶
> I expected this function to return an array of users,
but it returns undefined. Here's how I'm calling it...
Share What You Tried¶
Anti-Patterns to Avoid¶
Too Vague¶
# Bad
> Help me with my code
# Good
> Help me fix the sorting bug in src/utils/sort.js
- It should sort users by lastName then firstName
- Currently it only sorts by lastName
Too Much at Once¶
# Bad
> Create a full e-commerce site with cart, checkout, payments,
user accounts, admin panel, and inventory management
# Good
> Let's start with user registration. What's the first step?
Assuming Context¶
# Bad (Claude can't see your screen)
> Why isn't this working?
# Good
> Why does this return NaN?
function add(a, b) {
return a + b;
}
add("5", 3);
Try It Yourself¶
Exercise: Prompt Improvement¶
Take these weak prompts and improve them:
- "Make a function"
Better: ___
- "Fix the bug"
Better: ___
- "Add error handling"
Better: ___
Exercise: Iterative Development¶
- Start Claude Code in a new directory
- Begin with a simple prompt:
- Iterate at least 5 times, adding requirements:
- Add due dates
- Add priorities
- Add persistence (save to file)
- Add categories
- Add a CLI interface
Notice how each iteration builds on the last.
Quick Reference¶
┌─────────────────────────────────────────────────────┐
│ PROMPTING CHECKLIST │
├─────────────────────────────────────────────────────┤
│ □ Did I provide context? │
│ □ Is my task clearly stated? │
│ □ Did I mention constraints? │
│ □ Am I being specific, not vague? │
│ □ Did I include error messages if debugging? │
│ □ Am I asking one thing at a time? │
└─────────────────────────────────────────────────────┘
What's Next?¶
You've completed the beginner tutorials! Move on to Intermediate: Code Exploration to learn how to navigate real codebases.
Summary: - Good prompts have context, task, and constraints - Be specific - "fix the login bug" beats "fix it" - Iterate - start simple and refine - Include error messages and expected behavior when debugging - Use patterns like show-and-tell, constraints-first, and step-by-step
Learning Resources¶
Featured Video¶
NetworkChuck: AI in the Terminal - Prompting (3.6M subscribers)
Effective prompting strategies for terminal-based AI assistants including context management.
Additional Resources¶
| Type | Resource | Description |
|---|---|---|
| 🎬 Video | 800+ Hours Claude Code Tips | Edmund Yong - Prompting best practices |
| 📚 Official Docs | Prompt Engineering Guide | Anthropic official prompting docs |
| 📖 Tutorial | Best Practices | Anthropic engineering guide |
| 🎓 Free Course | Interactive Prompt Tutorial | Anthropic 9-chapter free course |
| 💼 Commercial | Prompt Engineering Course | Comprehensive prompting course |