
Claude Code スラッシュコマンド完全ガイド
はじめに
Claude Codeは、Anthropicが提供するコマンドライン型のAIコーディングアシスタントです。その中でも「スラッシュコマンド」は、開発ワークフローを劇的に効率化する強力な機能です。
本記事では、スラッシュコマンドの基本概念から高度な活用方法まで、コードレビューコマンドを中心とした具体例とともに詳しく解説します。
スラッシュコマンドの基本概念
スラッシュコマンドとは
スラッシュコマンドは、頻繁に使用するプロンプトをMarkdownファイルとして保存し、簡潔なコマンド形式で呼び出せる機能です。これにより、複雑な指示を毎回入力する必要がなくなり、チーム全体で一貫したワークフローを実現できます。
コマンドの種類とスコープ
プロジェクトスコープコマンド
- 保存場所:
.claude/commands/ - 用途: プロジェクト固有の作業
- 共有: Gitでチームと共有可能
ユーザースコープコマンド
- 保存場所:
~/.claude/commands/ - 用途: 個人的な作業パターン
- 共有: 個人環境のみで利用
詳細な設定手順
ステップ1: プロジェクト構造の準備
# プロジェクトのルートディレクトリで実行 mkdir -p .claude/commands # サブディレクトリでの分類(推奨) mkdir -p .claude/commands/review mkdir -p .claude/commands/testing mkdir -p .claude/commands/deployment
ステップ2: Gitignoreの設定
# .gitignore(チーム共有する場合は追加しない) echo "# Claude commands are shared with team" >> .gitignore
ステップ3: 高機能コードレビューコマンドの実装
以下が、実際のプロジェクトで使用できる包括的なコードレビューコマンドです:
--- allowed-tools: Bash(git status:*), Bash(git diff:*), Bash(find:*) description: Comprehensive code review with security and performance analysis --- # Advanced Code Review Command Perform a thorough code review with multi-dimensional analysis including security, performance, and maintainability aspects. ## Pre-Review Context Analysis Before starting the review, gather the following context: - **Current git status**: !`git status --porcelain` - **Recent changes**: !`git diff --name-only HEAD~3..HEAD` - **File structure context**: !`find . -name "*.js" -o -name "*.jsx" -o -name "*.ts" -o -name "*.tsx" | head -20` ## Review Dimensions ### 1. Security Analysis - Check for common vulnerabilities (XSS, injection attacks, etc.) - Validate input sanitization and validation - Review authentication and authorization logic - Assess data exposure risks ### 2. Performance Assessment - Identify potential bottlenecks - Evaluate algorithm complexity - Check for memory leaks and inefficient operations - Review database query optimization ### 3. Code Quality Evaluation - Assess readability and maintainability - Check adherence to coding standards - Evaluate error handling strategies - Review naming conventions and documentation ### 4. Architecture & Design - Evaluate component/module structure - Check for proper separation of concerns - Assess design pattern usage - Review dependency management ## Target Analysis **Files to review**: $ARGUMENTS ## Output Requirements 1. **Executive Summary** - Overall code quality score (1-10) - Critical issues requiring immediate attention - Recommended next steps 2. **Detailed Findings** - Categorized by severity (Critical, High, Medium, Low) - Specific line numbers and code snippets - Concrete improvement suggestions 3. **Improvement Recommendations** - Refactoring opportunities - Performance optimization suggestions - Security enhancements - Documentation improvements 4. **Code Examples** - Before/after code snippets for major suggestions - Alternative implementation approaches - Best practice examples ## Review Standards - Follow project-specific coding standards found in @.eslintrc.js or @.prettierrc - Consider the project's architecture patterns found in @README.md - Reference any existing documentation in @docs/ directory
ステップ4: コマンドの登録と確認
# コマンドファイルを作成 cat > .claude/commands/review/comprehensive.md << 'EOF' [上記のマークダウンコンテンツ] EOF # Claude Codeでコマンドの確認 claude > /help
実際の使用例とベストプラクティス
基本的な使用パターン
# 特定ファイルのレビュー /project:review:comprehensive @src/components/UserAuth.jsx # 複数ファイルの一括レビュー /project:review:comprehensive @src/utils/validation.js @src/services/api.js # コードスニペット直接レビュー /project:review:comprehensive Here's my function: function processPayment(amount, card) { return charge(card, amount); }
高度な活用例
引数を使った動的レビュー
# セキュリティフォーカスレビュー /project:review:comprehensive Focus specifically on security vulnerabilities in: @src/auth/ # パフォーマンスフォーカスレビュー /project:review:comprehensive Analyze performance bottlenecks in: @src/data-processing/
Git統合レビュー
# 最新のコミット変更をレビュー /project:review:comprehensive Please review the files changed in the last commit # 特定のブランチ変更をレビュー /project:review:comprehensive Review changes between main and feature/user-auth branches
チーム開発での活用戦略
1. コマンド体系の設計
# 機能別の分類例 .claude/commands/ ├── review/ │ ├── security.md │ ├── performance.md │ └── comprehensive.md ├── testing/ │ ├── unit-test.md │ └── integration-test.md └── deployment/ ├── staging.md └── production.md
2. チーム共有のルール
# .claude/README.md でチーム向けドキュメント作成 cat > .claude/README.md << 'EOF' # Team Claude Commands ## Available Commands - `/project:review:comprehensive` - Full code review - `/project:review:security` - Security-focused review - `/project:testing:unit-test` - Generate unit tests ## Usage Guidelines 1. Always run security review before merging 2. Use comprehensive review for complex features 3. Update commands when coding standards change EOF
3. CI/CD統合
# .github/workflows/claude-review.yml name: Automated Code Review on: pull_request: types: [opened, synchronize] jobs: claude-review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Claude Code Review run: | claude -p "/project:review:comprehensive Review the changes in this PR" \ --output-format stream-json > review-results.json
高度な機能の活用
動的コンテンツの統合
環境情報の自動取得
## Environment Context - **Node version**: !`node --version` - **Package manager**: !`which npm yarn pnpm | head -1` - **Git branch**: !`git branch --show-current` - **Project dependencies**: @package.json
動的ファイル参照
## Project Configuration Analysis - **Linting rules**: @.eslintrc.js - **TypeScript config**: @tsconfig.json - **Build configuration**: @webpack.config.js - **Testing setup**: @jest.config.js
セキュリティ考慮事項
機密情報の保護
--- allowed-tools: Bash(git status:*), Bash(find:. -name "*.js":*) description: Secure code review avoiding sensitive data exposure --- # Security-Focused Review ⚠️ **Security Notice**: This command will not process files containing: - API keys or secrets - Personal data or credentials - Configuration files with sensitive information ## Pre-flight Security Check !`find . -name "*.env*" -o -name "*secret*" -o -name "*key*" | head -5`
パフォーマンス最適化のヒント
1. コマンド実行の効率化
# 効率的なコマンド設計 - Bashコマンドは必要最小限に - ファイル参照は具体的なパスを指定 - 大きなファイルは事前にフィルタリング
2. コンテキスト管理
# コンテキスト最適化 - 関連ファイルのみを参照 - 過度な情報収集を避ける - 段階的な分析アプローチ
トラブルシューティング
よくある問題と解決策
問題1: コマンドが認識されない
# 解決策: ファイルパスとパーミッションを確認 ls -la .claude/commands/ # ファイルが存在し、読み取り可能であることを確認
問題2: 引数が正しく渡されない
# 解決策: $ARGUMENTSの配置と形式を確認 # Markdownファイル内で$ARGUMENTSが正しい位置にあることを確認
問題3: Bashコマンドが実行されない
# 解決策: allowed-toolsヘッダーを確認 --- allowed-tools: Bash(git status:*), Bash(find:*) ---
まとめ
Claude Codeのスラッシュコマンドは、単なる便利機能を超えて、チーム全体の開発文化と品質を向上させる強力なツールです。特にコードレビューの分野では、一貫性のある高品質なレビューを自動化し、開発者がより創造的な作業に集中できる環境を提供します。
重要なポイント:
- 段階的な導入でチームの習熟度を高める
- プロジェクト固有のニーズに合わせたカスタマイズ
- セキュリティとパフォーマンスを常に考慮
- 継続的な改善とメンテナンス
適切に設計・活用されたスラッシュコマンドは、開発チームの生産性を大幅に向上させ、コード品質の継続的な改善を実現します。今すぐプロジェクトに導入して、その効果を実感してください。
投稿されたコメントは管理者による承認後に表示される場合があります。 不適切な内容は削除される可能性があります。
コメント (0件)
関連記事

TypeScriptパッケージを0から自作して公開しよう!
2025年の最新ベストプラクティスに基づいて、実際に手を動かしながらTypeScriptパッケージを作成し、NPMに公開するまでの全工程を解説します。

Apple Silicon Macへのasdfインストール・設定手順【2025年版】
Apple Silicon Macでのasdfのインストールからセットアップまでをステップバイステップで解説します。

2025年のAIサービス開発トレンド
2025年のAIサービス開発のトレンドについて、できるだけ分かりやすく説明します。