How to Prompt Claude (Opus, Sonnet, and Haiku)
A practical, docs-grounded guide to prompting Claude Opus, Sonnet, and Haiku — XML tags, thinking, caching, and tool use.
Claude rewards a specific prompting style: explicit instructions, structured input, and room to reason. This guide covers what's documented and current for Claude Opus 5, Claude Sonnet 5, and Claude Haiku 4.5, grounded in Anthropic's prompt engineering documentation. Comparing Claude to other model families first? Start at the top AI models hub or the complete guide to prompt engineering.
The current Claude lineup
Three model IDs cover the tiers most teams use:
- Claude Opus 5 (
claude-opus-5) — built for complex agentic coding and enterprise work: multi-file refactors, long-horizon agent loops, high-precision code review. It has a 1M-token context window and thinking on by default. - Claude Sonnet 5 (
claude-sonnet-5) — Anthropic's statedbest combination of speed and intelligence.
Near-Opus quality on coding and agentic tasks at a lower price point; also 1M context. - Claude Haiku 4.5 (
claude-haiku-4-5) — the fastest tier, described as havingnear-frontier intelligence
for its speed and cost. 200K context, 64K max output.
Above Opus sits Claude Fable 5 (claude-fable-5), Anthropic's most capable widely released model, aimed at the hardest reasoning and the longest-horizon autonomous agent work — reach for it only when Opus 5 genuinely isn't enough, since it's priced above Opus tier and runs slower.
Pick by workload: Opus 5 for the hardest coding/reasoning where quality dominates cost; Sonnet 5 as the default for most production work (Anthropic is running introductory pricing on it through August 31, 2026); Haiku 4.5 for high-volume, latency-sensitive, or simple classification/extraction. See the models overview for exact pricing and cutoffs.
Claude's core prompting preferences
Claude's documentation is explicit about what moves the needle, and it isn't exotic:
Be clear and direct. Treat Claude like a capable new hire with no context on your norms. State the desired output format, constraints, and — if you want above and beyond
effort — say so; Claude won't infer that from a vague ask. Anthropic's own framing: show the prompt to a colleague with minimal context and see if they'd be confused. If so, Claude will be too.
Structure prompts with XML tags. This is the closest thing to a Claude signature. When a prompt mixes instructions, context, examples, and variable input, wrap each in its own tag — <instructions>, <context>, <input> — so Claude doesn't have to guess where one section ends and another begins. Use consistent tag names and nest them when content has a natural hierarchy.
<role>
You are a support-ticket triager for a B2B SaaS product.
</role>
<instructions>
Read the ticket in <ticket> tags. Classify it as billing, bug, or feature_request.
Quote the sentence that drove your classification before giving your answer.
</instructions>
<ticket>
{{TICKET_TEXT}}
</ticket>
Set a role via the system prompt. Even one sentence — You are a helpful coding assistant specializing in Python
— focuses tone and behavior for the rest of the conversation.
Use multishot examples in <example> tags. Three to five well-chosen examples reliably steer format, tone, and structure more than lengthening the instructions. Make them relevant to the real task and diverse enough that Claude doesn't pick up an unintended pattern.
<examples>
<example>
<input>Invoice for last month never arrived.</input>
<output>billing</output>
</example>
<example>
<input>Export button does nothing on Safari.</input>
<output>bug</output>
</example>
</examples>
Extended thinking vs. adaptive thinking
The current generation differs meaningfully from older Claude models here. Opus 5 and Sonnet 5 don't support the old manual thinking: {type: "enabled", budget_tokens: N} mode at all — that flag errors on both. Instead they use adaptive thinking: Claude decides for itself when and how much to think, calibrated by query complexity and the effort parameter (low/medium/high/xhigh, high by default). Haiku 4.5 is the exception — it still uses classic extended thinking with an explicit budget_tokens, and has no adaptive mode.
What this means for prompting Opus/Sonnet: don't hand-script the reasoning. Anthropic's guidance is to prefer general instructions over prescriptive steps — think thoroughly
tends to out-perform a hand-written step-by-step plan, because Claude's own reasoning often exceeds what a human would prescribe. Use effort as your dial instead of a token budget: drop to low/medium for routine work (Opus 5 holds quality well at lower effort, so treat effort as your primary cost lever) and reserve xhigh for demanding multi-step coding or agentic runs. If Claude over-explores before answering, that's an effort problem, not a prompt problem — turn the dial down instead of instructing it to stop overthinking.
One gotcha on Opus 5: thinking can only be disabled at high effort or below, and running with it off occasionally leaks a stray tool-call description or an internal <thinking>-style tag into the visible response. If you need thinking disabled, give Claude explicit permission to say a brief sentence before a tool call rather than suppressing that impulse — see prompting reasoning models without fighting their reasoning for the broader pattern.
Prefilling — mostly retired on current models
Prefilling (seeding the start of Claude's response to force a format) is a well-known Claude technique, but it no longer works on Opus 5 or Sonnet 5 — a request with a prefilled final assistant turn returns a 400 error. It still works on Haiku 4.5 and older models.
messages: [
{"role": "user", "content": "Extract the invoice total as JSON."},
{"role": "assistant", "content": "{\"total\": "} // Haiku 4.5 only — 400s on Opus 5 / Sonnet 5
]
On Opus 5 and Sonnet 5, replace prefill with:
- Structured outputs (
output_config.formatwith a JSON schema) for forcing a shape — the direct successor to JSON-prefilling. - A direct instruction for skipping preambles:
Respond directly without preamble. Do not start with phrases like 'Here is...' or 'Based on...'.
- A tool with an enum field for forced classification labels.
Long-context tactics
For long documents or data-heavy inputs (Anthropic's own threshold: 20K+ tokens), structure matters more than for short prompts:
- Put the long content near the top of the prompt, above your instructions and query. Anthropic reports this measurably improves response quality — Claude's docs cite up to a 30% quality improvement on complex, multi-document inputs when the query comes last rather than first.
- Wrap each document in its own tags, with metadata as subtags:
<documents>
<document index="1">
<source>annual_report_2025.pdf</source>
<document_content>{{ANNUAL_REPORT}}</document_content>
</document>
</documents>
Analyze the report and identify Q3 focus areas.
- Ask Claude to quote relevant passages before answering. Having Claude pull quotes into a
<quotes>block first, then reason from those quotes, keeps it anchored to the source material instead of drifting into unsupported claims.
For the cost and latency side of long-context and repeated-prefix workloads, see prompt caching for cutting LLM cost and latency. The short version for Claude: prompt caching marks a cache_control breakpoint on a stable prefix (system prompt, tool definitions, a large document), and any exact-byte-match prefix on a later request is served at roughly a tenth of the input price. It's a strict prefix match — reordering tools, editing the system prompt, or interpolating a timestamp anywhere before your breakpoint invalidates everything after it, so keep volatile content after the last breakpoint.
Tool use
Claude expects tools defined with a name, a description, and a JSON Schema input_schema. The description is where the effort goes: Anthropic's guidance is to describe both what the tool does and when to call it — Call this when the user asks about current prices or recent events,
not just a statement of the function. If Claude under-uses a tool, tighten the trigger condition in its description before reaching for stronger system-prompt language.
Claude also runs independent tool calls in parallel by default at a high success rate; an explicit instruction (if there are no dependencies between calls, make them in parallel
) pushes that closer to 100%. If Claude is issuing more tool calls than the task needs, soften you MUST use this tool
language instead — current Claude models follow the system prompt closely enough that aggressive trigger language overshoots.
Common Claude-specific mistakes
- Carrying over prefill from older code. The single most common breakage moving to Opus 5 or Sonnet 5 — a prefilled last-assistant-turn message that worked six months ago now 400s.
- Skipping XML structure on mixed-content prompts. Instructions, examples, and documents run together in plain prose invite Claude to misparse which part is which.
- Over-prescribing the reasoning path. Step-by-step
think about X, then Y, then Z
scaffolding written for older models tends to constrain current Claude below what a general instruction plus adaptive thinking would produce. - Leftover
CRITICAL: you MUST
tool language. Written to overcome older models' reluctance, it now causes overtriggering; dial it back to a plainuse this when...
. - Assuming
temperaturestill shapes variety. Non-default sampling parameters are rejected on current models — steer tone and variety through the prompt instead. - Not budgeting for longer turns. Opus 5's default responses and narration run longer than prior models'; ask for brevity explicitly rather than assuming the old default.
Claude's prompting model — explicit instructions, XML structure, adaptive reasoning instead of scripted chains, and tool descriptions that state when not just what — is distinct enough from GPT-style prompting that porting a prompt directly rarely works well; see the GPT prompting guide if you're running both side by side. For the broader model-agnostic foundations these techniques sit on, the complete guide to prompt engineering in 2026 and the top AI models hub are the place to go next.