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 Academic Research and Literature Discovery: Leveraging X/Twitter for Scholarly Intelligence Best Practices Grok Best Practices for Content Strategy: Identify Trending Topics Before They Peak and Create Content That Captures Demand Best Practices Grok Case Study: How a DTC Beauty Brand Used Real-Time Social Listening to Save Their Product Launch Case Study Grok Case Study: How a Pharma Company Tracked Patient Sentiment During a Drug Launch and Caught a Safety Signal 48 Hours Before the FDA Case Study Grok Case Study: How a Disaster Relief Nonprofit Used Real-Time X/Twitter Monitoring to Coordinate Emergency Response 3x Faster Case Study Grok Case Study: How a Political Campaign Used X/Twitter Sentiment Analysis to Reshape Messaging and Win a Swing District Case Study How to Use Grok for Competitive Intelligence: Track Product Launches, Pricing Changes, and Market Positioning in Real Time How-To Grok vs Perplexity vs ChatGPT Search for Real-Time Information: Which AI Search Tool Is Most Accurate in 2026? Comparison How to Use Grok for Crisis Communication Monitoring: Detect, Assess, and Respond to PR Emergencies in Real Time How-To How to Use Grok for Product Improvement: Extract Customer Feedback Signals from X/Twitter That Your Support Team Misses How-To How to Use Grok for Conference Live Monitoring: Extract Event Insights and Identify Networking Opportunities in Real Time How-To How to Use Grok for Influencer Marketing: Discover, Vet, and Track Influencer Partnerships Using Real X/Twitter Data How-To How to Use Grok for Job Market Analysis: Track Industry Hiring Trends, Layoff Signals, and Salary Discussions on X/Twitter How-To How to Use Grok for Investor Relations: Track Earnings Sentiment, Analyst Reactions, and Shareholder Concerns in Real Time How-To How to Use Grok for Recruitment and Talent Intelligence: Identifying Hiring Signals from X/Twitter Data How-To How to Use Grok for Startup Fundraising Intelligence: Track Investor Sentiment, VC Activity, and Funding Trends on X/Twitter How-To How to Use Grok for Regulatory Compliance Monitoring: Real-Time Policy Tracking Across Industries How-To NotebookLM Best Practices for Financial Analysts: Due Diligence, Investment Research & Risk Factor Analysis Across SEC Filings Best Practices NotebookLM Best Practices for Teachers: Build Curriculum-Aligned Lesson Plans, Study Guides, and Assessment Materials from Your Own Resources Best Practices NotebookLM Case Study: How an Insurance Company Built a Claims Processing Training System That Cut Errors by 35% Case Study