Skip to content

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

bash
# Navigate to the sample project
cd sample-projects/hackathon-starter

# Create the commands directory
mkdir -p .claude/commands

# Start Claude Code
claude

Task 1: Create Your First Command

Time: 10 minutes

Create a simple command that documents a file.

Create the file: .claude/commands/document.md

markdown
---
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.js

Success 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

markdown
---
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.js

Verify: 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

markdown
---
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 why

Test it:

/compare controllers/user.js controllers/api.js

Success criteria:

  • [ ] Both arguments passed correctly
  • [ ] Meaningful comparison generated

Command Locations

LocationScopeUse Case
.claude/commands/ProjectTeam workflows, shared via git
~/.claude/commands/PersonalYour personal shortcuts

Note

Project commands override personal commands with the same name.


Frontmatter Options

yaml
---
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

  1. Start simple - One task per command
  2. Use tool restrictions - Prevent unintended modifications
  3. Document well - Good descriptions help teammates
  4. 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 $ARGUMENTS for all args as one string
  • Use $1, $2, $3 for positional arguments

Tool restrictions ignored:

  • Double-check allowed-tools spelling
  • Ensure tools are comma-separated

Stretch Goals

If you finish early:

  1. Create a /new-feature command that scaffolds a new feature with tests
  2. Create a /security-check command that audits a file for vulnerabilities
  3. Create a /pr-summary command that generates PR descriptions

Deliverables

At the end of this lab, you should have:

  1. At least 2 custom commands in .claude/commands/
  2. Understanding of frontmatter configuration
  3. Experience with argument passing
  4. Ideas for team workflow automation

Next Steps

After completing this lab, move on to Lab 3.4: MCP Integration.

Claude for Coders Training Course