Prompt Engineering for Claude
How you phrase a request in the Claude Code chat panel determines the quality of what comes back. These principles work the same whether you are drafting copy, reviewing code, or planning a project. This module covers Claude-specific prompting techniques — many of which differ from what works best with other models.
The Five Core Principles
Give Claude a Role
Start your message with who Claude should be: "Act as ThreadCo's brand copywriter — friendly, direct, never corporate." This calibrates tone, vocabulary, and depth without you having to specify every constraint. Roles work because they activate clusters of related training data — a "senior security engineer" role produces different code review feedback than a "junior developer" role, even on the same code.
Add Context with @files
Instead of pasting content into the chat, type @brandguide.md or @returns-policy.pdf. Claude reads the file directly. The more relevant context you attach, the more precise the output. Claude handles multiple attached files well — you can attach 5-10 files in a single message without degradation.
Specify the Output Format
Never leave format to chance. Say exactly what you want: "Respond with a bullet list of 5 items, each under 15 words" or "Write two sentences only. No headings. No bullet points." Claude follows format instructions more precisely than most models — use this to your advantage.
Use Negative Constraints
"Do not use the words vibrant, perfect, or stylish. Do not use exclamation marks." Negative constraints are as powerful as positive ones — they cut exactly what you don't want. Claude is particularly good at respecting negative constraints compared to other models.
Ask for Reasoning First
For complex tasks, add "Think through this step by step before answering." Claude reasons out loud, which surfaces assumptions you can correct before the final output is produced. This is especially valuable for code architecture decisions, business analysis, and any task with multiple valid approaches.
Claude-Specific Prompting Techniques
Claude has particular strengths that you can exploit with the right prompting patterns. These techniques work better with Claude than with other models because of how Claude was trained.
XML Tags for Structure
Claude was specifically trained to understand XML-style tags as structural delimiters. Wrapping content in tags like <document>, <instructions>, or <examples> dramatically improves Claude's ability to distinguish between instructions and content. This is Claude's single most powerful unique technique.
Prefilled Responses
In the API, you can start Claude's response with specific text (prefill). In the chat panel, you can simulate this: "Start your response with 'Analysis:' and then..." This steers Claude's output format from the very first token and reduces drift.
Explicit Audience
Claude adjusts depth and vocabulary based on the stated audience. "Explain this to a non-technical CEO" vs "Explain this to a senior backend engineer" produces genuinely different explanations — not just simplified language, but different emphasis and examples.
Constitutional Alignment
Claude is trained to be helpful first. If your prompt is clear and well-intentioned, Claude leans toward giving you a complete, useful answer rather than hedging. You rarely need to "jailbreak" or work around safety — just be direct about what you need and why.
XML Tags — Claude's Secret Weapon
This is the single most important Claude-specific technique. When you wrap content in XML tags, Claude treats the tags as semantic boundaries. This prevents Claude from confusing your instructions with the content it is processing.
Analyse the following customer email and classify it. <email> Hi, I ordered the Sunset Gradient Tee two weeks ago and it still hasn't arrived. The tracking says it's been stuck in transit for 5 days. Can you help? I'm getting frustrated. </email> <classification_options> - complaint - question - praise - return_request - shipping_issue </classification_options> <output_format> Classification: [one of the options above] Urgency: [low / medium / high] Suggested action: [one sentence] </output_format>
Without XML tags, Claude might confuse the email content with the instructions, or mix up the classification options with the email text. With tags, each section is semantically isolated. Here are the most useful tag patterns:
| Tag | Purpose | Example |
|---|---|---|
<document> | Wrap any content Claude should analyse (not treat as instructions) | Contract text, email body, code to review |
<instructions> | Separate meta-instructions from the content being processed | How to format the output, what to focus on |
<examples> | Wrap few-shot examples so Claude knows they are examples, not targets | 2-3 sample outputs you want Claude to match |
<constraints> | Group restrictions that must be applied | Word limits, forbidden words, format rules |
<context> | Background information Claude should know but not repeat | Company background, project history |
<output_format> | Specify exactly what the response should look like | JSON schema, bullet template, table structure |
There is no fixed list of valid XML tags. You can use any tag name that makes semantic sense: <brand_voice>, <banned_words>, <customer_data>. Claude understands the meaning from the tag name. The tags just need to be well-formed (opening tag matches closing tag).
System Prompts and CLAUDE.md Best Practices
In the API, you set a system prompt explicitly. In Claude Code (VS Code), the CLAUDE.md file serves as your system prompt — it is read automatically at the start of every session. Here is how to write an effective one:
# Project: ThreadCo E-Commerce Platform
## Role
You are a senior full-stack developer working on ThreadCo's e-commerce platform.
You write TypeScript, follow our coding standards, and prioritise security.
## Coding Standards
- TypeScript strict mode. No `any` types.
- All async functions must have try/catch error handling.
- Tests required for all new functions (Jest, co-located in __tests__/).
- Use `const` over `let`. Never use `var`.
- Maximum function length: 30 lines. Extract helpers for longer logic.
## Brand Voice (for any customer-facing copy)
- Friendly, direct, slightly playful. Never corporate.
- Sustainability is a feature, not a badge — mention it naturally.
- Forbidden words: vibrant, perfect, stylish, must-have, luxurious
- No exclamation marks in product copy.
## Architecture
- Next.js 15 app router, PostgreSQL via Prisma, Stripe for payments.
- API routes in /app/api/. Server components by default.
- Environment variables in .env.local (never commit).
## Do Not
- Suggest paid third-party services without noting the cost.
- Modify database schema without confirming with the team.
- Skip error handling for "simplicity".
Avoid these common mistakes in CLAUDE.md / system prompts:
Too long: Over 1,000 words dilutes attention. Keep it under 500 words; link to detailed docs instead.
Too vague: "Write good code" is useless. Be specific: "Use TypeScript strict mode, no any types."
Contradictory rules: "Be concise" + "Be thorough and detailed" confuses the model. Pick a priority.
Repeating the obvious: "You are an AI assistant" wastes tokens. Claude already knows what it is.
Few-Shot Prompting — Teaching by Example
Few-shot prompting means providing 2-5 examples of the input-output pattern you want before giving Claude the actual task. This is one of the most reliable ways to get consistent, on-brand results.
Write product descriptions for ThreadCo tees. Match the style of these approved examples: <examples> <example> Product: Sunset Gradient Tee Description: Made from 100% organic cotton in Portugal, the Sunset Gradient fades from amber to rose across the chest. Relaxed fit, pre-shrunk, and softer after every wash. </example> <example> Product: Midnight Pocket Tee Description: A solid midnight-navy tee with a single chest pocket cut from the same organic jersey. Designed to be the tee you reach for first — no logos, no fuss, just a good fit. </example> </examples> <task> Now write a description for the Raindrop Dye Tee. It's a light blue tie-dye pattern, 100% organic cotton, unisex sizing, made in Portugal. </task>
Notice how the examples implicitly teach the style (2 sentences, mentions material and origin, no exclamation marks, sensory language) without you having to list every rule explicitly. Claude extracts the pattern from the examples.
ThreadCo in the Claude Code Chat Panel
| Weak prompt | Strong prompt | Why it's better |
|---|---|---|
| Write a product description | You are a ThreadCo copywriter. Write a 2-sentence description for @sunset-tee.md. No exclamation marks. Mention the organic cotton. | Role + context file + format + constraint |
| Fix this bug | @orders.ts line 42 is throwing a null reference error. The stack trace is below. Fix the root cause — don't just add a null check. | Exact location + error + intent |
| Summarise the emails | @emails-this-week.txt — identify the top 3 customer complaints. For each: one sentence summary, suggested action, and who owns it. | Source file + structured output format |
| Make this better | @homepage-copy.md — rewrite for clarity. Target: someone who has never heard of ThreadCo. Keep it under 80 words. Do not change the tone. | Audience + word limit + preservation constraint |
| Write some tests | Write Jest tests for @cart.ts. Cover: happy path (add item, update quantity, remove item), empty cart, invalid product ID, and quantity of zero. Use describe/it blocks. | Framework + specific scenarios + structure |
| Review this code | Review @webhook-handler.ts for security issues. Focus on: input validation, authentication, rate limiting. Rate each issue Critical/High/Medium/Low. Suggest fixes with code. | Scope + focus areas + severity framework + actionable output |
Common Pitfalls When Prompting Claude
Claude has specific tendencies that differ from other models. Knowing these pitfalls saves you debugging time:
Being Too Polite Wastes Tokens
You don't need "Please could you kindly..." — Claude responds equally well to direct instructions. "Summarise this in 3 bullets" is better than "Would you be so kind as to provide a brief summary in bullet point format, please?" Save the tokens for actual context.
Claude Over-Caveats by Default
Claude tends to add disclaimers like "However, it's important to note..." and "Please keep in mind..." If you don't want these, say so explicitly: "Give the answer directly. No caveats, no disclaimers."
Ambiguous "It"
When you say "Fix it" or "Make it better" — Claude has to guess what "it" refers to. Be specific: "Fix the null reference on line 42 of @orders.ts" instead of "Fix it."
Overloading One Prompt
Asking Claude to "write, test, document, and deploy" in one message often produces mediocre results on all four. Break complex tasks into sequential steps. Each step gets Claude's full attention.
Telling Claude to "be creative" often produces worse results than giving it specific constraints. Creativity flourishes within boundaries. "Write a product description using a weather metaphor, exactly 2 sentences, mentioning organic cotton" produces more creative output than "Be creative and write a product description." Constraints force Claude to find novel solutions within a defined space.
Advanced Prompting Patterns
Chain of Verification
After Claude generates output, add a follow-up: "Now check your own answer for errors, inconsistencies, or anything that violates the constraints I gave you." Claude is surprisingly good at catching its own mistakes when explicitly asked to self-review.
Perspective Shifting
"You just wrote this product description. Now read it as a first-time customer who has never heard of ThreadCo. What questions would you have? What's unclear?" Asking Claude to shift perspective surfaces blind spots in the original output.
Constraint Stacking
Layer constraints progressively across turns: Turn 1 gets the core content right. Turn 2 adds the tone constraint. Turn 3 adds the format constraint. This is easier to debug than a single prompt with 10 constraints.
Meta-Prompting
Ask Claude to help you write better prompts: "I need to write a prompt that will consistently generate product descriptions in ThreadCo's voice. What information do you need from me to write that prompt?" Claude will ask you the right questions.
Reusable Prompt Templates
Save these as team resources — in a Notion doc, a prompts/ folder in your repo, or as custom slash commands:
Review @[FILE] for the following criteria:
1. Security vulnerabilities (especially input validation and auth)
2. Error handling (are all failure modes covered?)
3. Performance (any N+1 queries, unnecessary re-renders, or O(n^2) loops?)
4. Readability (clear names, appropriate comments, no magic numbers)
For each issue found:
- Severity: Critical / High / Medium / Low
- Location: file and line number
- Problem: one sentence
- Fix: code snippet showing the correction
You are a [ROLE] writing for [AUDIENCE].
<brand_voice>
[TONE DESCRIPTION]
Forbidden words: [LIST]
</brand_voice>
<examples>
[2-3 APPROVED EXAMPLES]
</examples>
<task>
Write [FORMAT] for [SUBJECT].
Length: [CONSTRAINT]
Must mention: [REQUIREMENTS]
Must avoid: [RESTRICTIONS]
</task>
Hands-On Exercises
Take a paragraph of text and ask Claude to summarise it. Then wrap the same paragraph in <document> tags and add your instructions in <instructions> tags. Compare the outputs. Notice how XML tags prevent Claude from confusing content with instructions, especially when the content itself contains instruction-like language.
Write 3 product descriptions you consider "perfect" for your brand. Use them as few-shot examples and ask Claude to write a 4th. Rate how closely it matches. Adjust your examples and try again. How many iterations does it take to get consistently on-brand output?
Start with a simple prompt: "Write a product description for a blue organic cotton tee." Then progressively add constraints across 4 turns: (1) exactly 2 sentences, (2) mention Portugal, (3) no exclamation marks, (4) use a sensory word in the first sentence. Notice how each constraint sharpens the output without losing quality.
Deliberately write a bad prompt: vague, no context, no format specification. Send it. Then rewrite it using the principles from this module and send the improved version. Compare the outputs side by side. Save both as a "before/after" example for your team.
Create a prompts/ folder in your project. Write 3 reusable prompt templates for tasks your team does regularly (e.g., code review, email drafting, bug report analysis). Test each template with real data. Refine until they consistently produce good results. Share with your team.