Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/init-firewall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail # Exit on error, undefined vars, and pipeline failures
IFS=$'\n\t' # Stricter word splitting

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Agent File Validator
# Validates agent markdown files for correct structure and content

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test -f .claude/commands/my-command.md && echo "Found" || echo "Missing"
**Automated validation script:**

```bash
#!/bin/bash
#!/usr/bin/env bash
# validate-command.sh

COMMAND_FILE="$1"
Expand Down Expand Up @@ -80,7 +80,7 @@ echo "✓ Command file structure valid"
**Validation script:**

```bash
#!/bin/bash
#!/usr/bin/env bash
# validate-frontmatter.sh

COMMAND_FILE="$1"
Expand Down Expand Up @@ -175,7 +175,7 @@ tail -f ~/.claude/debug-logs/latest
**Test script:**

```bash
#!/bin/bash
#!/usr/bin/env bash
# test-command-arguments.sh

COMMAND="$1"
Expand Down Expand Up @@ -345,7 +345,7 @@ EOF
Create a test suite script:

```bash
#!/bin/bash
#!/usr/bin/env bash
# test-commands.sh - Command test suite

TEST_DIR=".claude/commands"
Expand Down Expand Up @@ -390,7 +390,7 @@ exit $FAILED_TESTS
Validate commands before committing:

```bash
#!/bin/bash
#!/usr/bin/env bash
# .git/hooks/pre-commit

echo "Validating commands..."
Expand Down Expand Up @@ -501,7 +501,7 @@ jobs:
### Response Time Testing

```bash
#!/bin/bash
#!/usr/bin/env bash
# test-command-performance.sh

COMMAND="$1"
Expand Down
6 changes: 3 additions & 3 deletions plugins/plugin-dev/skills/hook-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ Plugin hooks merge with user's hooks and run in parallel.
Always validate inputs in command hooks:

```bash
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

input=$(cat)
Expand Down Expand Up @@ -529,7 +529,7 @@ Create hooks that activate conditionally by checking for a flag file or configur

**Pattern: Flag file activation**
```bash
#!/bin/bash
#!/usr/bin/env bash
# Only active when flag file exists
FLAG_FILE="$CLAUDE_PROJECT_DIR/.enable-strict-validation"

Expand All @@ -545,7 +545,7 @@ input=$(cat)

**Pattern: Configuration-based activation**
```bash
#!/bin/bash
#!/usr/bin/env bash
# Check configuration for activation
CONFIG_FILE="$CLAUDE_PROJECT_DIR/.claude/plugin-config.json"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Example SessionStart hook for loading project context
# This script detects project type and sets environment variables

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Example PreToolUse hook for validating Bash commands
# This script demonstrates bash command validation patterns

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Example PreToolUse hook for validating Write/Edit operations
# This script demonstrates file write validation patterns

Expand Down
36 changes: 18 additions & 18 deletions plugins/plugin-dev/skills/hook-development/references/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Combine command and prompt hooks for layered validation:

**Example quick-check.sh:**
```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command')

Expand All @@ -52,7 +52,7 @@ The command hook quickly approves obviously safe commands, while the prompt hook
Execute hooks based on environment or context:

```bash
#!/bin/bash
#!/usr/bin/env bash
# Only run in CI environment
if [ -z "$CI" ]; then
echo '{"continue": true}' # Skip in non-CI
Expand All @@ -71,7 +71,7 @@ input=$(cat)

**Example: Skip certain checks for trusted users:**
```bash
#!/bin/bash
#!/usr/bin/env bash
# Skip detailed checks for admin users
if [ "$USER" = "admin" ]; then
exit 0
Expand All @@ -88,7 +88,7 @@ Share state between hooks using temporary files:

```bash
# Hook 1: Analyze and save state
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command')

Expand All @@ -101,7 +101,7 @@ exit 0

```bash
# Hook 2: Use saved state
#!/bin/bash
#!/usr/bin/env bash
risk_level=$(cat /tmp/hook-state-$$ 2>/dev/null || echo "unknown")

if [ "$risk_level" = "high" ]; then
Expand All @@ -117,7 +117,7 @@ fi
Modify hook behavior based on project configuration:

```bash
#!/bin/bash
#!/usr/bin/env bash
cd "$CLAUDE_PROJECT_DIR" || exit 1

# Read project-specific config
Expand Down Expand Up @@ -170,7 +170,7 @@ The LLM can read the transcript file and make context-aware decisions.
### Caching Validation Results

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path')
cache_key=$(echo -n "$file_path" | md5sum | cut -d' ' -f1)
Expand Down Expand Up @@ -232,15 +232,15 @@ Coordinate hooks across different events:

**SessionStart - Set up tracking:**
```bash
#!/bin/bash
#!/usr/bin/env bash
# Initialize session tracking
echo "0" > /tmp/test-count-$$
echo "0" > /tmp/build-count-$$
```

**PostToolUse - Track events:**
```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')

Expand All @@ -255,7 +255,7 @@ fi

**Stop - Verify based on tracking:**
```bash
#!/bin/bash
#!/usr/bin/env bash
test_count=$(cat /tmp/test-count-$$ 2>/dev/null || echo "0")

if [ "$test_count" -eq 0 ]; then
Expand All @@ -269,7 +269,7 @@ fi
### Slack Notifications

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')
decision="blocked"
Expand All @@ -287,7 +287,7 @@ exit 2
### Database Logging

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)

# Log to database
Expand All @@ -300,7 +300,7 @@ exit 0
### Metrics Collection

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')

Expand All @@ -315,7 +315,7 @@ exit 0
### Rate Limiting

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command')

Expand Down Expand Up @@ -349,7 +349,7 @@ exit 0
### Audit Logging

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')
timestamp=$(date -Iseconds)
Expand All @@ -363,7 +363,7 @@ exit 0
### Secret Detection

```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
content=$(echo "$input" | jq -r '.tool_input.content')

Expand All @@ -382,7 +382,7 @@ exit 0

```bash
# test-hook.sh
#!/bin/bash
#!/usr/bin/env bash

# Test 1: Approve safe command
result=$(echo '{"tool_input": {"command": "ls"}}' | bash validate-bash.sh)
Expand All @@ -407,7 +407,7 @@ Create test scenarios that exercise the full hook workflow:

```bash
# integration-test.sh
#!/bin/bash
#!/usr/bin/env bash

# Set up test environment
export CLAUDE_PROJECT_DIR="/tmp/test-project"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Prompt-based hooks offer several advantages:

**Script (validate-bash.sh):**
```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command')

Expand Down Expand Up @@ -103,7 +103,7 @@ fi

**Script (validate-write.sh):**
```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path')

Expand Down Expand Up @@ -159,7 +159,7 @@ Command hooks still have their place:
### 1. Deterministic Performance Checks

```bash
#!/bin/bash
#!/usr/bin/env bash
# Check file size quickly
file_path=$(echo "$input" | jq -r '.tool_input.file_path')
size=$(stat -f%z "$file_path" 2>/dev/null || stat -c%s "$file_path" 2>/dev/null)
Expand All @@ -175,7 +175,7 @@ fi
### 2. External Tool Integration

```bash
#!/bin/bash
#!/usr/bin/env bash
# Run security scanner
file_path=$(echo "$input" | jq -r '.tool_input.file_path')
scan_result=$(security-scanner "$file_path")
Expand All @@ -191,7 +191,7 @@ fi
### 3. Very Fast Checks (< 50ms)

```bash
#!/bin/bash
#!/usr/bin/env bash
# Quick regex check
command=$(echo "$input" | jq -r '.tool_input.command')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Load project-specific context at session start:

**Example script (load-context.sh):**
```bash
#!/bin/bash
#!/usr/bin/env bash
cd "$CLAUDE_PROJECT_DIR" || exit 1

# Detect project type
Expand Down Expand Up @@ -193,7 +193,7 @@ Run linters or formatters on file edits:

**Example script (check-quality.sh):**
```bash
#!/bin/bash
#!/usr/bin/env bash
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path')

Expand Down Expand Up @@ -263,7 +263,7 @@ This provides multi-layered protection and automation.
Create hooks that only run when explicitly enabled via flag files:

```bash
#!/bin/bash
#!/usr/bin/env bash
# Hook only active when flag file exists
FLAG_FILE="$CLAUDE_PROJECT_DIR/.enable-security-scan"

Expand Down Expand Up @@ -302,7 +302,7 @@ rm .enable-security-scan
Use JSON configuration to control hook behavior:

```bash
#!/bin/bash
#!/usr/bin/env bash
CONFIG_FILE="$CLAUDE_PROJECT_DIR/.claude/my-plugin.local.json"

# Read configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Checks hook scripts for common issues and best practices violations.
### Hook doesn't execute

Check:
- Script has shebang (`#!/bin/bash`)
- Script has shebang (`#!/usr/bin/env bash`)
- Script is executable (`chmod +x`)
- Path in hooks.json is correct (use `${CLAUDE_PLUGIN_ROOT}`)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Hook Linter
# Checks hook scripts for common issues and best practices

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Hook Testing Helper
# Tests a hook with sample input and shows output

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Hook Schema Validator
# Validates hooks.json structure and checks for common issues

Expand Down
Loading