Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Pattern documentation for configuring settings in Claude Code plugins (from the official Anthropic claude-code repo).
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/real-world-examples.md
1# Real-World Plugin Settings Examples23Detailed analysis of how production plugins use the `.claude/plugin-name.local.md` pattern.45## multi-agent-swarm Plugin67### Settings File Structure89**.claude/multi-agent-swarm.local.md:**1011```markdown12---13agent_name: auth-implementation14task_number: 3.515pr_number: 123416coordinator_session: team-leader17enabled: true18dependencies: ["Task 3.4"]19additional_instructions: "Use JWT tokens, not sessions"20---2122# Task: Implement Authentication2324Build JWT-based authentication for the REST API.2526## Requirements27- JWT token generation and validation28- Refresh token flow29- Secure password hashing3031## Success Criteria32- Auth endpoints implemented33- Tests passing (100% coverage)34- PR created and CI green35- Documentation updated3637## Coordination38Depends on Task 3.4 (user model).39Report status to 'team-leader' session.40```4142### How It's Used4344**File:** `hooks/agent-stop-notification.sh`4546**Purpose:** Send notifications to coordinator when agent becomes idle4748**Implementation:**4950```bash51#!/bin/bash52set -euo pipefail5354SWARM_STATE_FILE=".claude/multi-agent-swarm.local.md"5556# Quick exit if no swarm active57if [[ ! -f "$SWARM_STATE_FILE" ]]; then58exit 059fi6061# Parse frontmatter62FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$SWARM_STATE_FILE")6364# Extract configuration65COORDINATOR_SESSION=$(echo "$FRONTMATTER" | grep '^coordinator_session:' | sed 's/coordinator_session: *//' | sed 's/^"\(.*\)"$/\1/')66AGENT_NAME=$(echo "$FRONTMATTER" | grep '^agent_name:' | sed 's/agent_name: *//' | sed 's/^"\(.*\)"$/\1/')67TASK_NUMBER=$(echo "$FRONTMATTER" | grep '^task_number:' | sed 's/task_number: *//' | sed 's/^"\(.*\)"$/\1/')68PR_NUMBER=$(echo "$FRONTMATTER" | grep '^pr_number:' | sed 's/pr_number: *//' | sed 's/^"\(.*\)"$/\1/')69ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//')7071# Check if enabled72if [[ "$ENABLED" != "true" ]]; then73exit 074fi7576# Send notification to coordinator77NOTIFICATION="๐ค Agent ${AGENT_NAME} (Task ${TASK_NUMBER}, PR #${PR_NUMBER}) is idle."7879if tmux has-session -t "$COORDINATOR_SESSION" 2>/dev/null; then80tmux send-keys -t "$COORDINATOR_SESSION" "$NOTIFICATION" Enter81sleep 0.582tmux send-keys -t "$COORDINATOR_SESSION" Enter83fi8485exit 086```8788**Key patterns:**891. **Quick exit** (line 7-9): Returns immediately if file doesn't exist902. **Field extraction** (lines 11-17): Parses each frontmatter field913. **Enabled check** (lines 19-21): Respects enabled flag924. **Action based on settings** (lines 23-29): Uses coordinator_session to send notification9394### Creation9596**File:** `commands/launch-swarm.md`9798Settings files are created during swarm launch with:99100```bash101cat > "$WORKTREE_PATH/.claude/multi-agent-swarm.local.md" <<EOF102---103agent_name: $AGENT_NAME104task_number: $TASK_ID105pr_number: TBD106coordinator_session: $COORDINATOR_SESSION107enabled: true108dependencies: [$DEPENDENCIES]109additional_instructions: "$EXTRA_INSTRUCTIONS"110---111112# Task: $TASK_DESCRIPTION113114$TASK_DETAILS115EOF116```117118### Updates119120PR number updated after PR creation:121122```bash123# Update pr_number field124sed "s/^pr_number: .*/pr_number: $PR_NUM/" \125".claude/multi-agent-swarm.local.md" > temp.md126mv temp.md ".claude/multi-agent-swarm.local.md"127```128129## ralph-wiggum Plugin130131### Settings File Structure132133**.claude/ralph-loop.local.md:**134135```markdown136---137iteration: 1138max_iterations: 10139completion_promise: "All tests passing and build successful"140started_at: "2025-01-15T14:30:00Z"141---142143Fix all the linting errors in the project.144Make sure tests pass after each fix.145Document any changes needed in CLAUDE.md.146```147148### How It's Used149150**File:** `hooks/stop-hook.sh`151152**Purpose:** Prevent session exit and loop Claude's output back as input153154**Implementation:**155156```bash157#!/bin/bash158set -euo pipefail159160RALPH_STATE_FILE=".claude/ralph-loop.local.md"161162# Quick exit if no active loop163if [[ ! -f "$RALPH_STATE_FILE" ]]; then164exit 0165fi166167# Parse frontmatter168FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$RALPH_STATE_FILE")169170# Extract configuration171ITERATION=$(echo "$FRONTMATTER" | grep '^iteration:' | sed 's/iteration: *//')172MAX_ITERATIONS=$(echo "$FRONTMATTER" | grep '^max_iterations:' | sed 's/max_iterations: *//')173COMPLETION_PROMISE=$(echo "$FRONTMATTER" | grep '^completion_promise:' | sed 's/completion_promise: *//' | sed 's/^"\(.*\)"$/\1/')174175# Check max iterations176if [[ $MAX_ITERATIONS -gt 0 ]] && [[ $ITERATION -ge $MAX_ITERATIONS ]]; then177echo "๐ Ralph loop: Max iterations ($MAX_ITERATIONS) reached."178rm "$RALPH_STATE_FILE"179exit 0180fi181182# Get transcript and check for completion promise183TRANSCRIPT_PATH=$(echo "$HOOK_INPUT" | jq -r '.transcript_path')184LAST_OUTPUT=$(grep '"role":"assistant"' "$TRANSCRIPT_PATH" | tail -1 | jq -r '.message.content | map(select(.type == "text")) | map(.text) | join("\n")')185186# Check for completion187if [[ "$COMPLETION_PROMISE" != "null" ]] && [[ -n "$COMPLETION_PROMISE" ]]; then188PROMISE_TEXT=$(echo "$LAST_OUTPUT" | perl -0777 -pe 's/.*?<promise>(.*?)<\/promise>.*/$1/s; s/^\s+|\s+$//g')189190if [[ "$PROMISE_TEXT" = "$COMPLETION_PROMISE" ]]; then191echo "โ Ralph loop: Detected completion"192rm "$RALPH_STATE_FILE"193exit 0194fi195fi196197# Continue loop - increment iteration198NEXT_ITERATION=$((ITERATION + 1))199200# Extract prompt from markdown body201PROMPT_TEXT=$(awk '/^---$/{i++; next} i>=2' "$RALPH_STATE_FILE")202203# Update iteration counter204TEMP_FILE="${RALPH_STATE_FILE}.tmp.$$"205sed "s/^iteration: .*/iteration: $NEXT_ITERATION/" "$RALPH_STATE_FILE" > "$TEMP_FILE"206mv "$TEMP_FILE" "$RALPH_STATE_FILE"207208# Block exit and feed prompt back209jq -n \210--arg prompt "$PROMPT_TEXT" \211--arg msg "๐ Ralph iteration $NEXT_ITERATION" \212'{213"decision": "block",214"reason": $prompt,215"systemMessage": $msg216}'217218exit 0219```220221**Key patterns:**2221. **Quick exit** (line 7-9): Skip if not active2232. **Iteration tracking** (lines 11-20): Count and enforce max iterations2243. **Promise detection** (lines 25-33): Check for completion signal in output2254. **Prompt extraction** (line 38): Read markdown body as next prompt2265. **State update** (lines 40-43): Increment iteration atomically2276. **Loop continuation** (lines 45-53): Block exit and feed prompt back228229### Creation230231**File:** `scripts/setup-ralph-loop.sh`232233```bash234#!/bin/bash235PROMPT="$1"236MAX_ITERATIONS="${2:-0}"237COMPLETION_PROMISE="${3:-}"238239# Create state file240cat > ".claude/ralph-loop.local.md" <<EOF241---242iteration: 1243max_iterations: $MAX_ITERATIONS244completion_promise: "$COMPLETION_PROMISE"245started_at: "$(date -Iseconds)"246---247248$PROMPT249EOF250251echo "Ralph loop initialized: .claude/ralph-loop.local.md"252```253254## Pattern Comparison255256| Feature | multi-agent-swarm | ralph-wiggum |257|---------|-------------------|--------------|258| **File** | `.claude/multi-agent-swarm.local.md` | `.claude/ralph-loop.local.md` |259| **Purpose** | Agent coordination state | Loop iteration state |260| **Frontmatter** | Agent metadata | Loop configuration |261| **Body** | Task assignment | Prompt to loop |262| **Updates** | PR number, status | Iteration counter |263| **Deletion** | Manual or on completion | On loop exit |264| **Hook** | Stop (notifications) | Stop (loop control) |265266## Best Practices from Real Plugins267268### 1. Quick Exit Pattern269270Both plugins check file existence first:271272```bash273if [[ ! -f "$STATE_FILE" ]]; then274exit 0 # Not active275fi276```277278**Why:** Avoids errors when plugin isn't configured and performs fast.279280### 2. Enabled Flag281282Both use an `enabled` field for explicit control:283284```yaml285enabled: true286```287288**Why:** Allows temporary deactivation without deleting file.289290### 3. Atomic Updates291292Both use temp file + atomic move:293294```bash295TEMP_FILE="${FILE}.tmp.$$"296sed "s/^field: .*/field: $NEW_VALUE/" "$FILE" > "$TEMP_FILE"297mv "$TEMP_FILE" "$FILE"298```299300**Why:** Prevents corruption if process is interrupted.301302### 4. Quote Handling303304Both strip surrounding quotes from YAML values:305306```bash307sed 's/^"\(.*\)"$/\1/'308```309310**Why:** YAML allows both `field: value` and `field: "value"`.311312### 5. Error Handling313314Both handle missing/corrupt files gracefully:315316```bash317if [[ ! -f "$FILE" ]]; then318exit 0 # No error, just not configured319fi320321if [[ -z "$CRITICAL_FIELD" ]]; then322echo "Settings file corrupt" >&2323rm "$FILE" # Clean up324exit 0325fi326```327328**Why:** Fails gracefully instead of crashing.329330## Anti-Patterns to Avoid331332### โ Hardcoded Paths333334```bash335# BAD336FILE="/Users/alice/.claude/my-plugin.local.md"337338# GOOD339FILE=".claude/my-plugin.local.md"340```341342### โ Unquoted Variables343344```bash345# BAD346echo $VALUE347348# GOOD349echo "$VALUE"350```351352### โ Non-Atomic Updates353354```bash355# BAD: Can corrupt file if interrupted356sed -i "s/field: .*/field: $VALUE/" "$FILE"357358# GOOD: Atomic359TEMP_FILE="${FILE}.tmp.$$"360sed "s/field: .*/field: $VALUE/" "$FILE" > "$TEMP_FILE"361mv "$TEMP_FILE" "$FILE"362```363364### โ No Default Values365366```bash367# BAD: Fails if field missing368if [[ $MAX -gt 100 ]]; then369# MAX might be empty!370fi371372# GOOD: Provide default373MAX=${MAX:-10}374```375376### โ Ignoring Edge Cases377378```bash379# BAD: Assumes exactly 2 --- markers380sed -n '/^---$/,/^---$/{ /^---$/d; p; }'381382# GOOD: Handles --- in body383awk '/^---$/{i++; next} i>=2' # For body384```385386## Conclusion387388The `.claude/plugin-name.local.md` pattern provides:389- Simple, human-readable configuration390- Version-control friendly (gitignored)391- Per-project settings392- Easy parsing with standard bash tools393- Supports both structured config (YAML) and freeform content (markdown)394395Use this pattern for any plugin that needs user-configurable behavior or state persistence.396