surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | #!/bin/bash |
| 2 | # Settings File Validator |
| 3 | # Validates .claude/plugin-name.local.md structure |
| 4 | |
| 5 | set -euo pipefail |
| 6 | |
| 7 | # Usage |
| 8 | if [ $# -eq 0 ]; then |
| 9 | echo "Usage: $0 <path/to/settings.local.md>" |
| 10 | echo "" |
| 11 | echo "Validates plugin settings file for:" |
| 12 | echo " - File existence and readability" |
| 13 | echo " - YAML frontmatter structure" |
| 14 | echo " - Required --- markers" |
| 15 | echo " - Field format" |
| 16 | echo "" |
| 17 | echo "Example: $0 .claude/my-plugin.local.md" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | SETTINGS_FILE="$1" |
| 22 | |
| 23 | echo "🔍 Validating settings file: $SETTINGS_FILE" |
| 24 | echo "" |
| 25 | |
| 26 | # Check 1: File exists |
| 27 | if [ ! -f "$SETTINGS_FILE" ]; then |
| 28 | echo "❌ File not found: $SETTINGS_FILE" |
| 29 | exit 1 |
| 30 | fi |
| 31 | echo "✅ File exists" |
| 32 | |
| 33 | # Check 2: File is readable |
| 34 | if [ ! -r "$SETTINGS_FILE" ]; then |
| 35 | echo "❌ File is not readable" |
| 36 | exit 1 |
| 37 | fi |
| 38 | echo "✅ File is readable" |
| 39 | |
| 40 | # Check 3: Has frontmatter markers |
| 41 | MARKER_COUNT=$(grep -c '^---$' "$SETTINGS_FILE" 2>/dev/null || echo "0") |
| 42 | |
| 43 | if [ "$MARKER_COUNT" -lt 2 ]; then |
| 44 | echo "❌ Invalid frontmatter: found $MARKER_COUNT '---' markers (need at least 2)" |
| 45 | echo " Expected format:" |
| 46 | echo " ---" |
| 47 | echo " field: value" |
| 48 | echo " ---" |
| 49 | echo " Content..." |
| 50 | exit 1 |
| 51 | fi |
| 52 | echo "✅ Frontmatter markers present" |
| 53 | |
| 54 | # Check 4: Extract and validate frontmatter |
| 55 | FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$SETTINGS_FILE") |
| 56 | |
| 57 | if [ -z "$FRONTMATTER" ]; then |
| 58 | echo "❌ Empty frontmatter (nothing between --- markers)" |
| 59 | exit 1 |
| 60 | fi |
| 61 | echo "✅ Frontmatter not empty" |
| 62 | |
| 63 | # Check 5: Frontmatter has valid YAML-like structure |
| 64 | if ! echo "$FRONTMATTER" | grep -q ':'; then |
| 65 | echo "⚠️ Warning: Frontmatter has no key:value pairs" |
| 66 | fi |
| 67 | |
| 68 | # Check 6: Look for common fields |
| 69 | echo "" |
| 70 | echo "Detected fields:" |
| 71 | echo "$FRONTMATTER" | grep '^[a-z_][a-z0-9_]*:' | while IFS=':' read -r key value; do |
| 72 | echo " - $key: ${value:0:50}" |
| 73 | done |
| 74 | |
| 75 | # Check 7: Validate common boolean fields |
| 76 | for field in enabled strict_mode; do |
| 77 | VALUE=$(echo "$FRONTMATTER" | grep "^${field}:" | sed "s/${field}: *//" || true) |
| 78 | if [ -n "$VALUE" ]; then |
| 79 | if [ "$VALUE" != "true" ] && [ "$VALUE" != "false" ]; then |
| 80 | echo "⚠️ Field '$field' should be boolean (true/false), got: $VALUE" |
| 81 | fi |
| 82 | fi |
| 83 | done |
| 84 | |
| 85 | # Check 8: Check body exists |
| 86 | BODY=$(awk '/^---$/{i++; next} i>=2' "$SETTINGS_FILE") |
| 87 | |
| 88 | echo "" |
| 89 | if [ -n "$BODY" ]; then |
| 90 | BODY_LINES=$(echo "$BODY" | wc -l | tr -d ' ') |
| 91 | echo "✅ Markdown body present ($BODY_LINES lines)" |
| 92 | else |
| 93 | echo "⚠️ No markdown body (frontmatter only)" |
| 94 | fi |
| 95 | |
| 96 | echo "" |
| 97 | echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 98 | echo "✅ Settings file structure is valid" |
| 99 | echo "" |
| 100 | echo "Reminder: Changes to this file require restarting Claude Code" |
| 101 | exit 0 |