Your First Prompt
Let’s create your first custom prompt with SwissArmyHammer! This guide will walk you through creating a useful code review prompt.
Understanding Prompt Structure
SwissArmyHammer prompts are markdown files with YAML front matter. Here’s the basic structure:
---
title: Your Prompt Title
description: What this prompt does
arguments:
- name: argument_name
description: What this argument is for
required: true/false
default: "optional default value"
---
# Your Prompt Content
Use {{argument_name}} to insert variables into your prompt.
Creating a Code Review Prompt
Let’s create a practical code review prompt step by step.
Step 1: Create the File
First, create a new prompt file in your prompts directory:
# Create the file
touch ~/.swissarmyhammer/prompts/code-review.md
# Or create a category directory
mkdir -p ~/.swissarmyhammer/prompts/development
touch ~/.swissarmyhammer/prompts/development/code-review.md
Step 2: Add the YAML Front Matter
Open the file in your favorite editor and add the front matter:
---
title: Code Review Assistant
description: Comprehensive code review with focus on best practices, security, and performance
arguments:
- name: code
description: The code to review (can be a function, class, or entire file)
required: true
- name: language
description: Programming language (helps with language-specific advice)
required: false
default: "auto-detect"
- name: focus
description: Areas to focus on (security, performance, readability, etc.)
required: false
default: "general best practices"
---
Step 3: Write the Prompt Content
Below the front matter, add the prompt content:
# Code Review
I need a thorough code review for the following {{language}} code.
## Code to Review
```{{language}}
{{code}}
Review Focus
Please focus on: {{focus}}
Review Criteria
Please analyze the code for:
🔒 Security
- Potential security vulnerabilities
- Input validation issues
- Authentication/authorization concerns
🚀 Performance
- Inefficient algorithms or operations
- Memory usage concerns
- Potential bottlenecks
📖 Readability & Maintainability
- Code clarity and organization
- Naming conventions
- Documentation needs
🧪 Testing & Reliability
- Error handling
- Edge cases
- Testability
🏗️ Architecture & Design
- SOLID principles adherence
- Design patterns usage
- Code structure
Output Format
Please provide:
- Overall Assessment - Brief summary of code quality
- Specific Issues - List each issue with:
- Severity (High/Medium/Low)
- Location (line numbers if applicable)
- Explanation of the problem
- Suggested fix
- Positive Aspects - What’s done well
- Recommendations - Broader suggestions for improvement
Focus especially on {{focus}} in your analysis.
### Step 4: Complete File Example
Here's the complete prompt file:
```markdown
---
title: Code Review Assistant
description: Comprehensive code review with focus on best practices, security, and performance
arguments:
- name: code
description: The code to review (can be a function, class, or entire file)
required: true
- name: language
description: Programming language (helps with language-specific advice)
required: false
default: "auto-detect"
- name: focus
description: Areas to focus on (security, performance, readability, etc.)
required: false
default: "general best practices"
---
# Code Review
I need a thorough code review for the following {{language}} code.
## Code to Review
```{{language}}
{{code}}
Review Focus
Please focus on: {{focus}}
Review Criteria
Please analyze the code for:
🔒 Security
- Potential security vulnerabilities
- Input validation issues
- Authentication/authorization concerns
🚀 Performance
- Inefficient algorithms or operations
- Memory usage concerns
- Potential bottlenecks
📖 Readability & Maintainability
- Code clarity and organization
- Naming conventions
- Documentation needs
🧪 Testing & Reliability
- Error handling
- Edge cases
- Testability
🏗️ Architecture & Design
- SOLID principles adherence
- Design patterns usage
- Code structure
Output Format
Please provide:
- Overall Assessment - Brief summary of code quality
- Specific Issues - List each issue with:
- Severity (High/Medium/Low)
- Location (line numbers if applicable)
- Explanation of the problem
- Suggested fix
- Positive Aspects - What’s done well
- Recommendations - Broader suggestions for improvement
Focus especially on {{focus}} in your analysis.
## Step 5: Test Your Prompt
Save the file and test that SwissArmyHammer can load it:
```bash
# Check if your prompt loads correctly
swissarmyhammer doctor
The doctor command will validate your YAML syntax and confirm the prompt is loaded.
Step 6: Use Your Prompt
- Open Claude Code
- Start a new conversation
- Look for your prompt in the prompt picker - it should appear as “Code Review Assistant”
- Fill in the parameters:
code
: Paste some code you want reviewedlanguage
: Specify the programming language (optional)focus
: Specify what to focus on (optional)
Understanding What Happened
When you created this prompt, SwissArmyHammer:
- Detected the new file using its file watcher
- Parsed the YAML front matter to understand the prompt structure
- Made it available to Claude Code via the MCP protocol
- Prepared for template substitution when the prompt is used
Best Practices for Your First Prompt
✅ Do’s
- Use descriptive titles and descriptions
- Document your arguments clearly
- Provide sensible defaults for optional arguments
- Structure your prompt content with clear sections
- Use template variables to make prompts flexible
❌ Don’ts
- Don’t use required arguments unless necessary
- Don’t make prompts too rigid - allow for flexibility
- Don’t forget to test your YAML syntax
- Don’t use overly complex template logic in your first prompts
Next Steps
Now that you’ve created your first prompt, you can:
- Create more prompts for different use cases
- Organize prompts into directories by category
- Learn advanced template features like conditionals and loops
- Share prompts with your team or the community
Recommended Reading
- Creating Prompts - Comprehensive guide to prompt creation
- Template Variables - Advanced template features
- Prompt Organization - How to organize your prompt library
- Built-in Prompts - Examples from the built-in library
Troubleshooting
If your prompt isn’t working:
- Check YAML syntax - Make sure your front matter is valid YAML
- Run doctor -
swissarmyhammer doctor
will catch common issues - Check file permissions - Make sure SwissArmyHammer can read the file
- Restart Claude Code - Sometimes needed after creating new prompts
Common issues:
- YAML indentation errors - Use spaces, not tabs
- Missing required fields - Title and description are required
- Invalid argument structure - Check the argument format
- File encoding - Use UTF-8 encoding for your markdown files