Skip to main content
Early access — new tools and guides added regularly
🟢 Zero to Claude Code — Guide 5 of 6
View track
>_ claude codeBeginner15 min

Prompting Techniques for Claude Code

The difference between mediocre and exceptional Claude Code output is how you ask. Learn the prompting patterns that experienced users rely on daily.

What you will build
A personal cheat sheet of prompting patterns you can reference in every session

Why prompting matters more in Claude Code

In a chat-based AI, a vague prompt gets a vague answer — but it is just text, so you can rephrase and try again cheaply. In Claude Code, a vague prompt can lead to the wrong files being edited, the wrong architecture being chosen, or time wasted on an approach you did not want. The stakes are higher because Claude Code takes action, not just gives advice. The good news: Claude Code is remarkably good at understanding intent when you give it enough context. The difference between a frustrating session and a productive one is almost always the quality of the initial prompt. A great prompt has three elements: what you want (the task), why you want it (the context), and how you want it done (the constraints). "Add authentication" is a poor prompt. "Add email/password authentication using NextAuth.js with a PostgreSQL adapter, following the existing patterns in our auth/ directory, with proper error handling and TypeScript types" is an excellent one.

The CONTEXT-TASK-CONSTRAINTS pattern

The most reliable prompting pattern for Claude Code: start with context, then the task, then constraints. Context: "This is a Next.js e-commerce app. The product catalog is in src/lib/products.ts and the cart uses React Context in src/context/CartContext.tsx." Task: "Add a wishlist feature where users can save products they want to buy later." Constraints: "Use the same pattern as CartContext. Store wishlist in localStorage. Add a heart icon toggle on each product card. No new dependencies." This pattern works because it gives Claude Code the information in the order it needs it: first understand the project, then understand the goal, then understand the boundaries. Without context, Claude Code guesses your tech stack. Without constraints, it might install a database for something that should use localStorage. Practice writing prompts in this three-part structure until it becomes automatic.

Iterative refinement: the conversation advantage

Claude Code's biggest advantage over one-shot AI tools is that it maintains conversation context. Use this. Start broad, then narrow. First prompt: "Look at the authentication flow in this project and tell me how it works." Read Claude Code's summary. Now you both have shared context. Second prompt: "The login form does not handle network errors. Add proper error handling that shows a user-friendly message." Claude Code knows exactly which files to edit because it already read them. Third prompt: "Good. Now add the same error handling pattern to the registration form." Claude Code applies the established pattern consistently. This iterative approach produces better results than a single massive prompt because each step validates understanding. If Claude Code's summary of your auth flow is wrong, you catch it before it starts editing. If the error handling looks different from what you expected, you redirect before it touches the registration form. Think of it as pair programming: your partner shows you their understanding, you confirm or correct, then they proceed.

Prompts that prevent common mistakes

Experienced Claude Code users include preventive constraints in their prompts. Instead of fixing mistakes after they happen, they prevent them. "Do not create any new files — only modify existing ones." This prevents Claude Code from creating a new utils.ts when you already have helpers.ts. "Do not install any new dependencies." This prevents Claude Code from npm-installing a library when a simple native solution exists. "Follow the exact pattern used in [specific file]." This prevents Claude Code from inventing a new pattern when you have an established one. "Show me the plan before making changes." This turns Claude Code into a consultant first, an executor second. "Make the smallest possible change." This prevents over-engineering. Claude Code sometimes builds elaborate solutions for simple problems. "Do not touch any files in [directory]." This creates a safety boundary around sensitive code. These constraints feel restrictive, but they actually make Claude Code more effective. Like guardrails on a bowling lane, they prevent gutter balls without limiting the range of useful outputs.

Advanced prompting patterns

Role assignment: "Act as a senior TypeScript developer reviewing this code for production readiness." This changes Claude Code's perspective and the kind of output it produces. Decomposition: "Break this task into numbered steps. Show me the steps before starting. I will approve each step individually." This gives you control over complex multi-file changes. Reference-based: "Look at how the UserProfile component handles loading states and apply the exact same pattern to the OrderHistory component." This is more effective than describing the pattern — Claude Code reads the reference and matches it precisely. Negative examples: "Here is how the old code handled this (badly): [paste code]. Rewrite it to be more maintainable, but keep the same inputs and outputs." Giving Claude Code a bad example to improve is often more effective than describing what you want from scratch. Checklist prompts: "Before committing these changes, verify: all TypeScript compiles, no unused imports, all functions have return types, no console.log statements." This creates a self-review step that catches common issues.

Related Lesson

Prompt Engineering Masterclass

This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.

Go to lesson