Skip to main content
ClaudeWave
Skill462 repo starsupdated 3d ago

Prompt Mastery

Prompt Mastery is a Claude Code skill providing comprehensive prompt engineering techniques specifically optimized for Claude models. Use it when designing system prompts, tool descriptions, agent instructions, or any complex prompt requiring sophisticated engineering. It distills current best practices, Claude-specific techniques from Anthropic, and iterative refinement strategies to ensure prompts produce accurate, relevant, and actionable outputs across a wide range of LLM tasks.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/taylorsatula/mira-OSS /tmp/prompt-mastery && cp -r /tmp/prompt-mastery/.claude/skills/prompt-mastery ~/.claude/skills/prompt-mastery
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Prompt Mastery: Advanced LLM Prompt Engineering Skill

**Purpose**: This skill provides comprehensive prompt engineering expertise, distilling cutting-edge research, best practices, and battle-tested techniques for crafting highly effective prompts for Large Language Models, with special emphasis on Claude.

**When to invoke**: Use this skill when creating system prompts, tool descriptions, agent instructions, or any situation requiring sophisticated prompt design. Invoke before writing any significant prompts to leverage advanced techniques.

---

## 🎯 Core Principles

### The Fundamentals (Never Violate These)

1. **Clarity Over Cleverness**: Clear, explicit instructions consistently outperform clever wordplay
2. **Specificity Beats Vagueness**: Precise requirements produce better results than general requests
3. **Context is Currency**: Provide enough background for the model to understand the task deeply
4. **Structure Reduces Ambiguity**: Well-structured prompts eliminate confusion
5. **Iteration is Essential**: First prompts rarely achieve perfection—treat prompting as iterative

### The 2025 Paradigm Shift

Modern prompt engineering isn't about asking questions—it's about **designing the question space** that guides models toward accurate, relevant, and actionable outputs. Context engineering enables you to shape not just what you ask, but how the model interprets and responds.

---

## 🔷 Claude-Specific Techniques

### Official Anthropic Best Practices (2025)

#### 1. **Be Clear and Explicit**
Claude 4 models (Sonnet 4.5, Sonnet 4, Haiku 4.5, Opus 4.1, Opus 4) respond best to clear, explicit instructions. If you want "above and beyond" behavior, explicitly request it—don't assume the model will infer it.

```xml
<!-- GOOD: Explicit and clear -->
<instruction>
Analyze this code for security vulnerabilities. Provide:
1. A severity rating (Critical/High/Medium/Low)
2. Specific line numbers where issues occur
3. Concrete remediation steps with code examples
4. Explanation of the attack vector
</instruction>

<!-- BAD: Vague and implicit -->
<instruction>
Look at this code and tell me if there are any problems.
</instruction>
```

#### 2. **Provide Context and Motivation**
Explaining **why** a behavior is important helps Claude understand your goals and deliver more targeted responses.

```xml
<context>
We're building a medical diagnosis system where accuracy is critical.
False positives can cause unnecessary anxiety, while false negatives
could delay treatment. We need responses that:
- Cite specific medical literature when making claims
- Express uncertainty appropriately
- Never provide definitive diagnoses (legal requirement)
</context>
```

#### 3. **Use XML Tags for Structure**
Claude was trained with XML tags, so they provide exceptional control over output structure and interpretation.

```xml
<task>
Analyze the following customer feedback and extract insights.
</task>

<feedback>
[Customer feedback text here]
</feedback>

<output_format>
- sentiment: positive/negative/neutral
- key_themes: list of main topics
- action_items: specific recommendations
- urgency: high/medium/low
</output_format>

<guidelines>
- Focus on actionable insights
- Distinguish between individual complaints and systemic issues
- Flag any mentions of competitors
</guidelines>
```

#### 4. **Leverage Thinking Capabilities**
Claude 4 offers thinking capabilities for reflection after tool use or complex multi-step reasoning. Guide initial or interleaved thinking for better results.

```xml
<thinking_instructions>
Before answering:
1. Identify what type of problem this is (optimization, debugging, architecture)
2. Consider edge cases that might break the obvious solution
3. Evaluate tradeoffs between performance, maintainability, and complexity
4. Only then propose your approach
</thinking_instructions>
```

#### 5. **Instruction Placement Matters**
Claude follows instructions in **human messages** (user prompts) better than those in the system message. Place critical requirements in the user message.

```python
# BETTER: Critical instructions in user message
messages = [
    {"role": "system", "content": "You are a helpful coding assistant."},
    {"role": "user", "content": """
    Write a Python function to calculate Fibonacci numbers.

    CRITICAL REQUIREMENTS:
    - Use memoization for efficiency
    - Include type hints
    - Add comprehensive docstrings
    - Handle edge cases (n=0, n=1, negative n)
    """}
]

# WORSE: Critical instructions only in system message
messages = [
    {"role": "system", "content": """
    You are a helpful coding assistant.
    Always use memoization, type hints, docstrings, and handle edge cases.
    """},
    {"role": "user", "content": "Write a Python function to calculate Fibonacci numbers."}
]
```

#### 6. **Prefill Claude's Response** (Powerful Technique!)
Guide Claude by starting the Assistant message with desired initial text. This skips preambles, enforces formats, and increases control.

```python
# Force JSON output by prefilling
messages = [
    {"role": "user", "content": "Extract key entities from: 'Apple announced the iPhone 15 in Cupertino on Sept 12.'"},
    {"role": "assistant", "content": "{"}  # Prefill starts JSON
]
# Claude continues: "entities": [{"name": "Apple", "type": "company"}, ...]
```

**Use cases for prefilling**:
- Skip preambles: Start with your desired first word
- Enforce JSON/XML: Begin with `{` or `<`
- Maintain character in roleplay: Start with character voice
- Control tone: Begin with desired emotional register

**Limitation**: Prefilling doesn't work with extended thinking mode.

---

## 🚀 Advanced Prompting Techniques

### Chain-of-Thought (CoT) Prompting

CoT enhances reasoning by incorporating logical steps within the prompt, making models more adept at complex tasks.

```xml
<example_problem>
Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls.
Each can has 3 tennis balls. How many tennis balls does
code-renamerSubagent

Use this agent when you need to rename classes, methods, functions, or variables in code files to align with specific naming requirements or conventions. Examples: <example>Context: User wants to clean up function names by removing a specific prefix. user: 'Please remove the prefix get_ from all function names in this file' assistant: 'I'll use the code-renamer agent to systematically rename all functions by removing the get_ prefix' <commentary>The user wants systematic renaming of functions, which is exactly what the code-renamer agent is designed for.</commentary></example> <example>Context: User wants to standardize method naming conventions. user: 'Can you rename all the camelCase methods to snake_case in this class?' assistant: 'I'll use the code-renamer agent to convert all camelCase method names to snake_case convention' <commentary>This is a systematic renaming task that requires careful attention to naming conventions.</commentary></example>

investigative-sidekickSubagent

Use this agent when the user makes offhanded comments, rhetorical questions, or expresses wishes about understanding something better. Trigger on patterns like:\n\n<example>\nContext: User is reviewing code and sees an assistant's explanation about how a function works.\nuser: "Can you believe this? Is this even right?"\nassistant: "Let me use the investigative-sidekick agent to verify if that explanation is accurate."\n<task tool_call to investigative-sidekick with context about what needs verification>\n</example>\n\n<example>\nContext: User is debugging and expresses frustration.\nuser: "I wish I could figure out what's causing this memory leak in the session handler"\nassistant: "I'll use the investigative-sidekick agent to investigate the root cause of that memory leak."\n<task tool_call to investigative-sidekick with the specific problem to investigate>\n</example>\n\n<example>\nContext: User reads a commit message claiming a performance improvement.\nuser: "Did this actually make things faster though?"\nassistant: "Let me launch the investigative-sidekick agent to verify that performance claim."\n<task tool_call to investigative-sidekick to fact-check the performance assertion>\n</example>\n\n<example>\nContext: User is reviewing documentation that seems questionable.\nuser: "This doesn't seem right - are we really supposed to use sync calls in async contexts?"\nassistant: "I'm going to use the investigative-sidekick agent to investigate whether that's actually correct."\n<task tool_call to investigative-sidekick to verify the technical claim>\n</example>\n\nActivate proactively when the user:\n- Questions accuracy or truthfulness ("Can you believe...", "Is this right?", "Really?")\n- Expresses wishes about understanding ("I wish I could figure out...", "I'd love to know...")\n- Shows skepticism ("Did this actually...", "Does this really...")\n- Makes rhetorical questions that imply investigation ("What's causing...", "Why is this...")\n- Doubts explanations or documentation they're reading

thinkSlash Command

Control thinking token limits via environment variable

validate-moduleSlash Command

Run complete two-agent validation on module+tests (contract extraction + test validation). Binary pass/fail with specific issues.

Code Consistency - Logging & StandardsSkill

Check Python logging levels and patterns for correctness. Focus on identifying wrong severity levels and missing exception handling. Use when reviewing code quality.

contextvar-opportunity-finderSkill

Detect explicit user_id parameters in functions to identify potential opportunities for using ambient context. This is an investigation tool that flags instances for human review, not a prescriptive analyzer.

contextvar-remediationSkill
fail-fast-no-hedgingSkill

Eliminate component hedging anti-patterns that mask infrastructure failures. Build systems that fail loudly when broken instead of limping along in degraded states. Critical for production reliability and operational visibility.