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-bash.sh
1#!/bin/bash2# Example PreToolUse hook for validating Bash commands3# This script demonstrates bash command validation patterns45set -euo pipefail67# Read input from stdin8input=$(cat)910# Extract command11command=$(echo "$input" | jq -r '.tool_input.command // empty')1213# Validate command exists14if [ -z "$command" ]; then15echo '{"continue": true}' # No command to validate16exit 017fi1819# Check for obviously safe commands (quick approval)20if [[ "$command" =~ ^(ls|pwd|echo|date|whoami)(\s|$) ]]; then21exit 022fi2324# Check for destructive operations25if [[ "$command" == *"rm -rf"* ]] || [[ "$command" == *"rm -fr"* ]]; then26echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Dangerous command detected: rm -rf"}' >&227exit 228fi2930# Check for other dangerous commands31if [[ "$command" == *"dd if="* ]] || [[ "$command" == *"mkfs"* ]] || [[ "$command" == *"> /dev/"* ]]; then32echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Dangerous system operation detected"}' >&233exit 234fi3536# Check for privilege escalation37if [[ "$command" == sudo* ]] || [[ "$command" == su* ]]; then38echo '{"hookSpecificOutput": {"permissionDecision": "ask"}, "systemMessage": "Command requires elevated privileges"}' >&239exit 240fi4142# Approve the operation43exit 044