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.
examples/read-settings-hook.sh
1#!/bin/bash2# Example hook that reads plugin settings from .claude/my-plugin.local.md3# Demonstrates the complete pattern for settings-driven hook behavior45set -euo pipefail67# Define settings file path8SETTINGS_FILE=".claude/my-plugin.local.md"910# Quick exit if settings file doesn't exist11if [[ ! -f "$SETTINGS_FILE" ]]; then12# Plugin not configured - use defaults or skip13exit 014fi1516# Parse YAML frontmatter (everything between --- markers)17FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$SETTINGS_FILE")1819# Extract configuration fields20ENABLED=$(echo "$FRONTMATTER" | grep '^enabled:' | sed 's/enabled: *//' | sed 's/^"\(.*\)"$/\1/')21STRICT_MODE=$(echo "$FRONTMATTER" | grep '^strict_mode:' | sed 's/strict_mode: *//' | sed 's/^"\(.*\)"$/\1/')22MAX_SIZE=$(echo "$FRONTMATTER" | grep '^max_file_size:' | sed 's/max_file_size: *//')2324# Quick exit if disabled25if [[ "$ENABLED" != "true" ]]; then26exit 027fi2829# Read hook input30input=$(cat)31file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')3233# Apply configured validation34if [[ "$STRICT_MODE" == "true" ]]; then35# Strict mode: apply all checks36if [[ "$file_path" == *".."* ]]; then37echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Path traversal blocked (strict mode)"}' >&238exit 239fi4041if [[ "$file_path" == *".env"* ]] || [[ "$file_path" == *"secret"* ]]; then42echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Sensitive file blocked (strict mode)"}' >&243exit 244fi45else46# Standard mode: basic checks only47if [[ "$file_path" == "/etc/"* ]] || [[ "$file_path" == "/sys/"* ]]; then48echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "System path blocked"}' >&249exit 250fi51fi5253# Check file size if configured54if [[ -n "$MAX_SIZE" ]] && [[ "$MAX_SIZE" =~ ^[0-9]+$ ]]; then55content=$(echo "$input" | jq -r '.tool_input.content // empty')56content_size=${#content}5758if [[ $content_size -gt $MAX_SIZE ]]; then59echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "File exceeds configured max size: '"$MAX_SIZE"' bytes"}' >&260exit 261fi62fi6364# All checks passed65exit 066