Skip to content

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:

  1. Context - What Claude needs to know
  2. Task - What you want done
  3. 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

> Look at this codebase and tell me what it does

Claude examines files and builds understanding.

Point to Specific Files

> Read src/auth.js - I have questions about it

Then follow up:

> Why does it refresh tokens every 15 minutes?

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

> Using the same pattern as the UserService we created earlier,
  create a ProductService

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

> Create a function to validate email addresses

Round 2: Refine

> Also check that the domain has an MX record

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

> Add TypeScript types and JSDoc comments

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

> Explain this code line by line. I'm trying to understand
  how the caching works.

Pattern: Comparison

> What are the pros and cons of using Redis vs in-memory
  caching for this use case?

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

> I tried adding a null check but now I get a different error.
  The null check is on line 20.

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:

  1. "Make a function"

Better: ___

  1. "Fix the bug"

Better: ___

  1. "Add error handling"

Better: ___

Exercise: Iterative Development

  1. Start Claude Code in a new directory
  2. Begin with a simple prompt:
    > Create a todo list manager in Python
    
  3. Iterate at least 5 times, adding requirements:
  4. Add due dates
  5. Add priorities
  6. Add persistence (save to file)
  7. Add categories
  8. 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

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