2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Code チートシート:開発者のための完全リファレンス

Last updated at Posted at 2026-01-28

Claude Code チートシート:開発者のための完全リファレンス

Claude Codeを効率的に使いこなすための、コマンドリファレンスとTips集です。基本操作から高度な機能まで、実務で役立つ情報をまとめました。


📑 目次


基本コマンド

インストール

# ネイティブ版(推奨)
curl -fsSL https://claude.ai/install.sh | bash

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

起動・終了

# 対話モードで起動
claude

# ヘッドレスモード(プロンプト指定)
claude -p "プロンプト" "追加の指示"

# セッションを再開
claude -r <session-id>

# 終了
Ctrl+D または /exit

バージョン確認・更新

# バージョン確認
claude --version

# 更新
claude update

# ヘルスチェック
claude doctor

対話モードのキーボードショートカット

キー 動作
Enter 入力を送信
Shift+Enter 改行(送信しない)
Ctrl+C 現在の応答を中断
Ctrl+D セッションを終了
Ctrl+L 画面をクリア
Up/Down コマンド履歴を表示
Tab 自動補完

スラッシュコマンド一覧

セッション管理

/checkpoint [name]     # 現在の状態を保存
/revert <checkpoint>   # チェックポイントに戻る
/branch <name>         # セッションを分岐
/compact              # コンテキストを圧縮
/exit                 # セッションを終了

設定・表示

/config               # 設定を表示
/config show          # 詳細な設定を表示
/stats                # 使用統計を表示
/costs                # コスト情報を表示
/permissions          # 権限設定を表示

プラグイン管理

/plugin list          # インストール済みプラグインを表示
/plugin add <name>    # プラグインを追加
/plugin remove <name> # プラグインを削除
/plugin update <name> # プラグインを更新
/plugin disable <name> # プラグインを無効化
/plugin enable <name>  # プラグインを有効化

MCPサーバー管理

/mcp list             # MCPサーバーを一覧表示
/mcp add <name>       # MCPサーバーを追加
/mcp remove <name>    # MCPサーバーを削除
/mcp disable <name>   # MCPサーバーを無効化
/mcp enable <name>    # MCPサーバーを有効化

Hooks管理

/hooks list           # Hooksを一覧表示
/hooks disable <hook> # Hookを無効化
/hooks enable <hook>  # Hookを有効化

その他

/help                 # ヘルプを表示
/clear                # 画面をクリア
/logout               # ログアウト

CLIフラグ・オプション

基本オプション

# モデルを指定
claude --model sonnet
claude --model opus
claude --model haiku

# 権限モードを指定
claude --permission-mode default
claude --permission-mode acceptEdits
claude --permission-mode plan
claude --permission-mode bypassPermissions

# プロンプトを指定(ヘッドレスモード)
claude -p "プロンプト"
claude --prompt "プロンプト"

# セッションを再開
claude -r <session-id>
claude --resume <session-id>

高度なオプション

# 許可するツールを指定
claude --allowedTools "Read" "Edit" "Bash"

# 禁止するツールを指定
claude --disallowedTools "WebSearch"

# 認証方法を指定
claude --auth bedrock
claude --auth vertex
claude --auth foundry

# デバッグモード
claude --debug
claude --debug "api,mcp"

# 設定ファイルを指定
claude --config /path/to/config.yaml

設定ファイルの場所

設定ファイルの優先順位

  1. Managed(最優先): 組織管理者が設定
  2. Local: .claude/config.local.yaml
  3. Project: .claude/config.yaml
  4. User: ~/.config/claude-code/config.yaml

主要な設定ファイル

# ユーザー設定
~/.config/claude-code/config.yaml

# 認証情報
~/.config/claude-code/auth.json

# プロジェクト設定
.claude/config.yaml

# ローカル設定(Gitにコミットしない)
.claude/config.local.yaml

# セッションデータ
~/.local/share/claude-code/sessions/

# ログ
~/.local/share/claude-code/logs/

サブエージェント活用Tips

組み込みエージェントの使い分け

# 一般的なタスク
> このファイルをリファクタリングして

# 計画立案
> このプロジェクトの実装計画を立てて
# → Plan agentが自動的に呼ばれる

# コードベース探索
> このプロジェクトの構造を教えて
# → Explore agentが自動的に呼ばれる

カスタムエージェントの定義

# .claude/config.yaml
agents:
  code-review:
    description: "コードレビュー専用エージェント"
    model: "opus"
    systemPrompt: |
      あなたは経験豊富なコードレビュアーです。
      以下の観点でレビューしてください:
      - コードの可読性
      - パフォーマンス
      - セキュリティ
      - ベストプラクティス
    allowedTools:
      - "Read"
      - "Grep"

エージェントの呼び出し

# 自動呼び出し(対話から推測)
> このコードをレビューして

# 明示的な呼び出し
> @code-review このファイルをレビューして

MCPサーバー設定例

GitHub統合

# .claude/config.yaml
mcpServers:
  github:
    transport: "http"
    url: "https://api.github.com/mcp"
    auth:
      type: "bearer"
      token: "${GITHUB_TOKEN}"
# 環境変数を設定
export GITHUB_TOKEN="your_token_here"

ローカルファイルシステム

mcpServers:
  filesystem:
    transport: "stdio"
    command: "npx"
    args:
      - "-y"
      - "@modelcontextprotocol/server-filesystem"
      - "${HOME}/documents"

PostgreSQL

mcpServers:
  postgres:
    transport: "stdio"
    command: "npx"
    args:
      - "-y"
      - "@modelcontextprotocol/server-postgres"
    env:
      DATABASE_URL: "${DATABASE_URL}"

Hooks実践例

自動フォーマット(PostToolUse)

# .claude/config.yaml
hooks:
  PostToolUse:
    - matcher:
        tool: "Edit"
        path: "*.js"
      hooks:
        - "npx prettier --write {{path}}"

自動テスト(PostToolUse)

hooks:
  PostToolUse:
    - matcher:
        tool: "Edit"
        path: "src/**/*.ts"
      hooks:
        - "npm test -- {{path}}.test.ts || true"

本番ファイル保護(PreToolUse)

hooks:
  PreToolUse:
    - matcher:
        tool: "Edit"
        path: "production/*"
      hooks:
        - "echo 'Error: Cannot edit production files' && exit 1"

Git自動ステージング(PostToolUse)

hooks:
  PostToolUse:
    - matcher:
        tool: "Edit"
      hooks:
        - "git add {{path}} || true"

環境変数の読み込み(SessionStart)

hooks:
  SessionStart:
    - hooks:
        - "[ -f .env ] && export $(cat .env | xargs)"

よく使う設定例

最小限の設定(初心者向け)

# .claude/config.yaml
model: "sonnet"
permissionMode: "acceptEdits"

実用的な設定(中級者向け)

# .claude/config.yaml
model: "sonnet"
permissionMode: "acceptEdits"

enablePromptCaching: true

agents:
  explore:
    model: "haiku"
    allowedTools: ["Read", "Grep", "Glob"]

hooks:
  PostToolUse:
    - matcher:
        tool: "Edit"
        path: "*.{js,ts,jsx,tsx}"
      hooks:
        - "npx prettier --write {{path}}"

フル機能設定(上級者向け)

# .claude/config.yaml
model: "sonnet"
permissionMode: "default"

enablePromptCaching: true

sandbox:
  enabled: true
  autoAllowBashIfSandboxed: true

network:
  enabled: true
  allowedDomains:
    - "github.com"
    - "*.npmjs.com"

agents:
  code-review:
    model: "opus"
    systemPrompt: "詳細なコードレビューを実施"
    allowedTools: ["Read", "Grep"]

mcpServers:
  github:
    transport: "http"
    url: "https://api.github.com/mcp"
    auth:
      type: "bearer"
      token: "${GITHUB_TOKEN}"

hooks:
  PostToolUse:
    - matcher:
        tool: "Edit"
        path: "*.{js,ts}"
      hooks:
        - "npx prettier --write {{path}}"
        - "npm test -- {{path}}.test.* || true"

audit:
  enabled: true
  logLevel: "standard"
  logFile: ".claude/audit.log"

トラブルシューティング

よくある問題と解決方法

問題1:認証エラー

# 解決方法:再認証
> /logout
claude

問題2:コマンドが見つからない

# 解決方法:PATHを確認
echo $PATH

# PATHに追加
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

問題3:応答が遅い

# 解決方法:コンテキストを圧縮
> /compact

# または新しいセッションを開始
claude

問題4:WebSearchが使えない

# 解決方法:ネットワークを有効化
network:
  enabled: true

問題5:MCPサーバーに接続できない

# 環境変数を確認
echo $GITHUB_TOKEN

# MCPサーバーのステータス確認
> /mcp list

# 手動でテスト
curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/mcp

便利なTips

Tip 1: プロンプトの効果的な書き方

良い例:

このReactコンポーネントをTypeScriptに変換して。
型定義を追加し、PropsとStateを明示的に定義してください。

悪い例:

TSに変換

Tip 2: ファイル指定の方法

# 特定のファイルを参照
> src/App.jsを読み込んで

# パターンマッチ
> src/**/*.tsのすべてのファイルを分析して

# 複数ファイル
> App.jsとApp.test.jsを比較して

Tip 3: セッション管理のベストプラクティス

# 重要な作業前にチェックポイントを作成
> /checkpoint before-refactor

# 失敗したら元に戻す
> /revert before-refactor

# 別のアプローチを試す場合は分岐
> /branch alternative-approach

Tip 4: プロンプトキャッシングの活用

# プロンプトキャッシングを有効化(コスト削減)
enablePromptCaching: true

長いコンテキストを繰り返し使う場合、最大90%のコスト削減が可能。

Tip 5: 権限の永続化

対話中に「今後聞かない」を選択することで、特定のコマンドやファイルへの操作を自動承認できます。

# 権限をリセットしたい場合
> /permissions reset

クイックリファレンス

🚀 最速スタート(3ステップ)

# 1. インストール
curl -fsSL https://claude.ai/install.sh | bash

# 2. 起動
claude

# 3. 使ってみる
> このディレクトリのファイル構造を教えて

📝 毎日使うコマンドTop 5

  1. claude - 起動
  2. /checkpoint - 保存
  3. /compact - コンテキスト圧縮
  4. Ctrl+C - 応答中断
  5. /exit - 終了

🎯 生産性を上げる設定Top 3

  1. acceptEditsモード: 編集を自動承認

    claude --permission-mode acceptEdits
    
  2. Hooks: 自動フォーマット・テスト

    hooks:
      PostToolUse:
        - matcher:
            tool: "Edit"
          hooks:
            - "prettier --write {{path}}"
    
  3. サブエージェント: タスクを分散

    agents:
      explore:
        model: "haiku"
    

このチートシートを手元に置いて、Claude Codeを使いこなしましょう! 🚀

最終更新:2026年1月26日

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?