Custom Slash Commands & Agent Skills
Creating reusable commands and skill definitions.
Learning Objectives
- Create project and user-level slash commands
- Use $ARGUMENTS for parameterized commands
- Define agent skills with SKILL.md files
Custom Slash Commands & Agent Skills
Claude Code supports extensibility through two powerful mechanisms: custom slash commands and agent skills. Slash commands let you create reusable prompts that your entire team can share, while agent skills (SKILL.md files) provide Claude with domain-specific capabilities. For the CCA-F exam, you need to understand how to create, configure, and use both.
Custom Slash Commands
Slash commands are reusable prompt templates stored as Markdown files in your project. When you type / in Claude Code, these commands appear as options you can invoke. They are the primary mechanism for encoding team workflows into repeatable actions.
Where Slash Commands Live
Slash commands are stored in the .claude/commands/ directory at the root of your project:
my-project/
.claude/
commands/
review.md # Invoked as /project:review
test-plan.md # Invoked as /project:test-plan
migrate-db.md # Invoked as /project:migrate-dbYou can also create personal slash commands that apply across all projects by placing them in your home directory:
~/.claude/
commands/
my-review.md # Invoked as /user:my-review
my-refactor.md # Invoked as /user:my-refactor/project: while personal commands use /user:. The exam will test whether you know the correct prefix for each location. Commands in .claude/commands/ at the project root are /project:; commands in ~/.claude/commands/are /user:.Creating a Slash Command
A slash command is simply a Markdown file whose content becomes the prompt sent to Claude. The filename (minus the .md extension) becomes the command name.
# .claude/commands/review.md
Review the current code changes for:
1. **Correctness**: Are there any bugs, logic errors, or edge cases?
2. **Security**: Are there any security vulnerabilities (SQL injection,
XSS, auth bypass, etc.)?
3. **Performance**: Are there any obvious performance issues?
4. **Style**: Does the code follow our project conventions from CLAUDE.md?
Provide specific, actionable feedback. For each issue found, reference
the exact file and line number.
Focus on the files changed in the current git diff:
git diff --name-onlyWhen a developer types /project:review in Claude Code, the entire content of this file is sent as the prompt.
The $ARGUMENTS Variable
Slash commands support a special $ARGUMENTS placeholder that is replaced with any text the user provides after the command name. This makes commands parameterizable:
# .claude/commands/test-for.md
Write comprehensive tests for the following module:
$ARGUMENTS
Requirements:
- Use Jest with TypeScript
- Cover happy path, error cases, and edge cases
- Mock external dependencies using jest.mock()
- Aim for >90% code coverage
- Follow the test patterns in our existing test filesUsage:
# In Claude Code:
/project:test-for src/services/payment.ts
# This expands to:
# "Write comprehensive tests for the following module:
# src/services/payment.ts
# Requirements: ..."Advanced Slash Command Examples
Here are several production-quality slash command examples that demonstrate common team workflows:
# .claude/commands/migrate.md
Create a new database migration for the following change:
$ARGUMENTS
Steps:
1. Create a new migration file in /src/db/migrations/
2. Use the naming convention: YYYYMMDD_HHMMSS_description.sql
3. Write both the UP and DOWN migration
4. Update the schema types in /src/db/schema.ts
5. Run the migration locally: npm run db:migrate
6. Verify the migration succeeded by checking the schema
7. Run the test suite to ensure nothing broke: npm test# .claude/commands/component.md
Create a new React component:
Component name: $ARGUMENTS
Requirements:
- Create the component file in /src/components/
- Use TypeScript with a Props interface
- Export as a named export (not default)
- Create a corresponding test file in /src/components/__tests__/
- Create a Storybook story in /src/components/__stories__/
- Follow the patterns in existing components# .claude/commands/debug.md
I am experiencing the following issue:
$ARGUMENTS
Please debug this by:
1. Searching the codebase for relevant code
2. Identifying the root cause
3. Proposing a fix with explanation
4. Implementing the fix
5. Running tests to verify: npm test
6. If tests pass, summarize what was wrong and how it was fixedAgent Skills (SKILL.md)
Agent skills are a more advanced extension mechanism. A SKILL.md file provides Claude with structured knowledge about how to perform a specific type of task. Unlike slash commands (which are user-invoked prompts), skills are automatically available to Claude and inform its behavior when relevant tasks arise.
SKILL.md Structure
Skills are defined in Markdown files with frontmatter metadata:
# .claude/skills/deploy.md
---
title: Production Deployment
description: How to deploy this application to production
trigger: When the user asks to deploy or release
---
# Production Deployment Procedure
## Prerequisites
- All tests must pass: npm test
- Build must succeed: npm run build
- No TypeScript errors: npx tsc --noEmit
## Deployment Steps
1. Create a release branch: git checkout -b release/vX.Y.Z
2. Update version in package.json
3. Run the full test suite
4. Build the production bundle
5. Deploy to staging first: npm run deploy:staging
6. Run smoke tests against staging
7. Deploy to production: npm run deploy:production
8. Tag the release: git tag vX.Y.Z
## Rollback Procedure
If something goes wrong:
1. Revert to previous deployment: npm run deploy:rollback
2. Notify the team in #engineering Slack channelSkill Triggers
The trigger field in the frontmatter tells Claude when this skill is relevant. Claude uses this information to decide when to apply the skill's knowledge:
# Different trigger patterns:
---
trigger: When the user asks to create a new API endpoint
---
---
trigger: When working with database migrations
---
---
trigger: When the user asks about authentication or authorization
---/project:name or/user:name. Skills are automatically applied by Claude when the trigger condition matches the current task. Slash commands live in .claude/commands/; skills can live in .claude/skills/ or other configured locations.Combining Slash Commands and Skills
A powerful pattern is to use slash commands as entry points that trigger skill-enhanced behavior:
# Project structure combining both:
my-project/
.claude/
commands/
new-endpoint.md # Slash command: /project:new-endpoint
new-component.md # Slash command: /project:new-component
deploy.md # Slash command: /project:deploy
skills/
api-patterns.md # Skill: API development patterns
testing.md # Skill: Testing conventions
deployment.md # Skill: Deployment proceduresWhen a developer runs /project:new-endpoint, Claude receives the slash command prompt and also has access to the api-patterns skill for additional context on how API endpoints should be structured in this project.
Built-In Slash Commands
Claude Code includes several built-in slash commands that you should know for the exam:
- /compact: Compacts the conversation context to free up context window space. Optionally takes instructions about what to preserve.
- /clear: Clears the entire conversation history and starts fresh.
- /help: Shows available commands and usage information.
- /init: Generates an initial CLAUDE.md file for the current project by analyzing the codebase structure.
# Built-in command usage examples:
/compact preserve the auth refactoring context
/clear
/help
/initSlash Command Organization Patterns
For larger teams, organize slash commands by workflow category using subdirectories:
.claude/
commands/
review/
pr.md # /project:review/pr
security.md # /project:review/security
performance.md # /project:review/performance
create/
component.md # /project:create/component
endpoint.md # /project:create/endpoint
migration.md # /project:create/migration
fix/
lint.md # /project:fix/lint
types.md # /project:fix/types
tests.md # /project:fix/tests.claude/commands/ that create reusable prompts invoked with/project:name (project-level) or /user:name (personal). The $ARGUMENTS variable makes commands parameterizable. Agent skills (SKILL.md) provide automatic domain knowledge triggered by context. Slash commands are explicitly invoked; skills are automatically applied. Both should be committed to version control for team sharing.Exam-Relevant Concepts Summary
- Project commands:
.claude/commands/name.mdinvoked as/project:name. - Personal commands:
~/.claude/commands/name.mdinvoked as/user:name. $ARGUMENTSis the placeholder for user-provided parameters.- Skills (SKILL.md) use frontmatter with trigger conditions for automatic activation.
- Built-in commands:
/compact,/clear,/help,/init. - Subdirectories in commands/ create namespaced commands (e.g.,
/project:review/pr).