1
5

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 全設定リファレンス 2026 — CLAUDE.md / Hooks / Permissions / MCP を 1 ページで網羅

1
Posted at

この記事は Claude Code の設定をすべて 1 ページにまとめた「永久保存版」です。Hooks / Permissions / MCP を組み合わせた応用も含みます。

この記事でわかること

  • Claude Code のすべての設定項目(2026 年 5 月時点)
  • CLAUDE.md の書き方ベストプラクティス
  • Hooks の全イベントタイプと使い分け
  • Permissions の allow / deny ルール完全リスト
  • MCP サーバー追加・管理のすべてのパターン
  • 設定ファイルの優先順位と上書きルール

目次

  1. 設定ファイルの場所と優先順位
  2. CLAUDE.md 完全リファレンス
  3. settings.json 全項目
  4. Hooks 全イベントタイプ
  5. Permissions ルール完全リスト
  6. MCP サーバー設定
  7. 環境変数
  8. Slash Commands
  9. Keybindings
  10. トラブルシューティング

1. 設定ファイルの場所と優先順位

優先度(高)
    ↑
.claude/settings.local.json          ← 個人設定(gitignore推奨)
.claude/settings.json                ← プロジェクト共有
~/.claude/settings.json              ← グローバル(全プロジェクト)
CLAUDE.md(リポジトリ root)           ← プロジェクト最重要ルール
.claude/CLAUDE.md                    ← プロジェクト追加ルール
~/.claude/CLAUDE.md                  ← グローバルルール
    ↓
優先度(低)

設定の競合時:

  • 同じキー → 上の方が勝つ
  • allow / denydeny が常に優先
  • hooks → 全部実行される(マージされる)

2. CLAUDE.md 完全リファレンス

2.1 基本構造

# プロジェクト名

## このプロジェクトについて
- 技術スタック: Next.js 14, TypeScript, PostgreSQL
- 主な機能: ...

## 絶対ルール
- any 型禁止 → unknown + type guard を使う
- console.log を残さない → logger.ts を使う

## コーディング規約
@include .claude/rules/typescript.md
@include .claude/rules/react.md

## よく使うコマンド
- 開発: `npm run dev`
- テスト: `npm run test`

2.2 @include で分割

300 行を超えそうなら必ず分割:

# CLAUDE.md(60行以内)

## 絶対ルール
(5 個以内)

## 詳細
@include .claude/rules/typescript.md
@include .claude/rules/react.md
@include .claude/rules/api.md

2.3 効果的な書き方

✅ 効果的
- 「any 型禁止。代替: unknown + type guard」
  → なぜ + 代替案がある

❌ 効果が薄い
- 「TypeScript を適切に書く」
  → 抽象的、解釈の余地がある

2.4 サイズ目安

サイズ 評価
〜60 行 ◎ 推奨
60〜150 行 ○ OK
150〜300 行 △ 分割検討
300 行〜 ✕ 精度落ちる

3. settings.json 全項目

~/.claude/settings.json または .claude/settings.json

{
  "permissions": {
    "allow": [...],
    "deny": [...]
  },
  "hooks": {
    "PreToolUse": [...],
    "PostToolUse": [...],
    "Stop": [...],
    "Notification": [...]
  },
  "model": "claude-opus-4-7",
  "mcpServers": {...},
  "env": {...},
  "preferences": {...}
}

主要項目

キー 用途
permissions コマンドの自動承認/拒否
hooks ツール実行前後のスクリプト
model 使用モデル
mcpServers MCP サーバー定義
env 環境変数
preferences UI / UX 設定

4. Hooks 全イベントタイプ

4.1 イベント一覧

Event タイミング 主な用途
PreToolUse ツール実行直前 自動承認・拒否、安全チェック
PostToolUse ツール実行直後 フォーマット、テスト実行、ログ記録
Stop Claude が応答終了 Slack 通知、集計、後処理
Notification 通知発生時 カスタム通知ハンドリング

4.2 matcher で対象ツールを指定

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",                    // Bash だけに適用
        "hooks": [{ "type": "command", "command": "..." }]
      },
      {
        "matcher": "Edit|Write",              // 複数ツール
        "hooks": [{ "type": "command", "command": "..." }]
      },
      {
        "matcher": "*",                        // 全ツール
        "hooks": [{ "type": "command", "command": "..." }]
      }
    ]
  }
}

4.3 Hook 入力 JSON

PreToolUse:

{
  "session_id": "abc123",
  "transcript_path": "/tmp/...",
  "hook_event_name": "PreToolUse",
  "tool_name": "Bash",
  "tool_input": { "command": "npm test" }
}

PostToolUse:

{
  "session_id": "abc123",
  "hook_event_name": "PostToolUse",
  "tool_name": "Edit",
  "tool_input": {...},
  "tool_response": {...}
}

Stop:

{
  "session_id": "abc123",
  "hook_event_name": "Stop",
  "stop_hook_active": false,
  "messages": [...]
}

4.4 Hook の戻り値

戻り値 効果
{"decision": "approve"} 自動承認
{"decision": "block", "reason": "..."} ブロック
何も返さない 通常フロー
文字列を stdout に返す Claude へのフィードバック

5. Permissions ルール完全リスト

5.1 基本フォーマット

{
  "permissions": {
    "allow": [
      "Tool(pattern)",
      "Bash(npm run *)"
    ],
    "deny": [
      "Bash(rm -rf *)"
    ]
  }
}

5.2 ツール別パターン

Bash

"Bash(npm run test)"          // 完全一致
"Bash(npm run *)"             // ワイルドカード
"Bash(git *)"                 // git すべて
"Bash(curl https://example.com/*)"  // URL 制限

Read / Edit / Write

"Read(*)"                     // 全ファイル読み取り
"Read(src/*)"                 // src/ 以下のみ
"Edit(src/*)"                 // src/ 以下の編集
"Write(test/*)"               // test/ 以下の作成

WebSearch / WebFetch

"WebSearch(*)"                // 全検索OK
"WebFetch(https://docs.*)"    // ドキュメントサイトのみ

MCP Tools

"mcp__servername__toolname(*)"  // 特定MCPツール
"mcp__pay-per-call__*"          // 特定MCPサーバーの全ツール

5.3 推奨設定(コピペ可)

グローバル(~/.claude/settings.json):

{
  "permissions": {
    "allow": [
      "Read(*)",
      "Bash(ls *)", "Bash(cat *)", "Bash(echo *)",
      "Bash(pwd)", "Bash(which *)",
      "Bash(git status)", "Bash(git diff*)",
      "Bash(git log*)", "Bash(git branch*)",
      "WebSearch(*)", "WebFetch(*)"
    ],
    "deny": [
      "Bash(rm -rf *)",
      "Bash(git push --force*)",
      "Bash(git reset --hard*)",
      "Bash(sudo *)",
      "Bash(chmod 777*)"
    ]
  }
}

プロジェクト(.claude/settings.json):

{
  "permissions": {
    "allow": [
      "Bash(npm *)", "Bash(npx *)",
      "Bash(node *)", "Bash(pnpm *)",
      "Edit(src/*)", "Edit(tests/*)",
      "Write(src/*)", "Write(tests/*)"
    ],
    "deny": [
      "Edit(.env*)",
      "Bash(npm publish*)"
    ]
  }
}

6. MCP サーバー設定

6.1 基本フォーマット

{
  "mcpServers": {
    "server-name": {
      "command": "npx",
      "args": ["-y", "package-name"],
      "env": {
        "API_KEY": "..."
      }
    }
  }
}

6.2 よく使う MCP サーバー設定

{
  "mcpServers": {
    "pay-per-call": {
      "command": "npx",
      "args": ["-y", "pay-per-call-mcp"],
      "env": {
        "LEMON_CAKE_PAY_TOKEN": "..."
      }
    },
    "gmail": {
      "command": "npx",
      "args": ["-y", "@gongrzhe/server-gmail-autoauth-mcp"]
    },
    "slack": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-slack"],
      "env": {
        "SLACK_BOT_TOKEN": "...",
        "SLACK_TEAM_ID": "..."
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "..."
      }
    }
  }
}

6.3 ローカル開発中の MCP を読み込む

{
  "mcpServers": {
    "my-dev-server": {
      "command": "node",
      "args": ["/Users/me/my-mcp/dist/index.js"]
    }
  }
}

7. 環境変数

変数 用途
ANTHROPIC_API_KEY Claude API キー
CLAUDE_MODEL デフォルトモデル
CLAUDE_HOOK_DEBUG Hook デバッグ出力 ON
CLAUDE_DISABLE_TELEMETRY テレメトリ無効化

~/.claude/.env または ~/.zshrc に設定。


8. Slash Commands

8.1 ビルトイン

コマンド 用途
/help ヘルプ
/clear 履歴クリア
/model モデル切り替え
/init CLAUDE.md 初期化
/review PR レビュー
/security-review セキュリティレビュー

8.2 カスタム Slash Commands

~/.claude/commands/my-command.md

---
description: コミットメッセージを生成
---

git diff --cached を分析して、conventional commits 形式で
コミットメッセージを生成してください。

これで /my-command で呼び出せます。


9. Keybindings

~/.claude/keybindings.json

{
  "ctrl+s": "submit",
  "ctrl+l": "clear",
  "ctrl+shift+v": "paste-image",
  "ctrl+r": "reload"
}

10. トラブルシューティング

10.1 設定が反映されない

□ ファイルパスが正しいか確認
□ JSON のシンタックスエラー(カンマ忘れ)
□ Claude Desktop の場合は Cmd+Q → 再起動
□ Claude Code の場合は session を新規開始

10.2 Hook が動かない

□ スクリプトに実行権限があるか(chmod +x)
□ パスが絶対パスになっているか
□ stdout への output が json として valid か

10.3 MCP サーバーがエラー

□ パッケージ名が正しいか
□ env が必要なら設定されているか
□ ログ確認: ~/Library/Logs/Claude/mcp-server-*.log

10.4 Permissions が効かない

□ パターンのワイルドカードが正しいか
□ deny が優先されるので確認
□ ツール名の大文字小文字

おまけ:最強の Claude Code 設定(コピペ可)

~/.claude/settings.json

{
  "permissions": {
    "allow": [
      "Read(*)",
      "Bash(ls *)", "Bash(cat *)", "Bash(echo *)",
      "Bash(pwd)", "Bash(which *)",
      "Bash(git status)", "Bash(git diff*)",
      "Bash(git log*)", "Bash(git branch*)",
      "Bash(git add *)", "Bash(git commit*)",
      "Bash(npm *)", "Bash(npx *)",
      "Bash(node *)", "Bash(pnpm *)",
      "WebSearch(*)", "WebFetch(*)"
    ],
    "deny": [
      "Bash(rm -rf *)",
      "Bash(git push --force*)",
      "Bash(git reset --hard*)",
      "Bash(sudo *)",
      "Bash(chmod 777*)",
      "Edit(.env*)",
      "Bash(npm publish*)"
    ]
  },
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{
          "type": "command",
          "command": "bash ~/.claude/hooks/format.sh"
        }]
      }
    ],
    "Stop": [
      {
        "hooks": [{
          "type": "command",
          "command": "bash ~/.claude/hooks/notify-done.sh"
        }]
      }
    ]
  }
}

まとめ

設定項目 推奨ファイル
個人の自動承認 .claude/settings.local.json
チーム共通の自動承認 .claude/settings.json
全プロジェクト共通の安全コマンド ~/.claude/settings.json
プロジェクトの絶対ルール CLAUDE.md(root)
個人の好み ~/.claude/CLAUDE.md
MCP サーバー ~/.claude/settings.json または claude_desktop_config.json

Claude Code は「設定を整えるほど高速になる」ツールです。本記事をブックマークしておいて、新しいプロジェクトを始めるたびに参照してください。


参考リンク



試したい人へ

英語の Glama Playground が苦手な人は、以下のコマンドで日本のターミナルから動かせます:

npx -y pay-per-call-mcp@latest
# → 8 つのデモ API がすぐ使えます

設定不要、課金なし、サインアップ不要。

よくある質問(FAQ)

Q. 設定ファイルが多すぎて把握できません
A. 最低限 CLAUDE.md(root)と ~/.claude/settings.json の 2 つだけ覚えれば十分です。あとは必要になったら足してください。

Q. JSON ではなく YAML で書けますか?
A. 現バージョンは JSON のみ対応。コメント可(JSON5 風)で書けます。

Q. チーム全員に同じ設定を強制できますか?
A. .claude/settings.json を git 管理すれば共有できます。ただし個人設定(.local.json)は上書きできるので強制ではありません。

Q. 設定の差分を比較したい
A. claude config diff コマンドで現在の有効な設定とデフォルトの差分を表示できます。

Q. 古い設定を削除したい
A. 不要な項目を削除して保存するだけ。バックアップは ~/.claude/backups/ に自動保存されます。

1
5
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
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?