Skip to content

Commit 73b9a63

Browse files
sjnimsclaude
andauthored
docs: minor script and documentation improvements from security review (#166)
## Summary Batch of four low-priority improvements identified during a comprehensive security review. These are minor quality enhancements that improve usability and defensive coding practices. ## Problem Fixes #163 1. **chmod reminder missing** - Users copying example scripts encounter permission errors 2. **Hardcoded plugin name** - Example doesn't teach portable pattern 3. **Missing jq timeout** - Inconsistent with defensive patterns elsewhere in script 4. **Undocumented file stability assumption** - Settings parsing assumes stable files ## Solution ### Item 1: chmod reminder (SKILL.md) Added note in "Example Hook Scripts" section: > **Note:** After copying example scripts, make them executable: `chmod +x script.sh` ### Item 2: Parameterized plugin name (read-settings-hook.sh) Changed from: ```bash SETTINGS_FILE=".claude/my-plugin.local.md" ``` To: ```bash PLUGIN_NAME="${PLUGIN_NAME:-my-plugin}" SETTINGS_FILE=".claude/${PLUGIN_NAME}.local.md" ``` ### Item 3: jq timeout (test-hook.sh) Changed from: ```bash if ! jq empty "$TEST_INPUT" 2>/dev/null; then ``` To: ```bash if ! timeout 5 jq empty "$TEST_INPUT" 2>/dev/null; then ``` ### Item 4: Race condition documentation (parse-frontmatter.sh) Added comment explaining file stability assumption and that changes require restart. ### Alternatives Considered None - all changes follow the suggestions in the issue exactly. ## Changes | File | Change | |------|--------| | `hook-development/SKILL.md` | Added chmod reminder note | | `plugin-settings/examples/read-settings-hook.sh` | Parameterized plugin name | | `hook-development/scripts/test-hook.sh` | Added timeout to jq validation | | `plugin-settings/scripts/parse-frontmatter.sh` | Documented file stability assumption | ## Testing - [x] shellcheck passes on all modified scripts (pre-existing info-level warnings unrelated to changes) - [x] markdownlint passes on modified markdown - [x] Changes are backwards compatible (parameterized name defaults to original) --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent ecfecb6 commit 73b9a63

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

plugins/plugin-dev/skills/hook-development/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ For detailed patterns and advanced techniques, consult:
689689

690690
Working examples in `examples/`:
691691

692+
> **Note:** After copying example scripts, make them executable: `chmod +x script.sh`
693+
692694
- **`validate-write.sh`** - File write validation example
693695
- **`validate-bash.sh`** - Bash command validation example
694696
- **`load-context.sh`** - SessionStart context loading example

plugins/plugin-dev/skills/hook-development/scripts/test-hook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ if [[ "$TEST_INPUT" =~ [\;\|\&\`\$\(\)\{\}\<\>] ]]; then
169169
exit 1
170170
fi
171171

172-
# Validate test input JSON
173-
if ! jq empty "$TEST_INPUT" 2>/dev/null; then
172+
# Validate test input JSON (with timeout for defensive consistency)
173+
if ! timeout 5 jq empty "$TEST_INPUT" 2>/dev/null; then
174174
echo "❌ Error: Test input is not valid JSON"
175175
exit 1
176176
fi

plugins/plugin-dev/skills/plugin-settings/examples/read-settings-hook.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
2-
# Example hook that reads plugin settings from .claude/my-plugin.local.md
2+
# Example hook that reads plugin settings from .claude/<plugin>.local.md
33
# Demonstrates the complete pattern for settings-driven hook behavior
44

55
set -euo pipefail
66

7-
# Define settings file path
8-
SETTINGS_FILE=".claude/my-plugin.local.md"
7+
# Define settings file path using environment variable with default
8+
# This allows the plugin name to be configured externally if needed
9+
PLUGIN_NAME="${PLUGIN_NAME:-my-plugin}"
10+
SETTINGS_FILE=".claude/${PLUGIN_NAME}.local.md"
911

1012
# Quick exit if settings file doesn't exist
1113
if [[ ! -f "$SETTINGS_FILE" ]]; then

plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
# Frontmatter Parser Utility
33
# Extracts YAML frontmatter from .local.md files
4+
#
5+
# Note: This script assumes the settings file is stable (not being written to).
6+
# Settings changes require a Claude Code restart to take effect, so there's no
7+
# need for file locking in normal usage.
48

59
set -euo pipefail
610

0 commit comments

Comments
 (0)