{"slug":"anthropic","id":"prompt-anthropic","type":"prompt-pattern","title":"Prompting Patterns for Anthropic Claude","description":"What works specifically with Claude Opus 4.6, Sonnet 4.6, and Haiku 4.5 — XML tags, long context, constraint following, extended thinking, and tiered instructions.","last_updated":"2026-04-10","last_verified":null,"verification_status":"unverified","markdown_url":"/content/prompt-patterns/anthropic.md","html_url":"/prompt-patterns/anthropic","api_url":"/api/v1/prompt-patterns/anthropic.json","content_hash":"99e32f1a153918999c7aba0dedc3f9b0721c0bc479c1f791d3c033a7e7609e9c","sha256":"99e32f1a153918999c7aba0dedc3f9b0721c0bc479c1f791d3c033a7e7609e9c","tags":["anthropic","claude","opus","sonnet","haiku","prompt-patterns"],"relationships":{"links":[{"text":"Prompt Engineering Guide","href":"/guides/prompting","html_path":"/guides/prompting","target_id":"prompting","target_type":"guide","target_title":"Prompt Engineering Guide — How to Write Better AI Prompts"}],"related":[{"id":"prompt-google","title":"Prompting Patterns for Google Gemini","type":"prompt-pattern","html_url":"/prompt-patterns/google","markdown_url":"/content/prompt-patterns/google.md","shared_tags":["prompt-patterns"],"score":3},{"id":"prompt-open-source","title":"Prompting Patterns for Open Source Models","type":"prompt-pattern","html_url":"/prompt-patterns/open-source","markdown_url":"/content/prompt-patterns/open-source.md","shared_tags":["prompt-patterns"],"score":3},{"id":"prompt-openai","title":"Prompting Patterns for OpenAI GPT-5.4","type":"prompt-pattern","html_url":"/prompt-patterns/openai","markdown_url":"/content/prompt-patterns/openai.md","shared_tags":["prompt-patterns"],"score":3},{"id":"prompt-xai","title":"Prompting Patterns for xAI Grok","type":"prompt-pattern","html_url":"/prompt-patterns/xai","markdown_url":"/content/prompt-patterns/xai.md","shared_tags":["prompt-patterns"],"score":3},{"id":"claude-vs-gemini","title":"Claude Opus 4.6 vs Gemini 3.1 Pro","type":"comparison","html_url":"/comparisons/claude-vs-gemini","markdown_url":"/content/comparisons/claude-vs-gemini.md","shared_tags":["claude","anthropic"],"score":2},{"id":"claude-vs-gpt","title":"Claude Opus 4.6 vs GPT-5.4","type":"comparison","html_url":"/comparisons/claude-vs-gpt","markdown_url":"/content/comparisons/claude-vs-gpt.md","shared_tags":["claude","anthropic"],"score":2}],"explicit":{}},"metadata":{"title":"Prompting Patterns for Anthropic Claude","type":"prompt-pattern","id":"prompt-anthropic","description":"What works specifically with Claude Opus 4.6, Sonnet 4.6, and Haiku 4.5 — XML tags, long context, constraint following, extended thinking, and tiered instructions.","last_updated":"2026-04-10","tags":["anthropic","claude","opus","sonnet","haiku","prompt-patterns"]},"content_text":"# Prompting Patterns for Anthropic Claude\n\nClaude handles prompts differently than GPT or Gemini. It was trained with a focus on instruction-following precision, long-context reasoning, and nuanced output. The patterns that get the best results from Claude are specific to how it processes structure and constraints.\n\nThis guide covers Claude Opus 4.6, Sonnet 4.6, and Haiku 4.5. The same patterns work across all three tiers -- Opus is the most capable, Sonnet is the best balance of speed and quality, and Haiku is the fastest and cheapest.\n\nFor general prompting techniques that work across all models, see the [Prompt Engineering Guide](/guides/prompting).\n\n---\n\n## XML Tags: Claude's Secret Weapon\n\nClaude responds exceptionally well to XML-style tags for organizing prompt sections. This is the single most impactful pattern for Claude -- it dramatically improves how Claude parses and follows complex prompts.\n\nThe tags are not real XML and do not need to be valid markup. They are structural markers that tell Claude \"this section is context,\" \"this section is instructions,\" \"this section is an example.\" Claude was specifically trained to recognize and respect these boundaries.\n\n```\n<instructions>\nYou are a code reviewer. Review the code below for bugs, performance\nissues, and readability. For each issue, explain the problem and\nprovide a fix.\n\nRules:\n- Focus only on substantive issues, not style nitpicks\n- Rate overall code quality on a scale of 1-10\n- If the code is good, say so briefly and move on\n</instructions>\n\n<context>\nThis is a Python microservice that handles payment processing. It runs\non AWS Lambda with a 30-second timeout. The team uses Python 3.12 and\nfollows PEP 8.\n</context>\n\n<code>\ndef process_payment(amount, currency, customer_id):\n    response = stripe.charges.create(\n        amount=amount,\n        currency=currency,\n        customer=customer_id\n    )\n    db.execute(\"INSERT INTO payments VALUES (?, ?, ?)\",\n               (customer_id, amount, response.id))\n    return {\"status\": \"success\", \"charge_id\": response.id}\n</code>\n```\n\nCommon tags that work well with Claude:\n- `<instructions>` -- what you want Claude to do\n- `<context>` -- background information\n- `<examples>` -- input/output examples\n- `<constraints>` -- rules and boundaries\n- `<input>` or `<document>` -- the content to process\n- `<output_format>` -- how you want the response structured\n\nYou can nest them, combine them, and invent your own. Claude treats any XML-like tag as a section boundary.\n\n---\n\n## Long Context: Put the Question After the Context\n\nWith 1M tokens of context across all tiers, Claude can process entire codebases, full document collections, and lengthy datasets in a single prompt. But *where* you place your question matters.\n\nThe pattern: put all context material first, then your question or instructions at the end. Claude weights the end of the prompt more heavily for determining what to do, while the beginning serves as reference material.\n\n```\n<documents>\n\n<document title=\"Q1 Financial Report\">\n[... 15 pages of financial data ...]\n</document>\n\n<document title=\"Q2 Financial Report\">\n[... 15 pages of financial data ...]\n</document>\n\n<document title=\"Board Meeting Notes - March\">\n[... 5 pages of meeting notes ...]\n</document>\n\n</documents>\n\n<instructions>\nBased on the documents above, answer these questions:\n\n1. What was the quarter-over-quarter revenue growth rate?\n2. Which product line showed the largest margin improvement?\n3. What risks were discussed in the board meeting that could affect Q3?\n\nFor each answer, cite the specific document and section where you found\nthe information.\n</instructions>\n```\n\nThis \"context first, question last\" pattern produces noticeably better results than putting the question at the top. Claude will reference the full context but focus its response on the instructions at the end.\n\n---\n\n## Constraint Following: \"Do This But Not That\"\n\nClaude excels at following explicit constraints -- especially negative constraints. If there are things you *do not* want Claude to do, say so directly. Claude is more reliable at respecting boundaries than most models.\n\n```\n<instructions>\nExplain blockchain technology for a business audience.\n\nDo:\n- Use analogies from traditional business (ledgers, contracts, audits)\n- Keep paragraphs under 4 sentences\n- Include one real-world use case that is NOT cryptocurrency\n\nDo not:\n- Mention Bitcoin, Ethereum, or any specific cryptocurrency\n- Use technical jargon (hash, nonce, Merkle tree, consensus mechanism)\n- Include disclaimers about volatility or investment risk\n- Start with a dictionary-style definition\n</instructions>\n```\n\nClaude handles this \"do/do not\" pattern cleanly. It will follow the positive instructions while reliably avoiding the negative ones. This is particularly useful for:\n\n- Content generation where you need to avoid certain topics\n- Code generation where you want to exclude certain libraries or patterns\n- Analysis where you want to focus on specific angles and ignore others\n\n---\n\n## Extended Thinking: For Complex Tasks\n\nClaude's extended thinking feature gives the model time to reason through complex problems before responding. Unlike GPT-5.4 Thinking, this is not activated by the prompt itself -- it is an API parameter (`thinking: { type: \"enabled\", budget_tokens: 10000 }`).\n\nIn Claude.ai (the web interface), extended thinking is available as a toggle. Turn it on for:\n\n- Complex coding tasks (architecture decisions, debugging multi-file issues)\n- Math and logic problems\n- Long-document analysis where synthesis is required\n- Any task where you notice Claude's first answer is shallow or wrong\n\nYou do not need to prompt \"think step by step\" with Claude. If extended thinking is enabled, Claude will automatically use it when the task warrants it. Your prompt should focus on *what* you want, not *how* Claude should think.\n\n```\n<context>\n[paste a 2,000-line Python codebase here]\n</context>\n\n<instructions>\nThis codebase has a bug: when two users simultaneously update the same\nrecord, one update is silently lost. Find the race condition, explain\nwhy it happens, and provide a fix that uses optimistic locking.\n</instructions>\n```\n\nWith extended thinking enabled, Claude will reason through the codebase methodically before responding. Without it, Claude might jump to the most obvious candidate and miss the actual bug.\n\n---\n\n## Nuanced Writing: Give Claude a Voice\n\nClaude produces less formulaic prose than most models. It does not default to the \"listicle with emoji\" style that plagues AI-generated content. But to get the best writing out of Claude, give it a specific voice or style to match rather than just a topic.\n\n```\n<instructions>\nWrite a 500-word essay arguing that most productivity advice is\ncounterproductive.\n\nVoice and style:\n- Write like Paul Graham: conversational but intellectually rigorous\n- Short paragraphs (2-3 sentences max)\n- Start with a contrarian observation, not a thesis statement\n- Use specific examples, not generic ones\n- No bullet points, no headers, no bold text -- just flowing prose\n- The tone should be \"smart friend explaining something at dinner,\"\n  not \"business blog post\"\n</instructions>\n```\n\nClaude responds well to style references (named authors, publications, specific tones) and to explicit structural guidance. The more specific you are about *how* you want something written, the more distinctive the output.\n\n---\n\n## Artifacts: Standalone Outputs in Claude.ai\n\nWhen using Claude.ai, Claude can create \"artifacts\" -- standalone pieces of content that appear in a separate panel. These include code files, HTML pages, SVG graphics, diagrams, and interactive React components.\n\nTo trigger artifact creation, be explicit about wanting a standalone output:\n\n```\nCreate an interactive calculator that converts between Celsius and\nFahrenheit. It should:\n- Have a single input field with a toggle for C→F or F→C\n- Update the result in real-time as the user types\n- Show the formula used below the result\n- Use clean, minimal styling with a dark theme\n\nMake this as a standalone interactive artifact.\n```\n\nClaude will produce a complete, runnable React component. Artifacts are useful when you want something you can copy, download, or interact with directly rather than reading it inline in the conversation.\n\n---\n\n## Tiered Instructions: Hierarchical Prompts\n\nClaude handles hierarchical instructions well. You can give it a high-level goal, then specific rules, then examples -- and it will respect all three levels without losing track.\n\n```\n<goal>\nYou are helping me prepare for a job interview at a senior engineering\nlevel. Your job is to ask me technical questions, evaluate my answers,\nand give me honest feedback.\n</goal>\n\n<rules>\n- Ask one question at a time\n- Wait for my answer before proceeding\n- After I answer, rate it on a scale of 1-5 and explain what a\n  perfect answer would include\n- Vary difficulty: alternate between medium and hard questions\n- Cover these topics: system design, algorithms, behavioral\n- If I say \"skip,\" move to the next question without judgment\n- After 10 questions, give me an overall assessment with specific\n  areas to improve\n</rules>\n\n<examples>\nGood question: \"Design a URL shortening service that handles 100M\nnew URLs per day. Walk me through your approach.\"\n\nBad question: \"What is a hash table?\" (too basic for senior level)\n\nGood feedback: \"3/5. You covered the basic architecture well but\ndidn't address data partitioning or cache invalidation, which are\ncritical at this scale. A strong answer would also discuss trade-offs\nbetween consistency and availability.\"\n</examples>\n\nStart with your first question.\n```\n\nThe three-tier structure (goal, rules, examples) gives Claude a clear hierarchy: the goal defines success, the rules define behavior, and the examples calibrate quality. Claude follows all three levels simultaneously without conflating them.\n\n---\n\n## Quick Reference\n\n- **XML tags:** Use `<instructions>`, `<context>`, `<examples>`, and similar tags to separate prompt sections. This is the highest-impact pattern for Claude.\n- **Long context:** With 1M tokens, paste entire documents and codebases. Always put your question/instructions *after* the context, not before.\n- **Constraints:** Claude excels at \"do this but not that\" instructions. Be explicit about both what you want and what you want to avoid.\n- **Extended thinking:** Activated via API parameter or toggle in Claude.ai, not by prompt. Use it for complex reasoning, debugging, and multi-document analysis.\n- **Writing quality:** Give Claude a specific voice, style reference, or structural guidance. It produces less formulaic output than most models when given room.\n- **Artifacts:** In Claude.ai, ask for \"standalone\" or \"interactive\" outputs to get artifacts (code, HTML, diagrams) in a separate panel.\n- **Tiered instructions:** Structure complex prompts as goal (what) > rules (how) > examples (calibration). Claude respects the hierarchy.\n- **Negative instructions:** \"Do not\" instructions are followed reliably. Use them to prevent common AI output patterns you want to avoid.","content_length":11526,"generated_at":"2026-04-24"}