$npx -y skills add anthropics/claude-code --skill plugin-settingsThis 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. Document
| 1 | # Plugin Settings Pattern for Claude Code Plugins |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | **Key characteristics:** |
| 8 | - File location: `.claude/plugin-name.local.md` in project root |
| 9 | - Structure: YAML frontmatter + markdown body |
| 10 | - Purpose: Per-project plugin configuration and state |
| 11 | - Usage: Read from hooks, commands, and agents |
| 12 | - Lifecycle: User-managed (not in git, should be in `.gitignore`) |
| 13 | |
| 14 | ## File Structure |
| 15 | |
| 16 | ### Basic Template |
| 17 | |
| 18 | ```markdown |
| 19 | --- |
| 20 | enabled: true |
| 21 | setting1: value1 |
| 22 | setting2: value2 |
| 23 | numeric_setting: 42 |
| 24 | list_setting: ["item1", "item2"] |
| 25 | --- |
| 26 | |
| 27 | # Additional Context |
| 28 | |
| 29 | This markdown body can contain: |
| 30 | - Task descriptions |
| 31 | - Additional instructions |
| 32 | - Prompts to feed back to Claude |
| 33 | - Documentation or notes |
| 34 | ``` |
| 35 | |
| 36 | ### Example: Plugin State File |
| 37 | |
| 38 | **.claude/my-plugin.local.md:** |
| 39 | ```markdown |
| 40 | --- |
| 41 | enabled: true |
| 42 | strict_mode: false |
| 43 | max_retries: 3 |
| 44 | notification_level: info |
| 45 | coordinator_session: team-leader |
| 46 | --- |
| 47 | |
| 48 | # Plugin Configuration |
| 49 | |
| 50 | This plugin is configured for standard validation mode. |
| 51 | Contact @team-lead with questions. |
| 52 | ``` |
| 53 | |
| 54 | ## Reading Settings Files |
| 55 | |
| 56 | ### From Hooks (Bash Scripts) |
| 57 | |
| 58 | **Pattern: Check existence and parse frontmatter** |
| 59 | |
| 60 | ```bash |
| 61 | #!/bin/bash |
| 62 | set -euo pipefail |
| 63 | |
| 64 | # Define state file path |
| 65 | STATE_FILE=".claude/my-plugin.local.md" |
| 66 | |
| 67 | # Quick exit if file doesn't exist |
| 68 | if [[ ! -f "$STATE_FILE" ]]; then |
| 69 | exit 0 # Plugin not configured, skip |
| 70 | fi |
| 71 | |
| 72 | # Parse YAML frontmatter (between --- markers) |
| 73 | FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE") |
| 74 | |
| 75 | # Extract individual fields |
| 76 | ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//' | sed 's/^"\(.*\)"$/\1/') |
| 77 | STRICT_MODE=$(echo "$FRONTMATTER" | grep '^strict_mode:' | sed 's/strict_mode: *//' | sed 's/^"\(.*\)"$/\1/') |
| 78 | |
| 79 | # Check if enabled |
| 80 | if [[ "$ENABLED" != "true" ]]; then |
| 81 | exit 0 # Disabled |
| 82 | fi |
| 83 | |
| 84 | # Use configuration in hook logic |
| 85 | if [[ "$STRICT_MODE" == "true" ]]; then |
| 86 | # Apply strict validation |
| 87 | # ... |
| 88 | fi |
| 89 | ``` |
| 90 | |
| 91 | See `examples/read-settings-hook.sh` for complete working example. |
| 92 | |
| 93 | ### From Commands |
| 94 | |
| 95 | Commands can read settings files to customize behavior: |
| 96 | |
| 97 | ```markdown |
| 98 | --- |
| 99 | description: Process data with plugin |
| 100 | allowed-tools: ["Read", "Bash"] |
| 101 | --- |
| 102 | |
| 103 | # Process Command |
| 104 | |
| 105 | Steps: |
| 106 | 1. Check if settings exist at `.claude/my-plugin.local.md` |
| 107 | 2. Read configuration using Read tool |
| 108 | 3. Parse YAML frontmatter to extract settings |
| 109 | 4. Apply settings to processing logic |
| 110 | 5. Execute with configured behavior |
| 111 | ``` |
| 112 | |
| 113 | ### From Agents |
| 114 | |
| 115 | Agents can reference settings in their instructions: |
| 116 | |
| 117 | ```markdown |
| 118 | --- |
| 119 | name: configured-agent |
| 120 | description: Agent that adapts to project settings |
| 121 | --- |
| 122 | |
| 123 | Check for plugin settings at `.claude/my-plugin.local.md`. |
| 124 | If present, parse YAML frontmatter and adapt behavior according to: |
| 125 | - enabled: Whether plugin is active |
| 126 | - mode: Processing mode (strict, standard, lenient) |
| 127 | - Additional configuration fields |
| 128 | ``` |
| 129 | |
| 130 | ## Parsing Techniques |
| 131 | |
| 132 | ### Extract Frontmatter |
| 133 | |
| 134 | ```bash |
| 135 | # Extract everything between --- markers |
| 136 | FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE") |
| 137 | ``` |
| 138 | |
| 139 | ### Read Individual Fields |
| 140 | |
| 141 | **String fields:** |
| 142 | ```bash |
| 143 | VALUE=$(echo "$FRONTMATTER" | grep '^field_name:' | sed 's/field_name: *//' | sed 's/^"\(.*\)"$/\1/') |
| 144 | ``` |
| 145 | |
| 146 | **Boolean fields:** |
| 147 | ```bash |
| 148 | ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//') |
| 149 | # Compare: if [[ "$ENABLED" == "true" ]]; then |
| 150 | ``` |
| 151 | |
| 152 | **Numeric fields:** |
| 153 | ```bash |
| 154 | MAX=$(echo "$FRONTMATTER" | grep '^max_value:' | sed 's/max_value: *//') |
| 155 | # Use: if [[ $MAX -gt 100 ]]; then |
| 156 | ``` |
| 157 | |
| 158 | ### Read Markdown Body |
| 159 | |
| 160 | Extract content after second `---`: |
| 161 | |
| 162 | ```bash |
| 163 | # Get everything after closing --- |
| 164 | BODY=$(awk '/^---$/{i++; next} i>=2' "$FILE") |
| 165 | ``` |
| 166 | |
| 167 | ## Common Patterns |
| 168 | |
| 169 | ### Pattern 1: Temporarily Active Hooks |
| 170 | |
| 171 | Use settings file to control hook activation: |
| 172 | |
| 173 | ```bash |
| 174 | #!/bin/bash |
| 175 | STATE_FILE=".claude/security-scan.local.md" |
| 176 | |
| 177 | # Quick exit if not configured |
| 178 | if [[ ! -f "$STATE_FILE" ]]; then |
| 179 | exit 0 |
| 180 | fi |
| 181 | |
| 182 | # Read enabled flag |
| 183 | FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$STATE_FILE") |
| 184 | ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//') |
| 185 | |
| 186 | if [[ "$ENABLED" != "true" ]]; then |
| 187 | exit 0 # Disabled |
| 188 | fi |
| 189 | |
| 190 | # Run hook logic |
| 191 | # ... |
| 192 | ``` |
| 193 | |
| 194 | **Use case:** Enable/disable hooks without editing hooks.json (requires restart). |
| 195 | |
| 196 | ### Pattern 2: Agent State Management |
| 197 | |
| 198 | Store agent-specific state and configuration: |
| 199 | |
| 200 | **.claude/multi-agent-swarm.local.md:** |
| 201 | ```markdow |