# Claude-Specific Techniques ## Overview Claude (by Anthropic) excels at instruction following, long-context tasks, and detailed analysis. This guide covers techniques optimized specifically for Claude, based on official Anthropic documentation and best practices. ## Claude's Strengths ### What Claude Does Best 1. **Instruction adherence** - Exceptional at following complex, detailed instructions 2. **Long context** - Handles 100K+ tokens effectively 3. **Structured output** - Excels with XML and structured formats 4. **Safety and helpfulness** - Well-calibrated for harmless, helpful responses 5. **Analysis depth** - Thorough analysis when asked 6. **Reasoning clarity** - Shows work step-by-step naturally ### Key Differentiators **Claude vs GPT-5:** - Better with very long contexts (200K vs GPT-5's limits) - More conservative (less likely to make things up) - Responds better to XML structuring - Excellent at detailed instruction following - Strong at nuanced analysis ## XML Tag Structuring ### Why XML Tags Matter Claude was trained with XML tags extensively, making them highly effective for: - Separating different types of content - Creating clear structure - Guiding output format - Organizing complex prompts ### Basic XML Pattern ```xml Your main task description Background information Claude needs - Limitation 1 - Limitation 2 Expected structure of the response ``` ### Common Tag Names **Use these for clarity:** - `` - Main task - `` - Background info - `` - Sample inputs/outputs - `` - Limitations - `` - Desired structure - `` - Data to process - `` - Long-form content - `` - Code snippets - `` - Request reasoning steps **Example:** ```xml Review this code for security vulnerabilities function login(username, password) { const query = `SELECT * FROM users WHERE username='${username}'`; // ... more code } - SQL injection - Password handling - Session management For each issue: - Severity: Critical/High/Medium/Low - Location: Line number - Problem: Description - Fix: Recommended solution ``` ## Step-by-Step Thinking ### Enabling Reasoning Claude naturally shows reasoning when asked, but you can enhance it: **Simple approach:** ``` Think step-by-step about this problem: [Problem description] ``` **Structured approach:** ```xml Solve this problem by thinking through it step-by-step [Problem description] 1. First, identify the key components 2. Then, analyze relationships 3. Next, consider edge cases 4. Finally, provide solution ``` **Explicit reasoning request:** ``` Before providing your answer, explain your reasoning process. [Let Claude show its work here] [Then provide the final answer here] ``` ### Benefits - More accurate results - Visible logic for debugging - Builds trust in responses - Helps Claude catch its own errors - Better for complex problems ## Clear and Specific Instructions ### The Clarity Principle **Treat Claude like a skilled intern on day one:** - Provide ALL necessary context - Define terms explicitly - Give specific examples - State assumptions clearly - Specify exact requirements ### Bad vs Good Instructions **❌ Vague:** ``` "Make this better" ``` **✅ Specific:** ``` "Refactor this function to: 1. Reduce cyclomatic complexity below 5 2. Extract helper functions for clarity 3. Add type annotations 4. Include JSDoc comments 5. Handle null/undefined edge cases" ``` **❌ Ambiguous:** ``` "Write professional content" ``` **✅ Explicit:** ``` "Write in formal business tone with these characteristics: - No contractions (use 'do not' vs 'don't') - Active voice - Sentences under 20 words - Direct address ('you') rather than third person - Industry-standard terminology - Professional but approachable" ``` ### Specificity Checklist - [ ] Exact task clearly stated - [ ] Output format specified - [ ] Length/size requirements defined - [ ] Tone/style described - [ ] Edge cases addressed - [ ] Success criteria stated - [ ] Examples provided (if applicable) - [ ] Constraints listed ## Progressive Disclosure ### Why It Matters for Claude With Claude's 100K+ token context window, you might be tempted to dump everything at once. Don't. **Progressive disclosure benefits:** - More focused responses - Better token efficiency - Clearer reasoning chains - Easier to course-correct - More maintainable conversations ### Pattern: Multi-Stage Workflow **Stage 1: High-level analysis** ```xml Analyze this codebase structure and provide: 1. List of main components 2. Key dependencies 3. Overall architecture pattern [File structure] ``` **Stage 2: Focused deep-dive** ```xml Now, for the authentication component you identified, perform a detailed security review You previously identified the auth component at: [location] Review for: - Authentication bypass vulnerabilities - Token security - Session management - Password handling ``` **Stage 3: Implementation** ```xml Based on the security issues you found, implement fixes for the high-severity items [High severity issues from previous response] ``` ### When to Use Progressive Disclosure **Good for:** - Large codebases - Multi-step workflows - Research tasks - Iterative refinement - Complex projects **Not needed for:** - Simple, single-shot tasks - Well-defined transformations - When all context fits easily ## Example-Driven Prompting ### Few-Shot with Claude Claude excels at learning from examples. Show 2-5 examples of desired behavior: ```xml Convert casual messages to professional email format Hey! Got your message. That sounds cool, let's do it! Thank you for your message. I appreciate the proposal and would be pleased to move forward with this initiative. Thanks! I'll get back to you later about this. Thank you. I will provide you with my response regarding this matter at my earliest convenience. Now convert this message: "Sounds good! See you next week for the meeting." ``` ### Example Quality Matters **Good examples:** - Cover edge cases - Show variety - Are realistic - Demonstrate exact format - Include challenging scenarios **Poor examples:** - Too similar to each other - Unrealistic/contrived - Missing edge cases - Inconsistent format ## Long-Context Best Practices ### Leveraging Claude's 100K+ Token Window Claude can handle massive context, but structure it well: ```xml Analyze all these customer support tickets for common issues [Ticket 1 content] [Ticket 2 content] [Ticket 1523 content] 1. Categorize issues by type 2. Identify the top 5 most common problems 3. Calculate frequency for each 4. Recommend solutions for top issues 5. Note any patterns across tickets ## Issue Categories [List of categories found] ## Top 5 Issues 1. [Issue]: [Frequency] - [Description] - Recommended solution: [Solution] ## Patterns Observed [Cross-ticket patterns] ``` ### Long-Context Tips 1. **Use clear delimiters** - XML tags, markdown headers 2. **Structure hierarchically** - Group related content 3. **Reference by ID** - Make it easy to cite specific parts 4. **Summarize upfront** - Give Claude the big picture first 5. **Be specific in queries** - Don't make Claude search the entire context ## Document Analysis Pattern ### For Large Documents ```xml Analyze this technical specification document [Large technical document - can be 50K+ tokens] 1. COMPLETENESS: Are all necessary sections present? 2. CLARITY: Are requirements unambiguous? 3. CONSISTENCY: Any contradictions? 4. FEASIBILITY: Any technical concerns? 5. GAPS: What's missing? For each framework dimension: ## [Dimension] - Assessment: [Good/Needs Work/Critical Issues] - Findings: [Specific findings with section references] - Recommendations: [What to improve] ``` ## Code Review Pattern ### Thorough Code Analysis ```xml Conduct a comprehensive code review [Code content] [Code content] [Code content] - Authentication/authorization flaws - Input validation - Sensitive data exposure - Injection vulnerabilities - Code complexity - Naming conventions - DRY violations - Error handling - N+1 queries - Unnecessary loops - Inefficient algorithms For each issue found: ### [Issue Title] - **Severity**: Critical/High/Medium/Low - **Category**: Security/Quality/Performance - **Location**: `[file]:[line]` - **Problem**: [Clear description] - **Impact**: [Why this matters] - **Fix**: [Specific code solution] At the end: ### Summary - Total issues: [count by severity] - Recommendation: Approve / Request Changes / Comment - Must-fix before merge: [Critical/High issues] ``` ## Iterative Refinement Pattern ### Building Complex Solutions **Round 1: Initial Draft** ```xml Create an initial draft of a REST API design for user management - CRUD operations for users - Authentication required - Role-based permissions - Email verification flow ``` **Round 2: Refine Based on Feedback** ```xml Refine the API design based on this feedback [Claude's previous response] - Add rate limiting specifications - Include pagination for list endpoints - Define error response format - Add API versioning strategy ``` **Round 3: Implementation Details** ```xml Now provide implementation details for the refined design Refined API design: [design from round 2] - TypeScript with Express - PostgreSQL database - JWT authentication - Include OpenAPI spec ``` ## Structured Output Enforcement ### Guaranteed Format with XML ```xml Analyze this data and respond ONLY in the specified XML format [Data to analyze] One paragraph overview What was discovered What it means What to do Do not include any text outside this XML structure. ``` ## Common Claude Patterns ### Pattern 1: Document Summarization ```xml Summarize this document for [target audience] [Long document] - Length: [word count] - Focus: [key aspects] - Include: [specific elements] - Tone: [formal/casual/technical] 1. Executive Summary (2-3 sentences) 2. Key Points (bullet list) 3. Important Details (1-2 paragraphs) 4. Action Items (if applicable) ``` ### Pattern 2: Data Extraction ```xml Extract structured data from these unstructured documents [Unstructured text] { "name": "string", "date": "YYYY-MM-DD", "amount": "number", "category": "string", "tags": ["string"] } Return a JSON array of objects matching the schema ``` ### Pattern 3: Comparative Analysis ```xml Compare these options across the specified dimensions - Cost (initial and ongoing) - Performance (speed, scalability) - Complexity (setup, maintenance) - Risk (technical, business) - Timeline (implementation time) ## Comparison Matrix | Dimension | Option A | Option B | Option C | |-----------|----------|----------|----------| ## Analysis For each dimension, explain the differences ## Recommendation Ranked recommendation with reasoning ``` ## Best Practices Summary ### Structure Your Prompts ✅ **DO:** - Use XML tags for organization - Separate concerns clearly - Provide complete context - Show examples - Specify exact format ❌ **DON'T:** - Mix different types of content without delimiters - Leave requirements implicit - Assume Claude knows your context - Skip format specification ### Leverage Long Context ✅ **DO:** - Include all relevant information - Structure with clear sections - Use progressive disclosure for complex tasks - Reference specific parts by ID ❌ **DON'T:** - Dump unstructured mass of text - Make Claude search for key info - Forget to organize hierarchically ### Request Reasoning ✅ **DO:** - Ask for step-by-step thinking - Request explanations - Use `` tags - Show work for complex problems ❌ **DON'T:** - Accept black-box answers for important decisions - Skip reasoning on complex tasks ### Be Specific ✅ **DO:** - Define exact requirements - Specify tone, length, format - Give concrete examples - State success criteria ❌ **DON'T:** - Use vague terms like "better" or "professional" - Assume Claude knows what you want - Leave format open-ended ## Quick Reference ### Basic Template ```xml [Clear, specific task] [Background information] - [Requirement 1] - [Requirement 2] - [Constraint 1] - [Constraint 2] [If using few-shot] [Exact structure expected] ``` ### Quick Tips | Goal | Technique | |------|-----------| | Structured output | XML tags with schema | | Complex reasoning | Ask for step-by-step thinking | | Learning patterns | 2-5 few-shot examples | | Long documents | XML sections with IDs | | Precise format | Provide exact template | | Detailed analysis | Multi-stage progressive disclosure | | Consistent style | Specific style guidelines + examples | --- **Remember:** Claude excels with clear structure, XML tags, and detailed instructions. Be explicit, provide context, and leverage its long-context capabilities.