このスキルの用途: ユーザーが「プラグイン設定」「プラグイン設定の保存」「ユーザーがカスタマイズできるプラグイン」「.local.md ファイル」「プラグインの状態ファイル」「YAML フロントマター(ファイル先頭のメタデータ)の読み込み」「プロジェクトごとのプラグイン設定」などについて尋ねたり、プラグインの動作をカスタマイズ可能にしたいと考えたりしている場合に使用します。 このスキルは、`.claude/plugin-name.local.md` というファイルパターンを使い、YAML フロントマター(データ形式)とマークダウンテキストを組み合わせてプラグイン固有の設定を保存する方法について説明します。
This skill should be used when the user asks about "plugin settings", "store plugin configuration", "user-configurable plugin", ".local.md files", "plugin state files", "read YAML frontmatter", "per-project plugin settings", or wants to make plugin behavior configurable. Documents the .claude/plugin-name.local.md pattern for storing plugin-specific configuration with YAML frontmatter and markdown content.
プラグインは、プロジェクトディレクトリ内の .claude/プラグイン名.local.md ファイルにユーザーが設定可能な設定と状態を保存できます。このパターンでは、YAML フロントマター(ファイルの冒頭に記述される設定情報)を構造化された設定用に、マークダウン本文をプロンプトや追加の文脈用に使用します。
主な特徴:
.claude/プラグイン名.local.md.gitignore に記述すること)---
enabled: true
setting1: value1
setting2: value2
numeric_setting: 42
list_setting: ["item1", "item2"]
---
# 追加の文脈
このマークダウン本文には以下を記述できます:
- タスク説明
- 追加の指示
- Claude に返すプロンプト
- ドキュメントやメモ
.claude/my-plugin.local.md:
---
enabled: true
strict_mode: false
max_retries: 3
notification_level: info
coordinator_session: team-leader
---
# プラグイン設定
このプラグインは標準検証モードで設定されています。
質問は @team-lead に連絡してください。
パターン: ファイルの存在確認とフロントマター解析
#!/bin/bash
set -euo pipefail
# 状態ファイルのパスを定義
STATE_FILE=".claude/my-plugin.local.md"
# ファイルが存在しない場合は終了
if [[ ! -f "$STATE_FILE" ]]; then
exit 0 # プラグイン未設定、スキップ
fi
# YAML フロントマター(--- で囲まれた部分)を解析
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE")
# 個別フィールドを抽出
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//' | sed 's/^"\(.*\)"$/\1/')
STRICT_MODE=$(echo "$FRONTMATTER" | grep '^strict_mode:' | sed 's/strict_mode: *//' | sed 's/^"\(.*\)"$/\1/')
# 有効かチェック
if [[ "$ENABLED" != "true" ]]; then
exit 0 # 無効
fi
# 設定をフック処理に使用
if [[ "$STRICT_MODE" == "true" ]]; then
# 厳密な検証を適用
# ...
fi
完全に動作する例は examples/read-settings-hook.sh を参照してください。
コマンドは設定ファイルを読み込んで動作をカスタマイズできます:
---
description: プラグインを使用してデータを処理
allowed-tools: ["Read", "Bash"]
---
# 処理コマンド
手順:
1. `.claude/my-plugin.local.md` に設定が存在するかチェック
2. Read ツールを使用して設定ファイルを読み込み
3. YAML フロントマターをパースして設定を抽出
4. 処理ロジックに設定を適用
5. 設定された動作で実行
エージェントは指示内で設定を参照できます:
---
name: configured-agent
description: プロジェクト設定に適応するエージェント
---
`.claude/my-plugin.local.md` でプラグイン設定をチェック。
存在する場合は YAML フロントマターをパースして、以下に従い動作を調整:
- enabled: プラグインがアクティブか
- mode: 処理モード(strict=厳密、standard=標準、lenient=寛容)
- その他の設定フィールド
# --- で囲まれた部分をすべて抽出
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE")
テキストフィールド:
VALUE=$(echo "$FRONTMATTER" | grep '^field_name:' | sed 's/field_name: *//' | sed 's/^"\(.*\)"$/\1/')
真偽値フィールド:
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//')
# 比較: if [[ "$ENABLED" == "true" ]]; then
数値フィールド:
MAX=$(echo "$FRONTMATTER" | grep '^max_value:' | sed 's/max_value: *//')
# 使用: if [[ $MAX -gt 100 ]]; then
2番目の --- の後のコンテンツを抽出:
# 終了--- の後のすべてを取得
BODY=$(awk '/^---$/{i++; next} i>=2' "$FILE")
設定ファイルを使用してフック実行を制御:
#!/bin/bash
STATE_FILE=".claude/security-scan.local.md"
# 設定されていない場合は終了
if [[ ! -f "$STATE_FILE" ]]; then
exit 0
fi
# 有効フラグを読み込み
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE")
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//')
if [[ "$ENABLED" != "true" ]]; then
exit 0 # 無効
fi
# フック処理を実行
# ...
次のような場合に使用: hooks.json を編集せずに、フック実行を有効/無効にしたい場合(再起動不要で対応可能にしたい場合)
エージェント固有の状態と設定を保存:
.claude/multi-agent-swarm.local.md:
---
agent_name: auth-agent
task_number: 3.5
pr_number: 1234
coordinator_session: team-leader
enabled: true
dependencies: ["Task 3.4"]
---
# タスク割り当て
API に JWT 認証を実装。
**成功条件:**
- 認証エンドポイントの作成
- テスト合格
- PR 作成と CI パス
フックから読み込んでエージェントを調整:
AGENT_NAME=$(echo "$FRONTMATTER" | grep '^agent_name:' | sed 's/agent_name: *//')
COORDINATOR=$(echo "$FRONTMATTER" | grep '^coordinator_session:' | sed 's/coordinator_session: *//')
# コーディネーターに通知を送信
tmux send-keys -t "$COORDINATOR" "Agent $AGENT_NAME completed task" Enter
.claude/my-plugin.local.md:
---
validation_level: strict
max_file_size: 1000000
allowed_extensions: [".js", ".ts", ".tsx"]
enable_logging: true
---
# 検証設定
このプロジェクトは厳密モードで有効です。
すべての書き込みはセキュリティポリシーに対して検証されます。
フックやコマンドで使用:
LEVEL=$(echo "$FRONTMATTER" | grep '^validation_level:' | sed 's/validation_level: *//')
case "$LEVEL" in
strict)
# 厳密な検証を適用
;;
standard)
# 標準検証を適用
;;
lenient)
# 寛容な検証を適用
;;
esac
コマンドは設定ファイルを作成できます:
# セットアップコマンド
手順:
1. ユーザーに設定の好みを質問
2. YAML フロントマター付きで `.claude/my-plugin.local.md` を作成
3. ユーザー入力に基づいて適切な値を設定
4. 設定が保存されたことをユーザーに通知
5. フックが認識されるよう Claude Code の再起動を促す
プラグイン README にテンプレートを提供:
## 設定
プロジェクトに `.claude/my-plugin.local.md` を作成:
\`\`\`markdown
---
enabled: true
mode: standard
max_retries: 3
---
# プラグイン設定
設定がアクティブです。
\`\`\`
作成または編集後、Claude Code を再起動して変更を反映させてください。
✅ 推奨:
.claude/プラグイン名.local.md 形式を使用.local.md サフィックスを使用❌ 非推奨:
.claude/ ではなく).local なしで .md のみ(コミットされる恐れ)常に .gitignore に追加:
.claude/*.local.md
.claude/*.local.json
プラグイン README に記載してください。
設定ファイルが存在しない場合は適切なデフォルト値を提供:
if [[ ! -f "$STATE_FILE" ]]; then
# デフォルトを使用
ENABLED=true
MODE=standard
else
# ファイルから読み込み
# ...
fi
設定値を検証:
MAX=$(echo "$FRONTMATTER" | grep '^max_value:' | sed 's/max_value: *//')
# 数値範囲を検証
if ! [[ "$MAX" =~ ^[0-9]+$ ]] || [[ $MAX -lt 1 ]] || [[ $MAX -gt 100 ]]; then
echo "⚠️ 設定の max_value が無効です(1〜100 である必要があります)" >&2
MAX=10 # デフォルトを使用
fi
重要: 設定の変更には Claude Code の再起動が必要です。
README に記載:
## 設定の変更
`.claude/my-plugin.local.md` を編集後:
1. ファイルを保存
2. Claude Code を終了
3. 再起動: `claude` または `cc`
4. 新しい設定が読み込まれます
フックはセッション内でホットリロード(再起動なしの即時反映)できません。
ユーザー入力から設定ファイルを書き込む場合:
# ユーザー入力内の引用符をエスケープ
SAFE_VALUE=$(echo "$USER_INPUT" | sed 's/"/\\"/g')
# ファイルに書き込み
cat > "$STATE_FILE" <<EOF
---
user_setting: "$SAFE_VALUE"
---
EOF
設定にファイルパスが含まれる場合:
FILE_PATH=$(echo "$FRONTMATTER" | grep '^data_file:' | sed 's/data_file: *//')
# パストラバーサル(不正なパス指定)をチェック
if [[ "$FILE_PATH" == *".."* ]]; then
echo "⚠️ 設定のパスが無効です(パストラバーサル)" >&2
exit 2
fi
設定ファイルは:
chmod 600).claude/multi-agent-swarm.local.md:
---
agent_name: auth-implementation
task_number: 3.5
pr_number: 1234
coordinator_session: team-leader
enabled: true
dependencies: ["Task 3.4"]
additional_instructions: JWT トークンを使用(セッションではなく)
---
# タスク: 認証を実装
REST API 用に JWT ベースの認証を構築。
共有型について auth-agent と調整。
フックの使用例(agent-stop-notification.sh):
enabled: true/false で素早くアクティベーション/ディアクティベーション可能.claude/ralph-loop.local.md:
---
iteration: 1
max_iterations: 10
completion_promise: "すべてのテスト合格、ビルド成功"
---
プロジェク
Plugins can store user-configurable settings and state in .claude/plugin-name.local.md files within the project directory. This pattern uses YAML frontmatter for structured configuration and markdown content for prompts or additional context.
Key characteristics:
.claude/plugin-name.local.md in project root.gitignore)---
enabled: true
setting1: value1
setting2: value2
numeric_setting: 42
list_setting: ["item1", "item2"]
---
# Additional Context
This markdown body can contain:
- Task descriptions
- Additional instructions
- Prompts to feed back to Claude
- Documentation or notes
.claude/my-plugin.local.md:
---
enabled: true
strict_mode: false
max_retries: 3
notification_level: info
coordinator_session: team-leader
---
# Plugin Configuration
This plugin is configured for standard validation mode.
Contact @team-lead with questions.
Pattern: Check existence and parse frontmatter
#!/bin/bash
set -euo pipefail
# Define state file path
STATE_FILE=".claude/my-plugin.local.md"
# Quick exit if file doesn't exist
if [[ ! -f "$STATE_FILE" ]]; then
exit 0 # Plugin not configured, skip
fi
# Parse YAML frontmatter (between --- markers)
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE")
# Extract individual fields
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//' | sed 's/^"\(.*\)"$/\1/')
STRICT_MODE=$(echo "$FRONTMATTER" | grep '^strict_mode:' | sed 's/strict_mode: *//' | sed 's/^"\(.*\)"$/\1/')
# Check if enabled
if [[ "$ENABLED" != "true" ]]; then
exit 0 # Disabled
fi
# Use configuration in hook logic
if [[ "$STRICT_MODE" == "true" ]]; then
# Apply strict validation
# ...
fi
See examples/read-settings-hook.sh for complete working example.
Commands can read settings files to customize behavior:
---
description: Process data with plugin
allowed-tools: ["Read", "Bash"]
---
# Process Command
Steps:
1. Check if settings exist at `.claude/my-plugin.local.md`
2. Read configuration using Read tool
3. Parse YAML frontmatter to extract settings
4. Apply settings to processing logic
5. Execute with configured behavior
Agents can reference settings in their instructions:
---
name: configured-agent
description: Agent that adapts to project settings
---
Check for plugin settings at `.claude/my-plugin.local.md`.
If present, parse YAML frontmatter and adapt behavior according to:
- enabled: Whether plugin is active
- mode: Processing mode (strict, standard, lenient)
- Additional configuration fields
# Extract everything between --- markers
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE")
String fields:
VALUE=$(echo "$FRONTMATTER" | grep '^field_name:' | sed 's/field_name: *//' | sed 's/^"\(.*\)"$/\1/')
Boolean fields:
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//')
# Compare: if [[ "$ENABLED" == "true" ]]; then
Numeric fields:
MAX=$(echo "$FRONTMATTER" | grep '^max_value:' | sed 's/max_value: *//')
# Use: if [[ $MAX -gt 100 ]]; then
Extract content after second ---:
# Get everything after closing ---
BODY=$(awk '/^---$/{i++; next} i>=2' "$FILE")
Use settings file to control hook activation:
#!/bin/bash
STATE_FILE=".claude/security-scan.local.md"
# Quick exit if not configured
if [[ ! -f "$STATE_FILE" ]]; then
exit 0
fi
# Read enabled flag
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE")
ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//')
if [[ "$ENABLED" != "true" ]]; then
exit 0 # Disabled
fi
# Run hook logic
# ...
Use case: Enable/disable hooks without editing hooks.json (requires restart).
Store agent-specific state and configuration:
.claude/multi-agent-swarm.local.md:
---
agent_name: auth-agent
task_number: 3.5
pr_number: 1234
coordinator_session: team-leader
enabled: true
dependencies: ["Task 3.4"]
---
# Task Assignment
Implement JWT authentication for the API.
**Success Criteria:**
- Authentication endpoints created
- Tests passing
- PR created and CI green
Read from hooks to coordinate agents:
AGENT_NAME=$(echo "$FRONTMATTER" | grep '^agent_name:' | sed 's/agent_name: *//')
COORDINATOR=$(echo "$FRONTMATTER" | grep '^coordinator_session:' | sed 's/coordinator_session: *//')
# Send notification to coordinator
tmux send-keys -t "$COORDINATOR" "Agent $AGENT_NAME completed task" Enter
.claude/my-plugin.local.md:
---
validation_level: strict
max_file_size: 1000000
allowed_extensions: [".js", ".ts", ".tsx"]
enable_logging: true
---
# Validation Configuration
Strict mode enabled for this project.
All writes validated against security policies.
Use in hooks or commands:
LEVEL=$(echo "$FRONTMATTER" | grep '^validation_level:' | sed 's/validation_level: *//')
case "$LEVEL" in
strict)
# Apply strict validation
;;
standard)
# Apply standard validation
;;
lenient)
# Apply lenient validation
;;
esac
Commands can create settings files:
# Setup Command
Steps:
1. Ask user for configuration preferences
2. Create `.claude/my-plugin.local.md` with YAML frontmatter
3. Set appropriate values based on user input
4. Inform user that settings are saved
5. Remind user to restart Claude Code for hooks to recognize changes
Provide template in plugin README:
## Configuration
Create `.claude/my-plugin.local.md` in your project:
\`\`\`markdown
---
enabled: true
mode: standard
max_retries: 3
---
# Plugin Configuration
Your settings are active.
\`\`\`
After creating or editing, restart Claude Code for changes to take effect.
✅ DO:
.claude/plugin-name.local.md format.local.md suffix for user-local files❌ DON'T:
.claude/).md without .local (might be committed)Always add to .gitignore:
.claude/*.local.md
.claude/*.local.json
Document this in plugin README.
Provide sensible defaults when settings file doesn't exist:
if [[ ! -f "$STATE_FILE" ]]; then
# Use defaults
ENABLED=true
MODE=standard
else
# Read from file
# ...
fi
Validate settings values:
MAX=$(echo "$FRONTMATTER" | grep '^max_value:' | sed 's/max_value: *//')
# Validate numeric range
if ! [[ "$MAX" =~ ^[0-9]+$ ]] || [[ $MAX -lt 1 ]] || [[ $MAX -gt 100 ]]; then
echo "⚠️ Invalid max_value in settings (must be 1-100)" >&2
MAX=10 # Use default
fi
Important: Settings changes require Claude Code restart.
Document in your README:
## Changing Settings
After editing `.claude/my-plugin.local.md`:
1. Save the file
2. Exit Claude Code
3. Restart: `claude` or `cc`
4. New settings will be loaded
Hooks cannot be hot-swapped within a session.
When writing settings files from user input:
# Escape quotes in user input
SAFE_VALUE=$(echo "$USER_INPUT" | sed 's/"/\\"/g')
# Write to file
cat > "$STATE_FILE" <<EOF
---
user_setting: "$SAFE_VALUE"
---
EOF
If settings contain file paths:
FILE_PATH=$(echo "$FRONTMATTER" | grep '^data_file:' | sed 's/data_file: *//')
# Check for path traversal
if [[ "$FILE_PATH" == *".."* ]]; then
echo "⚠️ Invalid path in settings (path traversal)" >&2
exit 2
fi
Settings files should be:
chmod 600).claude/multi-agent-swarm.local.md:
---
agent_name: auth-implementation
task_number: 3.5
pr_number: 1234
coordinator_session: team-leader
enabled: true
dependencies: ["Task 3.4"]
additional_instructions: Use JWT tokens, not sessions
---
# Task: Implement Authentication
Build JWT-based authentication for the REST API.
Coordinate with auth-agent on shared types.
Hook usage (agent-stop-notification.sh):
enabled: true/false.claude/ralph-loop.local.md:
---
iteration: 1
max_iterations: 10
completion_promise: "All tests passing and build successful"
---
Fix all the linting errors in the project.
Make sure tests pass after each fix.
Hook usage (stop-hook.sh):
project-root/
└── .claude/
└── plugin-name.local.md
# Extract frontmatter
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE")
# Read field
VALUE=$(echo "$FRONTMATTER" | grep '^field:' | sed 's/field: *//' | sed 's/^"\(.*\)"$/\1/')
# Extract body (after second ---)
BODY=$(awk '/^---$/{i++; next} i>=2' "$FILE")
if [[ ! -f ".claude/my-plugin.local.md" ]]; then
exit 0 # Not configured
fi
For detailed implementation patterns:
references/parsing-techniques.md - Complete guide to parsing YAML frontmatter and markdown bodiesreferences/real-world-examples.md - Deep dive into multi-agent-swarm and ralph-loop implementationsWorking examples in examples/:
read-settings-hook.sh - Hook that reads and uses settingscreate-settings-command.md - Command that creates settings fileexample-settings.md - Template settings fileDevelopment tools in scripts/:
validate-settings.sh - Validate settings file structureparse-frontmatter.sh - Extract frontmatter fieldsTo add settings to a plugin:
.claude/*.local.mdFocus on keeping settings simple and providing good defaults when settings file doesn't exist.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。