Lab 3.3: Workflow Automation
Module: 3.3 - Custom Slash Commands | ← SlidesDuration: 30 minutes Sample Project: hackathon-starter
Learning Objectives
By the end of this lab, you will be able to:
- Create custom slash commands for your project
- Use YAML frontmatter to configure commands
- Pass arguments to commands using $ARGUMENTS and $1, $2, $3
- Share commands with your team via
.claude/commands/
Prerequisites
- Completed Day 1-2 labs
- Understanding of Claude Code basics
- Familiarity with the hackathon-starter project
Why Custom Commands?
Your team has repetitive workflows:
- "Document this file and generate tests"
- "Review this code for security issues"
- "Create a new API endpoint with tests"
Custom slash commands encapsulate these workflows so anyone can run them.
Setup
# Navigate to the sample project
cd sample-projects/hackathon-starter
# Create the commands directory
mkdir -p .claude/commands
# Start Claude Code
claudeTask 1: Create Your First Command
Time: 10 minutes
Create a simple command that documents a file.
Create the file: .claude/commands/document.md
---
description: Generate documentation for a file
argument-hint: <filename>
---
Analyze the file $ARGUMENTS and generate:
1. A brief description of what it does
2. JSDoc comments for all exported functions
3. A usage example
Be concise and practical.Test it:
/document controllers/user.jsSuccess criteria:
- [ ] Command file created
- [ ] Command appears in
/help - [ ] Command generates documentation when run
Task 2: Add Tool Restrictions
Time: 10 minutes
Create a safer command that can only read files.
Create: .claude/commands/explain.md
---
description: Explain code without making changes
argument-hint: <filename>
allowed-tools: Read, Glob, Grep
---
Explain what the file $ARGUMENTS does.
Include:
1. High-level purpose
2. Key functions and their roles
3. Dependencies and relationships
4. One potential improvement
Do NOT modify any files.Test it:
/explain models/User.jsVerify: Claude should only read, not edit.
Success criteria:
- [ ] Command restricted to read-only tools
- [ ] Explanation generated without modifications
Task 3: Multi-Argument Command
Time: 10 minutes
Create a command that takes multiple arguments.
Create: .claude/commands/compare.md
---
description: Compare two files and explain differences
argument-hint: <file1> <file2>
allowed-tools: Read, Glob, Grep
---
Compare these two files:
- File 1: $1
- File 2: $2
Analyze:
1. Structural differences
2. Functional differences
3. Which approach is better and whyTest it:
/compare controllers/user.js controllers/api.jsSuccess criteria:
- [ ] Both arguments passed correctly
- [ ] Meaningful comparison generated
Command Locations
| Location | Scope | Use Case |
|---|---|---|
.claude/commands/ | Project | Team workflows, shared via git |
~/.claude/commands/ | Personal | Your personal shortcuts |
Note
Project commands override personal commands with the same name.
Frontmatter Options
---
description: Shown in /help
argument-hint: Shown in autocomplete
allowed-tools: Restrict which tools Claude can use
model: Override the model (e.g., claude-sonnet-4-20250514)
---Tips for Success
- Start simple - One task per command
- Use tool restrictions - Prevent unintended modifications
- Document well - Good descriptions help teammates
- Test thoroughly - Try edge cases before sharing
Troubleshooting
Command doesn't appear:
- Check file extension is
.md - Verify frontmatter syntax (no tabs, proper
---delimiters) - Restart Claude Code
Arguments not working:
- Use
$ARGUMENTSfor all args as one string - Use
$1,$2,$3for positional arguments
Tool restrictions ignored:
- Double-check
allowed-toolsspelling - Ensure tools are comma-separated
Stretch Goals
If you finish early:
- Create a
/new-featurecommand that scaffolds a new feature with tests - Create a
/security-checkcommand that audits a file for vulnerabilities - Create a
/pr-summarycommand that generates PR descriptions
Deliverables
At the end of this lab, you should have:
- At least 2 custom commands in
.claude/commands/ - Understanding of frontmatter configuration
- Experience with argument passing
- Ideas for team workflow automation
Next Steps
After completing this lab, move on to Lab 3.4: MCP Integration.