File: prompt-engineering.md | Updated: 11/15/2025
Agent Skills are now available! Learn more about extending Claude's capabilities with Agent Skills .
English
Search...
Ctrl K
Search...
Navigation
Build with Claude
Prompting best practices
Home Developer Guide API Reference Model Context Protocol (MCP) Resources Release Notes
On this page
This guide provides specific prompt engineering techniques for Claude 4.x models, with specific guidance for Sonnet 4.5 and Haiku 4.5. These models have been trained for more precise instruction following than previous generations of Claude models.
For an overview of Claude 4.5’s new capabilities, see What’s new in Claude 4.5 . For migration guidance from previous models, see Migrating to Claude 4.5 .
Be explicit with your instructions
Claude 4.x models respond well to clear, explicit instructions. Being specific about your desired output can help enhance results. Customers who desire the “above and beyond” behavior from previous Claude models might need to more explicitly request these behaviors with newer models.Example: Creating an analytics dashboard
Less effective:
Copy
Create an analytics dashboard
More effective:
Copy
Create an analytics dashboard. Include as many relevant features and interactions as possible. Go beyond the basics to create a fully-featured implementation.
Add context to improve performance
Providing context or motivation behind your instructions, such as explaining to Claude why such behavior is important, can help Claude 4.x models better understand your goals and deliver more targeted responses.Example: Formatting preferences
Less effective:
Copy
NEVER use ellipses
More effective:
Copy
Your response will be read aloud by a text-to-speech engine, so never use ellipses since the text-to-speech engine will not know how to pronounce them.
Claude is smart enough to generalize from the explanation.
Be vigilant with examples & details
Claude 4.x models pay close attention to details and examples as part of their precise instruction following capabilities. Ensure that your examples align with the behaviors you want to encourage and minimize behaviors you want to avoid.
Long-horizon reasoning and state tracking
Claude 4.5 models excel at long-horizon reasoning tasks with exceptional state tracking capabilities. It maintains orientation across extended sessions by focusing on incremental progress—making steady advances on a few things at a time rather than attempting everything at once. This capability especially emerges over multiple context windows or task iterations, where Claude can work on a complex task, save the state, and continue with a fresh context window.
Context awareness and multi-window workflows
Claude 4.5 models feature context awareness , enabling the model to track its remaining context window (i.e. “token budget”) throughout a conversation. This enables Claude to execute tasks and manage context more effectively by understanding how much space it has to work. Managing context limits: If you are using Claude in an agent harness that compacts context or allows saving context to external files (like in Claude Code), we suggest adding this information to your prompt so Claude can behave accordingly. Otherwise, Claude may sometimes naturally try to wrap up work as it approaches the context limit. Below is an example prompt:
Sample prompt
Copy
Your context window will be automatically compacted as it approaches its limit, allowing you to continue working indefinitely from where you left off. Therefore, do not stop tasks early due to token budget concerns. As you approach your token budget limit, save your current progress and state to memory before the context window refreshes. Always be as persistent and autonomous as possible and complete tasks fully, even if the end of your budget is approaching. Never artificially stop any task early regardless of the context remaining.
The memory tool pairs naturally with context awareness for seamless context transitions.
Multi-context window workflows
For tasks spanning multiple context windows:
tests.json). This leads to better long-term ability to iterate. Remind Claude of the importance of tests: “It is unacceptable to remove or edit tests because this could lead to missing or buggy functionality.”init.sh) to gracefully start servers, run test suites, and linters. This prevents repeated work when continuing from a fresh context window.Sample prompt
Copy
This is a very long task, so it may be beneficial to plan out your work clearly. It's encouraged to spend your entire output context working on the task - just make sure you don't run out of context with significant uncommitted work. Continue working systematically until you have completed this task.
State management best practices
Example: State tracking
Copy
// Structured state file (tests.json)
{
"tests": [\
{"id": 1, "name": "authentication_flow", "status": "passing"},\
{"id": 2, "name": "user_management", "status": "failing"},\
{"id": 3, "name": "api_endpoints", "status": "not_started"}\
],
"total": 200,
"passing": 150,
"failing": 25,
"not_started": 25
}
Copy
// Progress notes (progress.txt)
Session 3 progress:
- Fixed authentication token validation
- Updated user model to handle edge cases
- Next: investigate user_management test failures (test #2)
- Note: Do not remove tests as this could lead to missing functionality
Communication style
Claude 4.5 models have a more concise and natural communication style compared to previous models:
This communication style accurately reflects what has been accomplished without unnecessary elaboration.
Balance verbosity
Claude 4.5 models tend toward efficiency and may skip verbal summaries after tool calls, jumping directly to the next action. While this creates a streamlined workflow, you may prefer more visibility into its reasoning process. If you want Claude to provide updates as it works:
Sample prompt
Copy
After completing a task that involves tool use, provide a quick summary of the work you've done.
Tool usage patterns
Claude 4.5 models are trained for precise instruction following and benefits from explicit direction to use specific tools. If you say “can you suggest some changes,” it will sometimes provide suggestions rather than implementing them—even if making changes might be what you intended. For Claude to take action, be more explicit:Example: Explicit instructions
Less effective (Claude will only suggest):
Copy
Can you suggest some changes to improve this function?
More effective (Claude will make the changes):
Copy
Change this function to improve its performance.
Or:
Copy
Make these edits to the authentication flow.
To make Claude more proactive about taking action by default, you can add this to your system prompt:
Sample prompt for proactive action
Copy
<default_to_action>
By default, implement changes rather than only suggesting them. If the user's intent is unclear, infer the most useful likely action and proceed, using tools to discover any missing details instead of guessing. Try to infer the user's intent about whether a tool call (e.g., file edit or read) is intended or not, and act accordingly.
</default_to_action>
On the other hand, if you want the model to be more hesitant by default, less prone to jumping straight into implementations, and only take action if requested, you can steer this behavior with a prompt like the below:
Sample prompt for conservative action
Copy
<do_not_act_before_instructions>
Do not jump into implementatation or changes files unless clearly instructed to make changes. When the user's intent is ambiguous, default to providing information, doing research, and providing recommendations rather than taking action. Only proceed with edits, modifications, or implementations when the user explicitly requests them.
</do_not_act_before_instructions>
Control the format of responses
There are a few ways that we have found to be particularly effective in steering output formatting in Claude 4.x models:
Sample prompt to minimize markdown
Copy
<avoid_excessive_markdown_and_bullet_points>
When writing reports, documents, technical explanations, analyses, or any long-form content, write in clear, flowing prose using complete paragraphs and sentences. Use standard paragraph breaks for organization and reserve markdown primarily for `inline code`, code blocks (```...```), and simple headings (###, and ###). Avoid using **bold** and *italics*.
DO NOT use ordered lists (1. ...) or unordered lists (*) unless : a) you're presenting truly discrete items where a list format is the best option, or b) the user explicitly requests a list or ranking
Instead of listing items with bullets or numbers, incorporate them naturally into sentences. This guidance applies especially to technical writing. Using prose instead of excessive formatting will improve user satisfaction. NEVER output a series of overly short bullet points.
Your goal is readable, flowing text that guides the reader naturally through ideas rather than fragmenting information into isolated points.
</avoid_excessive_markdown_and_bullet_points>
Research and information gathering
Claude 4.5 models demonstrate exceptional agentic search capabilities and can find and synthesize information from multiple sources effectively. For optimal research results:
Sample prompt for complex research
Copy
Search for this information in a structured way. As you gather data, develop several competing hypotheses. Track your confidence levels in your progress notes to improve calibration. Regularly self-critique your approach and plan. Update a hypothesis tree or research notes file to persist information and provide transparency. Break down this complex research task systematically.
This structured approach allows Claude to find and synthesize virtually any piece of information and iteratively critique its findings, no matter the size of the corpus.
Subagent orchestration
Claude 4.5 models demonstrate significantly improved native subagent orchestration capabilities. These models can recognize when tasks would benefit from delegating work to specialized subagents and do so proactively without requiring explicit instruction. To take advantage of this behavior:
Sample prompt for conservative subagent usage
Copy
Only delegate to subagents when the task clearly benefits from a separate agent with a new context window.
Model self-knowledge
If you would like Claude to identify itself correctly in your application or use specific API strings:
Sample prompt for model identity
Copy
The assistant is Claude, created by Anthropic. The current model is Claude Sonnet 4.5.
For LLM-powered apps that need to specify model strings:
Sample prompt for model string
Copy
When an LLM is needed, please default to Claude Sonnet 4.5 unless the user requests otherwise. The exact model string for Claude Sonnet 4.5 is claude-sonnet-4-5-20250929.
Leverage thinking & interleaved thinking capabilities
Claude 4.x models offer thinking capabilities that can be especially helpful for tasks involving reflection after tool use or complex multi-step reasoning. You can guide its initial or interleaved thinking for better results.
Example prompt
Copy
After receiving tool results, carefully reflect on their quality and determine optimal next steps before proceeding. Use your thinking to plan and iterate based on this new information, and then take the best next action.
For more information on thinking capabilities, see Extended thinking .
Document creation
Claude 4.5 models excel at creating presentations, animations, and visual documents. These models match or exceed Claude Opus 4.1 in this domain, with impressive creative flair and stronger instruction following. The models produce polished, usable output on the first try in most cases. For best results with document creation:
Sample prompt
Copy
Create a professional presentation on [topic]. Include thoughtful design elements, visual hierarchy, and engaging animations where appropriate.
Optimize parallel tool calling
Claude 4.x models excel at parallel tool execution, with Sonnet 4.5 being particularly aggressive in firing off multiple operations simultaneously. Claude 4.x models will:
This behavior is easily steerable. While the model has a high success rate in parallel tool calling without prompting, you can boost this to ~100% or adjust the aggression level:
Sample prompt for maximum parallel efficiency
Copy
<use_parallel_tool_calls>
If you intend to call multiple tools and there are no dependencies between the tool calls, make all of the independent tool calls in parallel. Prioritize calling tools simultaneously whenever the actions can be done in parallel rather than sequentially. For example, when reading 3 files, run 3 tool calls in parallel to read all 3 files into context at the same time. Maximize use of parallel tool calls where possible to increase speed and efficiency. However, if some tool calls depend on previous calls to inform dependent values like the parameters, do NOT call these tools in parallel and instead call them sequentially. Never use placeholders or guess missing parameters in tool calls.
</use_parallel_tool_calls>
Sample prompt to reduce parallel execution
Copy
Execute operations sequentially with brief pauses between each step to ensure stability.
Reduce file creation in agentic coding
Claude 4.x models may sometimes create new files for testing and iteration purposes, particularly when working with code. This approach allows Claude to use files, especially python scripts, as a ‘temporary scratchpad’ before saving its final output. Using temporary files can improve outcomes particularly for agentic coding use cases. If you’d prefer to minimize net new file creation, you can instruct Claude to clean up after itself:
Sample prompt
Copy
If you create any temporary new files, scripts, or helper files for iteration, clean up these files by removing them at the end of the task.
Enhance visual and frontend code generation
Claude 4.x models can generate high-quality, visually distinctive, functional user interfaces. However, without guidance, frontend code can default to generic patterns that lack visual interest. To elicit exceptional UI results:
Sample prompt
Copy
Don't hold back. Give it your all. Create an impressive demonstration showcasing web development capabilities.
2. Specify aesthetic direction and design constraints:
Sample prompt
Copy
Create a professional dashboard using a dark blue and cyan color palette, modern sans-serif typography (e.g., Inter for headings, system fonts for body), and card-based layouts with subtle shadows. Include thoughtful details like hover states, transitions, and micro-interactions. Apply design principles: hierarchy, contrast, balance, and movement.
3. Encourage design diversity and fusion aesthetics:
Sample prompt
Copy
Provide multiple design options. Create fusion aesthetics by combining elements from different sources—one color scheme, different typography, another layout principle. Avoid generic centered layouts, simplistic gradients, and uniform styling.
4. Request specific features explicitly:
Avoid focusing on passing tests and hard-coding
Claude 4.x models can sometimes focus too heavily on making tests pass at the expense of more general solutions, or may use workarounds like helper scripts for complex refactoring instead of using standard tools directly. To prevent this behavior and ensure robust, generalizable solutions:
Sample prompt
Copy
Please write a high-quality, general-purpose solution using the standard tools available. Do not create helper scripts or workarounds to accomplish the task more efficiently. Implement a solution that works correctly for all valid inputs, not just the test cases. Do not hard-code values or create solutions that only work for specific test inputs. Instead, implement the actual logic that solves the problem generally.
Focus on understanding the problem requirements and implementing the correct algorithm. Tests are there to verify correctness, not to define the solution. Provide a principled implementation that follows best practices and software design principles.
If the task is unreasonable or infeasible, or if any of the tests are incorrect, please inform me rather than working around them. The solution should be robust, maintainable, and extendable.
Minimizing hallucinations in agentic coding
Claude 4.x models are less prone to hallucinations and give more accurate, grounded, intelligent answers based on the code. To encourage this behavior even more and minimize hallucinations:
Sample prompt
Copy
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file, you MUST read the file before answering. Make sure to investigate and read relevant files BEFORE answering questions about the codebase. Never make any claims about code before investigating unless you are certain of the correct answer - give grounded and hallucination-free answers.
</investigate_before_answering>
When migrating to Claude 4.5 models:
Was this page helpful?
YesNo
Context windows Prompt caching
Assistant
Responses are generated using AI and may contain mistakes.
Directory listing - 14 item(s) total