How to Write Better Prompts for Claude Code
I observe that effective prompting with Claude Code is more about clear communication than clever tricks. The key insight I've developed through extensive usage is being specific about what you want to achieve while leveraging CLAUDE.md for persistent context and project understanding.
Core Principles
Rev the Engine - Use Plan Mode multiple times to refine Claude's plan before allowing execution. This iterative planning process helps catch potential issues early, ensures Claude fully understands the requirements, and allows you to guide the solution architecture before any code is written. The process of reading Claude's plan multiple times makes you think of edge cases and better approaches that weren't obvious in your initial request.
Be Specific - Vague requests like improve this code
give Claude no direction and often produce generic responses. Instead, define exactly what you want to achieve: add input validation to the contact form to check email format and required fields
. Specificity transforms unclear intentions into actionable tasks, allowing Claude to focus on the precise outcome you need rather than guessing at your requirements.
Use Exact References - When referencing files, use @ notation like @ContactForm.js
for entire files or include exact line numbers like Fix the validation bug on line 47 in @ContactForm.js
for specific locations. This approach saves tokens by eliminating the need for Claude to search through files and removes any ambiguity about which code section you're discussing. The @ notation helps Claude quickly identify target files, while line numbers are particularly valuable for context window efficiency in large files.
Reference Technical Terms - Prime Claude's knowledge by using specific terminology like debouncing
, time complexity
, Big O notation
, or memoization
. Technical terms activate Claude's deeper understanding of concepts and algorithms, enabling more sophisticated analysis and solutions. This priming effect helps Claude access relevant patterns and best practices from its training.
Provide Context - Always mention your framework, coding style, constraints, and preferences, preferably in CLAUDE.md for persistence across sessions. For example: I'm using Python with Django and prefer class-based views
. Context shapes how Claude approaches problems, influences architectural decisions, and ensures solutions align with your existing codebase. CLAUDE.md context is followed more strictly than prompt context.
Set Clear Scope - Define explicit boundaries to prevent scope creep and protect critical systems. Instructions like Only modify the contact form component, don't change the routing logic
keep Claude focused on the specific task while avoiding unintended consequences. Clear scope also makes tasks more manageable and reduces the chance of introducing bugs in unrelated areas.
Include Examples in CLAUDE.md - Document patterns, preferences, and examples directly in your CLAUDE.md rather than repeating them in every prompt. This creates persistent context that carries across all sessions, ensuring consistency in how Claude approaches similar problems. CLAUDE.md serves as your project's style guide and prevents you from having to re-explain the same concepts repeatedly.
Utilize Markdown Structure - Use headers, code blocks, and lists in your CLAUDE.md so Claude knows the boundaries between concepts and systems. Proper markdown structure helps Claude understand relationships between different parts of your CLAUDE.md and maintain clarity when dealing with multiple requirements or constraints. Markdown also helps prevent different parts of your CLAUDE.md from contradicting each other.
Define Numbered System Steps - When describing processes in your CLAUDE.md, use numbered sequences like:
1. Connect to the database
2. Validate user input
3. Update the record
4. Return the response
Then you ask Claude to perform the defined steps. Numbers significantly improve adherence compared to descriptive words like first
, then
, or finally
. This systematic approach helps Claude maintain proper order and reduces the likelihood of skipping or reordering critical steps. It also encourages Claude to utilize the Todo Tool, which helps you track and steer his progress.
Show Existing Patterns - Document your coding patterns and style preferences directly in CLAUDE.md with concrete examples from your codebase. Include code snippets showing your preferred error handling, component structure, naming conventions, and architectural decisions. Present examples of both what you want and what you do not want to establish clear boundaries and prevent unwanted approaches. This allows Claude to automatically follow your established patterns without needing to re-explain them in every prompt, ensuring consistency across all sessions and preventing you from having to repeatedly describe your coding standards.
Working within token limits forces better prompting habits. Use explicit file selection, clear task definition, and precise requests. These skills make you more effective regardless of context size. See Context Window Constraints for detailed strategies.
See Also: CLAUDE.md Supremacy|Plan Mode|Context Window Constraints|Getting Started