Prompt Patterns
Long Context Prompt Patterns for Claude
How to structure long Claude prompts with source packets, XML sections, query placement, quote extraction, and token budgets.
"XML tags help Claude parse complex prompts unambiguously."
Source: Prompting best practices, Claude Platform Docs.
Build a source packet, not a paste pile
A source packet is a deliberate bundle of context. It names each document, gives provenance, includes timestamps, and separates content from instructions. That structure helps Claude distinguish evidence from task rules and reduces the chance that source text is accidentally treated as an instruction.
For long tasks, put the source packet near the top, then put the user's question and output requirements after it. This keeps the model grounded in the data while making the actual task clear at the end.
Use semantic sections
Anthropic's prompt guidance recommends XML-style tags for complex prompts. The exact tag names are less important than consistency and clarity. Use names that reflect the role of each block: `
<sources>
<document id="api-docs" source="Claude Platform Docs" updated="2026-07-06">
<summary>Context-window behavior, token accounting, and compaction links.</summary>
<excerpt>Short, relevant excerpt or structured notes go here.</excerpt>
</document>
</sources>
<instructions>
Answer only from the sources above. If the sources do not establish a fact, say so.
</instructions>
<question>
What counts toward the context window in this workflow?
</question> Ask for evidence before synthesis
For long-document work, ask Claude to identify the relevant source lines or short quoted phrases before writing the final answer. This is not about exposing hidden reasoning. It is about grounding the response in visible evidence and making it easier to detect when the wrong section drove the answer.
Reserve output budget
Do not fill the entire window with input. The response itself needs room. If you expect a detailed report, reserve enough output capacity and shorten the input accordingly. Token counting should happen before the final request, especially when the source packet is built automatically.
FAQ
Are XML tags required for Claude?
No. They are a useful structuring convention. Clear Markdown sections can also work, but XML tags are explicit when prompts mix sources, examples, instructions, and user input.
Should I quote entire source documents into Claude?
Only when the task needs full-document reasoning. Otherwise, use summaries, excerpts, retrieval, or MCP resources with provenance.
Sources Used
- Prompting best practices, Claude Platform Docs. Accessed 2026-07-06. Official guidance on clear instructions, examples, XML sections, long-context prompting, and tool-use prompting.
- Context windows, Claude Platform Docs. Accessed 2026-07-06. Official context-window behavior, token accumulation, extended thinking and tool-use accounting, and compaction guidance.
- Token counting, Claude Platform Docs. Accessed 2026-07-06. Official endpoint guidance for estimating input tokens, costs, rate limits, and model routing.
Cite this page
Suggested citation: Claude Context, "Long Context Prompt Patterns for Claude," updated 2026-07-06, https://claudecontext-com.pages.dev/long-context-prompts/.
This page is an independent educational resource and is not affiliated with Anthropic.