日曜日, 6月 1, 2025
ホームニューステックニュースClaude Codeの/ (スラッシュ)コマンドを全部試したので解説する

Claude Codeの/ (スラッシュ)コマンドを全部試したので解説する


初投稿です。

4月初旬くらいからClaude Codeを触っていたのですが、初心者向けに情報発信をしていたらそれなりの反響をいただきました。

𝕏(旧Twitter)では書ききれていないこともあるので、Zennに投稿しようと思った次第です。

Claude Code初心者向けの内容となりますのでご容赦ください。

また最後にCustom Command(カスタムコマンド)について少し触れているので、ぜひ読んでみてください。

Claude Code Slash Commandとは

Claude CodeはもともとCLIツールであり、コマンドが使えます。
最近VSCode, CursorといったIDE統合ができるようになりましたが、基本的な機能は同じです。

Claude Codeをclaude起動コマンドを実行したあとに、/(スラッシュ)を入力することで、あらかじめ割り当てられたコマンドを使用できます。これをClaude Code Slash Commandと言います。

この記事は、私が実際に/(スラッシュ)コマンドを使ってみたものをまとめたものです。

公式ドキュメントに詳しく書かれていない仕様もあったので、多少なりとも参考になる部分もあるかと思います。

Anthropicの公式ドキュメント:

https://docs.anthropic.com/ja/docs/claude-code/cli-usage

Claude Code Slash Command一覧

2025年5月29日時点で、Claude Codeに割り当てられているスラッシュコマンドの一覧テーブルです。

Anthropic公式ドキュメントのcli-usageに記載あるものに加えて、/install-github-appなど別のページに書かれているものも、Claude Codeから実行できるものは全てリストしています。

コマンドを一つずつ紹介していきます。
多いので気になるコマンドだけ見るのでもいいと思います。

/allowed-tools

Claude Codeに許可・拒否されているbashコマンド群等を表示します。中身は.claude以下のsettings.jsonにあるものです。

.claude/settings.local.jsonの例:

{
  "permissions": {
    "allow": [
      "Bash(ls:*)",
      "Bash(npm init:*)",
      "Bash(npm install:*)",
      "Bash(mkdir:*)",
      "Bash(npm start)",
      "Bash(npm run dev:*)",
      "WebFetch(domain:docs.anthropic.com)",
      "Bash(git init:*)",
      "Bash(git add:*)",
      "Bash(git commit:*)",
      "Bash(gh repo create:*)",
      "Bash(brew:*)",
      "Bash(gh auth:*)",
      "Bash(git push:*)",
      "WebFetch(domain:github.com)",
      "Bash(gh pr view:*)",
      "Bash(gh pr list:*)"
    ],
    "deny": []
  },
  "enableAllProjectMcpServers": false
}

Add new rulesを選択する、もしくはClaude Code実行中に実行権限許可を与えると、このファイルに実行可能コマンドが追加されます。

/bug

Anthropicへのバグ報告です。基本的には使わないです。
バグ報告が必要な場合は、”Describe the issue below:”という文言の下にバグの詳細を記載しレポートできます。

/clear

コンテキストウィンドウを完全にクリアするコマンドです。結構使います。

Claude Opus 4が優秀になっても会話が長引くとエラーを出すようになることもあるので、その際にリセットの目的で使うことが多いです。

/compact [instructions]

コンテキストウィンドウの内容を圧縮するコマンドです。

/clearが全ての会話の履歴をリセットするのに対し、/comapactは内容を圧縮して以降の会話でも保持します。
引数には「何に焦点を当ててデータを圧縮保持するか」の指示を書くことができます。

デフォルトの設定ではある程度コンテキストウィンドウが大きくなると、自動で/comapactが発動するようになっています。これは後述する/configコマンドでON/OFFを切り替えられます。

/config (or /theme)

Claude Codeの各種設定ができます。上の画像はTheme以外全てデフォルトです。

Options Values (太字はデフォルト) Description
Auto-compact true, false 自動で/compactをするか
Use todo list true, false Claude Codeが命令実行する際にTo Doリストを作るか
Verbose true, false 詳細ログを表示するか
Theme 6種類 テーマ設定
Notifications auto, iterm2, terminal_bell, iterm2_with_bell, kitty, notifications_disabled タスク完了時の通知設定
Editor mode normal, vim エディタをVimモードにするか
Model Default(recommended), Sonnet AIモデルの設定 (/modelと同じ)
Diff tool auto, terminal コードの差分表示方法

/cost

Claude Codeの料金が出ます。プランによって表示が違うためどちらでloginしているかの目安になります。

Maxプラン加入者:

/cost 
  ⎿ With your Claude Max subscription, no need to monitor 
    cost — your subscription includes Claude Code usage

API課金者:

/cost 
  ⎿ Total cost:            $0.0061
    Total duration (API):  2.2s
    Total duration (wall): 42.6s
    Total code changes:    0 lines added, 0 lines removed
    Token usage by model:
        claude-3-5-haiku:  7.5k input, 16 output, 0 cache 
    read, 0 cache write

/doctor

Claude Codeが正しくInstallされているかを確認できます。
Claude Codeに問題があれば/doctorコマンドを実行するいいです。

問題ない人は以下のようなテキストが表示されます:

 ※ Tip: Use /theme to change the color theme
 ✓ npm permissions: OK
 Your installation is healthy and ready for auto-updates.

 You can also install Claude Code locally to avoid npm
 permission issues using the slash command:

   /migrate-installer

/exit or (/quit)

Claude Codeのセッションを終了します。
ちなみにCtrl-cを2回押すのでも終了できます。

/help

コマンドのヘルプを表示します。あくまでClaude Codeを起動した後の内容なので、起動時コマンドはclaude -hで確認してください。

Claude Code version 1.0.6では以下のように表示されます

 ※ Tip: Press Shift+Enter to send a multi-line message

 Claude Code v1.0.6

 Always review Claude's responses, especially when running
 code. Claude has read access to files in the current
 directory and can run commands and edit files with your
 permission.

 Usage Modes:
 • REPL: claude (interactive session)
 • Non-interactive: claude -p "question"

 Run claude -h for all command line options

 Common Tasks:
 • Ask questions about your codebase > How does foo.py work?
 • Edit files > Update bar.ts to...
 • Fix errors > cargo build
 • Run commands > /help
 • Run bash commands > !ls

 Interactive Mode Commands:
  /allowed-tools - List all currently allowed tools
  /bug - Submit feedback about Claude Code
  /clear - Clear conversation history and free up context
  /compac - Clear conversation history but keep a summary in
         context. Optional: /compact [instructions for
         summarization]
  /config - Open config panel
  /cos - Show the total cost and duration of the current
      session
  /doctor - Checks the health of your Claude Code installation
  /exit - Exit the REPL
  /help - Show help and available commands
  /ide - Manage IDE integrations and show status
  /init - Initialize a new CLAUDE.md file with codebase
       documentation
  /install-github-a - Set up Claude GitHub Actions for a
  p                repository
  /login - Sign in with your Anthropic account
  /logout - Sign out from your Anthropic account
  /mcp - Show MCP server connection status
  /memory - Edit Claude memory files
  /migrate-install - Migrate from global npm installation to
  r               local installation
  /model - Set the AI model for Claude Code
  /pr-comments - Get comments from a GitHub pull request
  /release-notes - View release notes
  /review - Review a pull request
  /status - Show Claude Code status including version, model,
         account, API connectivity, and tool statuses
  /terminal-setu - Install Shift+Enter key binding for
                newlines
  /vim - Toggle between Vim and Normal editing modes

 Learn more at: https://docs.anthropic.com/s/claude-code

/ide

最近追加されたIDE統合機能です。
VSCode, Cursorなどと接続できます。

私はVSCodeでやった時は特にこのコマンドを使わなくても接続できたのですが、なぜかは不明。。。

/init

Claude Codeの設定ファイルCLAUDE.mdを作成します。

この際、既存のプロジェクトではプロジェクトを走査して設定ファイルなども確認します。

  • package.json
  • README.md
  • App.tsx
  • tsconfig.json
  • jest.config.js
  • App.test.tsx

これらのプロジェクトの設定ファイルに加えて、AIエディタのルール等も探しています。

  • .cursorrules
  • .cursor/rules
  • .github/copilot-instructions.md

CLAUDE.mdは他の設定ファイル同様、Edit可能です。

/install-github-app

GitHubリポジトリでClaude Code GitHub Actionsを使えるようにするコマンドです。

GitHub Actionsが何かは説明すると長くなるので割愛します。
ザックリいうと、GitHubのissuesやPull Requestで@claudeをつけて命令すると、Claudeがよしなに命令実行してくれる機能です。めっちゃ便利。

基本的には/install-github-appで指示された通りに設定するだけですが、内容は他の記事に譲ります。

/login

アカウントログインします。既にログインしていても実行可能で、その場合は上記のlogin方法の選択画面に遷移します。

/logout

サインアウトします。
実行するとセッション自体が終わりターミナルに戻されます。

/mcp

Model Contect Protcol(MCP)のサーバーの管理をします。

MCP自体はAIエージェントがツールを使用できるようにするプロトコルで、最近熱い技術の一つです。
MCPの説明はここでは割愛します。MCPは起動時コマンドclaude mcpの方で設定できます。

/memory

/initで作成したCLAUDE.mdを編集します。

  • Project
  • Local Project
  • User

上記3つのCLAUDE.mdのファイルがあり、プロジェクトに応じて共有方法を変更できます。

ちなみにIDEに接続していても、なぜかMacOSだとTerminalが開きます(なぜ)。

/migrate-installer

Claude Codeのnpm install方法をglobalからlocalに変更します。

多くの人は公式が推奨している以下のコマンドを実行していると思います。

npm install -g @anthropic-ai/claude-code

このコマンドはグローバルインストールから変更します。

Claude Code Local Installer
This will install Claude Code to ~/.claude/local
instead of using a global npm installation.
Press Enter to continue or Esc to exit

/model [model]


AIモデルを変更します

  • Default (Opus + Sonnet)
  • Sonnet

の2つの選択肢があります。最近になってレートリミットの50%までOpusが使われることが明示されました。
モデルをSonnetに変更すると、レートリミットまで緩くなるので用途に合わせてお好みで変更してください。

ちなみに /model Opusを使うと、常にモデルをOpusにしてClaude Codeが動きます

(Opus全振りでAnthropicは使って欲しくないのかもしれない…)

Gitのプルリクエストを表示します。

Claude Codeにプルリクの内容を理解させることができるので、複数人での開発で使用できると思います。
ghコマンドがInstallされていないと使えず、Claude Codeからghコマンドを入れていいか聞かれると思います(律儀)。

/release-notes

リリースノートが見れます。
見てみると結構こまめに機能変更しているので面白いです。

/review

プルリクエストのレビューをClaude Codeにお願いできます。
これも/pr_commentsと同様で、ghコマンドが必要になります。

試しに適当なプロジェクトをレビューしてもらったら、Ratingとか出してくれました。

/status

ステータスが見れます。

  • Working Directory
  • IDE Integration
  • Account
  • Memory
  • Model

などの項目があります

 Claude Code Status v1.0.6

 Working Directory 
  L /Users/workspace/claude/test-1

 IDE Integration • /config
 ✔  Connected to Cursor extension
  L Installed Cursor extension version 1.0.6 (server version: 1.0.5)

 Account • /login
  L Login Method: Claude Max Account
  L Email: [email protected]

 Memory • /memory
  L project: CLAUDE.md

 Model • /model
  L Default Opus 4 for up to 50% of usage limits, then use Sonnet 4 (currently Opus)

ここで自分がClaude Max Accountでログインしているか確認できます

/terminal-setup

Shift-Enterの挙動を変更します。\-Enterと同じ挙動になり、改行による複数行の入力ができるようになります。

/vibe

お楽しみ要素です。
せっかくなので自分で実行してみてください。

/vim

VimモードのON/OFFを設定します。/configコマンドと連動しています。

Custom Slash Command

カスタムスラッシュコマンドは自分でスラッシュコマンドを作ることができます。

例えば、.claude/commands/fix-github-issue.mdを作成したとします。

fix-github-issue.md:

Please analyze and fix the GitHub issue: $ARGUMENTS.

Follow these steps:

1. Use `gh issue view` to get the issue details
2. Understand the problem described in the issue
3. Search the codebase for relevant files
4. Implement the necessary changes to fix the issue
5. Write and run tests to verify the fix
6. Ensure code passes linting and type checking
7. Create a descriptive commit message
8. Push and create a PR

Remember to use the GitHub CLI (`gh`) for all GitHub-related tasks.

Claude Codeはこのコマンドファイルを読み、/project:fix-github-issueというカスタムコマンドを使えるようにします。

このカスタムコマンドは引数を取ることもでき、$ARGUMENTSに代入されます。
実行する際は、/project:fix-github-issue 1234で実行できます。

このサンプルは以下のドキュメントから引用したものです。詳しくは公式ドキュメントを確認してみてください。

https://www.anthropic.com/engineering/claude-code-best-practices

まとめ

Claude Codeのスラッシュコマンドを自分で動かしてみてわかったことを解説しました。

正直、全部書くの大変でした。

訂正や気づいたことがあったら気軽に言ってください。

𝕏フォローしてくれると嬉しいです!

𝕏でも情報発信しているのでよかったらフォローしてくれると、とても励みになります!!

参考文献

https://docs.anthropic.com/ja/docs/claude-code/cli-usage

https://www.anthropic.com/engineering/claude-code-best-practices



Source link

Views: 0

RELATED ARTICLES

返事を書く

あなたのコメントを入力してください。
ここにあなたの名前を入力してください

- Advertisment -