Claude Code Custom Slash Commands: Best Practices for Bash Scripts, Prompt Templates & Team Workflows

Claude Code Custom Slash Commands: Automate Repetitive Development Tasks

Custom slash commands in Claude Code transform repetitive development workflows into single-command operations. Whether you’re generating boilerplate, running complex multi-step builds, or sharing standardized workflows across your team, slash commands let you encode institutional knowledge into reusable automation. This guide covers best practices for writing effective commands using bash scripts, prompt templates, and shared libraries.

Understanding Slash Command Types

Claude Code supports two primary types of custom slash commands, each suited for different automation needs:

TypeFile ExtensionLocationBest For
Prompt Template.md.claude/commands/Context-rich prompts, code generation, reviews
Bash Script.sh.claude/commands/System operations, build pipelines, file manipulation
## Step 1: Set Up Your Command Directory Structure Organize commands by scope—project-level for repo-specific workflows and user-level for personal utilities. - **Create the project command directory** in your repository root:mkdir -p .claude/commands- **Create the user-level command directory** for personal commands available across all projects:
mkdir -p ~/.claude/commands
- **Add the project commands directory to version control** so your team can share them:
git add .claude/commands/
git commit -m "feat: add Claude Code custom slash commands"
## Step 2: Write Effective Prompt Template Commands

Prompt templates (.md files) are the most powerful command type. They inject structured context into Claude's conversation, enabling consistent and repeatable results.

Example: Code Review Command

Create .claude/commands/review.md: Review the current staged changes with these criteria:

  1. Security: Check for injection vulnerabilities, exposed secrets, and OWASP Top 10 issues
  2. Performance: Identify N+1 queries, unnecessary re-renders, or missing indexes
  3. Testing: Verify adequate test coverage for new logic paths
  4. Conventions: Ensure naming, file structure, and patterns match this project

Provide a summary table with severity (critical/warning/info) for each finding. If no issues found, confirm the changes are ready to merge.

Focus on files from: git diff —cached —name-only

Usage: Type /project:review in Claude Code to invoke this command.

Example: Feature Scaffolding Command with Arguments

Create .claude/commands/scaffold-feature.md: Generate a new feature module named “$ARGUMENTS” following our project conventions:

  • Create the component file in src/features/$ARGUMENTS/
  • Add a unit test file in src/features/$ARGUMENTS/tests/
  • Create an index.ts barrel export
  • Register the route in src/routes.ts
  • Add a basic TypeScript interface for props

Use existing features in src/features/ as reference for patterns and naming.

Usage: /project:scaffold-feature user-profile

Step 3: Build Bash Script Commands

Bash commands handle operations that require system-level execution before or alongside Claude’s AI capabilities.

Example: Pre-PR Validation Script

Create .claude/commands/pre-pr.sh: #!/bin/bash set -euo pipefail

echo ”## Pre-PR Validation Report” echo ""

Lint check

echo ”### Lint Results” if npx eslint src/ —quiet 2>/dev/null; then echo “All lint checks passed.” else echo “Lint errors detected. Fix before opening PR.” fi

echo ""

Type check

echo ”### TypeScript Check” if npx tsc —noEmit 2>/dev/null; then echo “No type errors found.” else npx tsc —noEmit 2>&1 | tail -20 fi

echo ""

Test summary

echo ”### Test Summary” npx jest —coverage —silent 2>&1 | grep -E “(Tests:|Suites:|Statements)” || echo “No test output captured.”

echo "" echo ”### Changed Files” git diff —stat HEAD~1

Make it executable: chmod +x .claude/commands/pre-pr.sh

Step 4: Create a Shared Team Command Library

Standardize workflows across your team by committing commands to version control with clear documentation.

  • Establish a naming convention: Use prefixes like dev-, qa-, ops- to categorize commands.- Add a README inside .claude/commands/README.md:# Team Slash Commands
CommandTypeDescription
/project:reviewPromptStructured code review
/project:scaffold-featurePromptGenerate feature module
/project:pre-prBashRun pre-PR validation
/project:dev-setupBashInitialize dev environment
/project:qa-checklistPromptQA verification checklist

Step 5: Chain Commands into Workflows

Combine multiple commands into end-to-end workflows. Create a master prompt that references other operations. Create .claude/commands/release-prep.md: Prepare this project for release by completing these steps in order:

  1. Run all tests and confirm they pass
  2. Check for any TODO or FIXME comments in changed files since last tag
  3. Review the git log since the last tag and draft release notes in Keep a Changelog format
  4. Verify package.json version matches the planned release
  5. List any dependency updates that should be noted

Present a final release readiness summary with go/no-go recommendation.

Pro Tips

  • Use $ARGUMENTS liberally — prompt templates support the $ARGUMENTS placeholder, which captures everything typed after the command name. Design commands to accept flexible input.- Reference project files in prompts — include instructions like “Use the patterns in src/utils/ as reference” to ground Claude in your actual codebase conventions.- Layer personal and project commands — keep personal productivity commands in ~/.claude/commands/ and team standards in .claude/commands/. Project commands take precedence on name collision.- Keep bash scripts idempotent — commands may be run multiple times. Use checks like if [ ! -f … ] to avoid duplicate operations.- Version your commands with your code — as your project evolves, update the commands. Outdated slash commands that reference removed patterns cause confusion.

Troubleshooting

IssueCauseSolution
Command not appearing in /project: listFile not in correct directoryVerify file is in .claude/commands/ at the repo root, not a subdirectory
Bash command fails with permission deniedScript not executableRun chmod +x .claude/commands/your-script.sh
$ARGUMENTS not replacedUsed in .sh file instead of .mdArgument substitution works in prompt templates (.md); for bash, use positional params $1, $@
Command runs but output is emptyScript writes to file instead of stdoutBash commands should output to stdout so Claude can process the results
Team members don't see commandsCommands not committed to gitEnsure .claude/commands/ is tracked and pushed to the remote branch
## Frequently Asked Questions

Can I use slash commands to interact with external APIs or services?

Yes. Bash script commands can call external APIs using curl or any CLI tool installed on your system. For example, you can create a command that fetches the latest deployment status from your CI/CD platform and presents it to Claude for analysis. Keep API keys in environment variables rather than hardcoding them in scripts—reference them as $YOUR_API_KEY in your bash commands.

What is the difference between project commands and user commands?

Project commands live in .claude/commands/ at your repository root and are shared with your team via version control. They appear under the /project: prefix. User commands live in ~/.claude/commands/ and are private to your machine, available across all projects under the /user: prefix. If both directories contain a command with the same name, the project-level command takes precedence.

How long can a slash command prompt template be?

Prompt templates can be as long as needed, but best practice is to keep them focused and under 500 words. Overly long templates dilute the instruction signal and may cause Claude to miss key requirements. If your workflow is complex, break it into multiple commands and chain them together rather than creating a single monolithic template. Reference existing project files for context instead of duplicating code patterns inline.

Explore More Tools

Grok Best Practices for Real-Time News Analysis and Fact-Checking with X Post Sourcing Best Practices Devin Best Practices: Delegating Multi-File Refactoring with Spec Docs, Branch Isolation & Code Review Checkpoints Best Practices Bolt Case Study: How a Solo Developer Shipped a Full-Stack SaaS MVP in One Weekend Case Study Midjourney Case Study: How an Indie Game Studio Created 200 Consistent Character Assets with Style References and Prompt Chaining Case Study How to Install and Configure Antigravity AI for Automated Physics Simulation Workflows Guide How to Set Up Runway Gen-3 Alpha for AI Video Generation: Complete Configuration Guide Guide Replit Agent vs Cursor AI vs GitHub Copilot Workspace: Full-Stack Prototyping Compared (2026) Comparison How to Build a Multi-Page SaaS Landing Site in v0 with Reusable Components and Next.js Export How-To Kling AI vs Runway Gen-3 vs Pika Labs: Complete AI Video Generation Comparison (2026) Comparison Claude 3.5 Sonnet vs GPT-4o vs Gemini 1.5 Pro: Long-Document Summarization Compared (2025) Comparison Midjourney v6 vs DALL-E 3 vs Stable Diffusion XL: Product Photography Comparison 2025 Comparison Runway Gen-3 Alpha vs Pika 1.0 vs Kling AI: Short-Form Video Ad Creation Compared (2026) Comparison BMI Calculator - Free Online Body Mass Index Tool Calculator Retirement Savings Calculator - Free Online Planner Calculator 13-Week Cash Flow Forecasting Best Practices for Small Businesses: Weekly Updates, Collections Tracking, and Scenario Planning Best Practices 30-60-90 Day Onboarding Plan Template for New Marketing Managers Template Amazon PPC Case Study: How a Private Label Supplement Brand Lowered ACOS With Negative Keyword Mining and Exact-Match Campaigns Case Study ATS-Friendly Resume Formatting Best Practices for Career Changers Best Practices Accounts Payable Automation Case Study: How a Multi-Location Restaurant Group Cut Invoice Processing Time With OCR and Approval Routing Case Study Apartment Move-Out Checklist for Renters: Cleaning, Damage Photos, and Security Deposit Return Checklist