Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for developing lifecycle hooks for Claude Code plugins from the official Anthropic repository.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/validate-write.sh
1#!/bin/bash2# Example PreToolUse hook for validating Write/Edit operations3# This script demonstrates file write validation patterns45set -euo pipefail67# Read input from stdin8input=$(cat)910# Extract file path and content11file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')1213# Validate path exists14if [ -z "$file_path" ]; then15echo '{"continue": true}' # No path to validate16exit 017fi1819# Check for path traversal20if [[ "$file_path" == *".."* ]]; then21echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Path traversal detected in: '"$file_path"'"}' >&222exit 223fi2425# Check for system directories26if [[ "$file_path" == /etc/* ]] || [[ "$file_path" == /sys/* ]] || [[ "$file_path" == /usr/* ]]; then27echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Cannot write to system directory: '"$file_path"'"}' >&228exit 229fi3031# Check for sensitive files32if [[ "$file_path" == *.env ]] || [[ "$file_path" == *secret* ]] || [[ "$file_path" == *credentials* ]]; then33echo '{"hookSpecificOutput": {"permissionDecision": "ask"}, "systemMessage": "Writing to potentially sensitive file: '"$file_path"'"}' >&234exit 235fi3637# Approve the operation38exit 039