[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6DT298FP0FD02RCDYGHG66S":3,"skill-same:01M6DT298FP0FD02RCDYGHG66S":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":25,"linkOnly":26,"markdownContent":27,"markdownBody":28,"frontMatter":29,"refName":32,"commitSha":33,"skillDirectory":34,"forksCount":35,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":38,"install":39,"resources":52},"01M6DT298FP0FD02RCDYGHG66S","enhance-hooks",null,"Use when reviewing hooks for safety, timeouts, and correct frontmatter.","AntifragileTech\u002Fantifragile-claude-code","AntifragileTech","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F174357194?v=4","01M6DQCYMK4CDSQQAN0ZC72NTV","01M6DQCYS9YPW1WKMQ5TJMPQ43",9,"MIT","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fenhance-hooks\u002FSKILL.md",[],[18,19,20,21,22,23,24],"hooks","enhance","enhance hooks","Safety","correct","fix","use","2026-11-10 10:12:30",false,"---\nname: enhance-hooks\ndescription: \"Use when reviewing hooks for safety, timeouts, and correct frontmatter.\"\nversion: 5.1.0\nargument-hint: \"[path] [--fix]\"\n---\n\n# enhance-hooks\n\nAnalyze hook definitions and scripts for safety, correctness, and best practices.\n\n## Parse Arguments\n\n```javascript\nconst args = '$ARGUMENTS'.split(' ').filter(Boolean);\nconst targetPath = args.find(a => !a.startsWith('--')) || '.';\nconst fix = args.includes('--fix');\n```\n\n## Workflow\n\n1. **Discover** - Find hook files (.md, .sh, .json)\n2. **Classify** - Identify hook type and event\n3. **Parse** - Extract frontmatter and script content\n4. **Check** - Run all pattern checks against knowledge below\n5. **Filter** - Apply certainty filtering\n6. **Report** - Generate markdown output\n7. **Fix** - Apply auto-fixes if --fix flag present\n\n---\n\n## Hook Knowledge Reference\n\n### What Are Hooks\n\nHooks are automated actions triggered at specific points in a Claude Code session. They enable validation, monitoring, and control of Claude's actions through bash commands or LLM-based evaluation.\n\n### Hook Lifecycle (Complete Reference)\n\nHooks fire in this sequence:\n\n| Order | Event | Description | Matcher Required |\n|-------|-------|-------------|------------------|\n| 1 | `SessionStart` | Session begins or resumes | No |\n| 2 | `UserPromptSubmit` | User submits a prompt | No |\n| 3 | `PreToolUse` | Before tool execution (can modify\u002Fblock) | Yes |\n| 4 | `PermissionRequest` | When permission dialog appears | Yes |\n| 5 | `PostToolUse` | After tool succeeds | Yes |\n| 6 | `SubagentStart` | When spawning a subagent | No |\n| 7 | `SubagentStop` | When subagent finishes | No |\n| 8 | `Stop` | Claude finishes responding | No |\n| 9 | `PreCompact` | Before context compaction | No |\n| 10 | `SessionEnd` | Session terminates | No |\n| 11 | `Notification` | Claude Code sends notifications | No |\n\n### Hook Types\n\n**Command Hooks** (`type: \"command\"`):\n- Execute bash commands with full stdin\u002Fstdout control\n- Available for all events\n\n**Prompt Hooks** (`type: \"prompt\"`):\n- Use LLM evaluation for intelligent, context-aware decisions\n- **Only supported for `Stop` and `SubagentStop` events**\n\n### Configuration Locations\n\n| File | Location | Scope | Committed |\n|------|----------|-------|-----------|\n| User settings | `~\u002F.claude\u002Fsettings.json` | All projects | No |\n| Project settings | `.claude\u002Fsettings.json` | Current project | Yes |\n| Local settings | `.claude\u002Fsettings.local.json` | Current project | No |\n\n### Configuration Structure\n\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"matcher\": \"Bash\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \".claude\u002Fhooks\u002Fvalidate-bash.sh\",\n            \"timeout\": 30\n          }\n        ]\n      }\n    ],\n    \"PostToolUse\": [\n      {\n        \"matcher\": \"Write|Edit\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"$CLAUDE_PROJECT_DIR\u002F.claude\u002Fhooks\u002Fformat-code.sh\"\n          }\n        ]\n      }\n    ],\n    \"Stop\": [\n      {\n        \"hooks\": [\n          {\n            \"type\": \"prompt\",\n            \"prompt\": \"Check if all requested tasks are complete.\",\n            \"timeout\": 30\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Matcher Syntax\n\n| Pattern | Description |\n|---------|-------------|\n| `Write` | Match exact tool name |\n| `Edit\\|Write` | Match multiple tools (regex OR) |\n| `Notebook.*` | Regex pattern matching |\n| `*` or `\"\"` | Match all tools |\n| (omitted) | Required for Stop, SubagentStop, UserPromptSubmit |\n\n### Input Schema (JSON via stdin)\n\nAll hooks receive this JSON structure:\n\n```json\n{\n  \"session_id\": \"abc123\",\n  \"transcript_path\": \"\u002Fpath\u002Fto\u002Ftranscript\",\n  \"cwd\": \"\u002Fproject\u002Froot\",\n  \"permission_mode\": \"default\",\n  \"hook_event_name\": \"PreToolUse\",\n  \"tool_name\": \"Bash\",\n  \"tool_input\": {\n    \"command\": \"npm test\",\n    \"description\": \"Run test suite\"\n  }\n}\n```\n\n### Exit Codes\n\n| Exit Code | Behavior |\n|-----------|----------|\n| 0 | Success - stdout shown to user or added as context |\n| 2 | Blocking error - stderr shown, action blocked |\n| Other | Non-blocking error - stderr shown in verbose mode |\n\n### Output Schemas\n\n**PreToolUse Decision Control:**\n```json\n{\n  \"hookSpecificOutput\": {\n    \"hookEventName\": \"PreToolUse\",\n    \"permissionDecision\": \"allow|deny|ask\",\n    \"permissionDecisionReason\": \"Reason for decision\",\n    \"updatedInput\": {\n      \"command\": \"modified command\"\n    },\n    \"additionalContext\": \"Context for Claude\"\n  }\n}\n```\n\n**Stop\u002FSubagentStop Control:**\n```json\n{\n  \"decision\": \"block\",\n  \"reason\": \"Tasks incomplete: missing test coverage\"\n}\n```\n\n### Environment Variables\n\n| Variable | Description | Available In |\n|----------|-------------|--------------|\n| `CLAUDE_PROJECT_DIR` | Absolute path to project root | All hooks |\n| `CLAUDE_CODE_REMOTE` | \"true\" if remote session | All hooks |\n| `CLAUDE_ENV_FILE` | Path to persist env vars | SessionStart only |\n| `CLAUDE_FILE_PATHS` | Space-separated file paths | PostToolUse (Write\u002FEdit) |\n\n### Practical Hook Examples\n\n**Security Firewall (PreToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n\n# Block dangerous patterns\nif echo \"$cmd\" | grep -qE 'rm -rf|git reset --hard|curl.*\\|.*sh'; then\n  echo '{\"decision\": \"block\", \"reason\": \"Dangerous command blocked\"}' >&2\n  exit 2\nfi\n\nexit 0\n```\n\n**Auto-Formatter (PostToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n\nfiles=$(jq -r '.tool_input.file_path \u002F\u002F \"\"')\n\nfor file in $files; do\n  case \"$file\" in\n    *.py) black \"$file\" 2>\u002Fdev\u002Fnull || true ;;\n    *.js|*.ts) prettier --write \"$file\" 2>\u002Fdev\u002Fnull || true ;;\n  esac\ndone\n\nexit 0\n```\n\n**Command Logger (PreToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\nprintf '%s %s\\n' \"$(date -Is)\" \"$cmd\" >> .claude\u002Fbash-commands.log\nexit 0\n```\n\n**Workflow Orchestration (SubagentStop - prompt type):**\n```json\n{\n  \"hooks\": {\n    \"SubagentStop\": [\n      {\n        \"hooks\": [\n          {\n            \"type\": \"prompt\",\n            \"prompt\": \"Review the subagent's work. Did it complete all tasks?\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n---\n\n## Detection Patterns\n\n### 1. Frontmatter Validation (HIGH Certainty)\n\n**Required:**\n- YAML frontmatter with `---` delimiters\n- `name` field in frontmatter\n- `description` field in frontmatter\n\n**Recommended:**\n- `timeout` for command hooks (default: 30s)\n- Hook type specification\n\n**Flag:**\n- Missing frontmatter delimiters\n- Missing name or description\n\n### 2. Script Safety (HIGH Certainty)\n\n**Required Safety Patterns:**\n- `set -euo pipefail` at script start\n- Error handling for jq\u002FJSON parsing\n- Proper quoting of variables\n\n**Dangerous Patterns to Flag:**\n\n| Pattern | Risk | Certainty |\n|---------|------|-----------|\n| `rm -rf` | Destructive without confirmation | HIGH |\n| `git reset --hard` | Data loss risk | HIGH |\n| `curl \\| sh` | Remote code execution | HIGH |\n| `eval \"$input\"` | Arbitrary code execution | HIGH |\n| `rm -r` | Recursive delete (may be intentional) | MEDIUM |\n| `git push --force` | Force push (may be intentional) | MEDIUM |\n\n### 3. Exit Code Handling (HIGH Certainty)\n\n**Check:** Scripts use correct exit codes\n\n**Flag:**\n- Missing `exit 0` for success path\n- Using exit code 1 for blocking (should be 2)\n- No exit code at end of script\n\n### 4. Hook Type Appropriateness (HIGH Certainty)\n\n**Check:** Hook type matches event\n\n**Flag:**\n- Prompt hooks used for events other than Stop\u002FSubagentStop\n- Missing type specification\n\n### 5. Lifecycle Event Appropriateness (MEDIUM Certainty)\n\n| Event | Appropriate Use Cases |\n|-------|----------------------|\n| `PreToolUse` | Security validation, command blocking, input modification |\n| `PostToolUse` | Formatting, logging, notifications |\n| `Stop` | Completion checks, cleanup, summary |\n| `SubagentStop` | Workflow orchestration, result validation |\n| `SessionStart` | Environment setup, initialization |\n\n**Flag:**\n- PostToolUse hooks trying to block actions (too late)\n- PreToolUse hooks doing heavy processing (should be fast)\n- Prompt hooks on unsupported events\n\n### 6. Timeout Configuration (MEDIUM Certainty)\n\n**Guidelines:**\n- Default: 30 seconds for command hooks\n- Network operations: Always set explicit timeout\n- External service calls: Set timeout based on expected latency\n\n**Flag:**\n- No timeout for network operations\n- Timeout missing for external service calls\n- Unreasonably long timeouts (>60s without justification)\n\n### 7. Output Format (MEDIUM Certainty)\n\n**PreToolUse Output Fields:**\n- `permissionDecision`: allow, deny, or ask\n- `permissionDecisionReason`: Explanation for decision\n- `updatedInput`: Modified tool input (optional)\n- `additionalContext`: Context for Claude (optional)\n\n**Flag:**\n- Invalid permissionDecision values\n- Missing reason for deny decisions\n- Malformed JSON output\n\n### 8. Matcher Patterns (MEDIUM Certainty)\n\n**Check:** Matcher syntax is valid\n\n**Flag:**\n- Invalid regex patterns\n- Too broad matchers (`*` without justification)\n- Matcher on events that don't support it (Stop, SubagentStop)\n\n### 9. Anti-Patterns (LOW Certainty)\n\n- Complex logic in hooks (should be simple and fast)\n- Missing documentation\u002Fcomments\n- Hardcoded paths (should use `$CLAUDE_PROJECT_DIR`)\n- Network calls without error handling\n- Secrets\u002Fcredentials in hook scripts\n\n---\n\n## Auto-Fix Implementations\n\n### 1. Missing safety header\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n```\n\n### 2. Missing exit code\nAdd `exit 0` at end of script\n\n### 3. Missing frontmatter fields\n```yaml\n---\nname: hook-name\ndescription: Hook description\ntimeout: 30\n---\n```\n\n### 4. Wrong blocking exit code\nReplace `exit 1` with `exit 2` for blocking errors\n\n---\n\n## Output Format\n\n```markdown\n## Hook Analysis: {hook-name}\n\n**File**: {path}\n**Type**: {command|prompt|config}\n**Event**: {PreToolUse|PostToolUse|Stop|...}\n\n### Summary\n- HIGH: {count} issues\n- MEDIUM: {count} issues\n\n### Frontmatter Issues ({n})\n| Issue | Fix | Certainty |\n\n### Safety Issues ({n})\n| Issue | Fix | Certainty |\n\n### Exit Code Issues ({n})\n| Issue | Fix | Certainty |\n\n### Lifecycle Issues ({n})\n| Issue | Fix | Certainty |\n\n### Output Format Issues ({n})\n| Issue | Fix | Certainty |\n```\n\n---\n\n## Pattern Statistics\n\n| Category | Patterns | Auto-Fixable |\n|----------|----------|--------------|\n| Frontmatter | 3 | 2 |\n| Safety | 6 | 2 |\n| Exit Code | 3 | 2 |\n| Hook Type | 2 | 0 |\n| Lifecycle | 5 | 0 |\n| Timeout | 3 | 0 |\n| Output | 3 | 0 |\n| Matcher | 3 | 0 |\n| Anti-Pattern | 5 | 0 |\n| **Total** | **33** | **6** |\n\n---\n\n\u003Cexamples>\n### Example: Missing Safety Header\n\n\u003Cbad_example>\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n```\n**Why it's bad**: Missing `set -euo pipefail` means errors may silently pass.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n```\n**Why it's good**: Fails fast on errors, unset variables, and pipe failures.\n\u003C\u002Fgood_example>\n\n### Example: Wrong Exit Code for Blocking\n\n\u003Cbad_example>\n```bash\nif [[ \"$cmd\" == *\"rm -rf\"* ]]; then\n  echo \"Blocked dangerous command\" >&2\n  exit 1  # Wrong!\nfi\n```\n**Why it's bad**: Exit code 1 is non-blocking. Action will still proceed.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nif [[ \"$cmd\" == *\"rm -rf\"* ]]; then\n  echo '{\"decision\": \"block\", \"reason\": \"Dangerous command\"}' >&2\n  exit 2  # Correct blocking exit code\nfi\n```\n**Why it's good**: Exit code 2 blocks the action. JSON output provides context.\n\u003C\u002Fgood_example>\n\n### Example: Prompt Hook on Wrong Event\n\n\u003Cbad_example>\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"hooks\": [{ \"type\": \"prompt\", \"prompt\": \"Is this safe?\" }]\n      }\n    ]\n  }\n}\n```\n**Why it's bad**: Prompt hooks only work for Stop and SubagentStop events.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"hooks\": [{ \"type\": \"command\", \"command\": \".\u002Fvalidate.sh\" }]\n      }\n    ]\n  }\n}\n```\n**Why it's good**: Command hooks work for all events.\n\u003C\u002Fgood_example>\n\n### Example: Dangerous Command Pattern\n\n\u003Cbad_example>\n```bash\nif echo \"$cmd\" | grep -q 'rm'; then\n  exit 2\nfi\n```\n**Why it's bad**: Too broad - blocks legitimate `rm file.tmp`.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nif echo \"$cmd\" | grep -qE 'rm\\s+(-rf|-fr)\\s+\u002F'; then\n  exit 2\nfi\n```\n**Why it's good**: Specific pattern targets actual dangerous commands.\n\u003C\u002Fgood_example>\n\n### Example: Hardcoded Path\n\n\u003Cbad_example>\n```bash\nlog_file=\"\u002Fhome\u002Fuser\u002Fproject\u002F.claude\u002Fcommands.log\"\n```\n**Why it's bad**: Hardcoded path breaks on other machines.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nlog_file=\"$CLAUDE_PROJECT_DIR\u002F.claude\u002Fcommands.log\"\n```\n**Why it's good**: Uses environment variable for portability.\n\u003C\u002Fgood_example>\n\u003C\u002Fexamples>\n\n---\n\n## Constraints\n\n- Only apply auto-fixes for HIGH certainty issues\n- Be cautious about security patterns - false negatives worse than false positives\n- Never remove content, only suggest improvements\n- Validate against embedded knowledge reference above\n","# enhance-hooks\n\nAnalyze hook definitions and scripts for safety, correctness, and best practices.\n\n## Parse Arguments\n\n```javascript\nconst args = '$ARGUMENTS'.split(' ').filter(Boolean);\nconst targetPath = args.find(a => !a.startsWith('--')) || '.';\nconst fix = args.includes('--fix');\n```\n\n## Workflow\n\n1. **Discover** - Find hook files (.md, .sh, .json)\n2. **Classify** - Identify hook type and event\n3. **Parse** - Extract frontmatter and script content\n4. **Check** - Run all pattern checks against knowledge below\n5. **Filter** - Apply certainty filtering\n6. **Report** - Generate markdown output\n7. **Fix** - Apply auto-fixes if --fix flag present\n\n---\n\n## Hook Knowledge Reference\n\n### What Are Hooks\n\nHooks are automated actions triggered at specific points in a Claude Code session. They enable validation, monitoring, and control of Claude's actions through bash commands or LLM-based evaluation.\n\n### Hook Lifecycle (Complete Reference)\n\nHooks fire in this sequence:\n\n| Order | Event | Description | Matcher Required |\n|-------|-------|-------------|------------------|\n| 1 | `SessionStart` | Session begins or resumes | No |\n| 2 | `UserPromptSubmit` | User submits a prompt | No |\n| 3 | `PreToolUse` | Before tool execution (can modify\u002Fblock) | Yes |\n| 4 | `PermissionRequest` | When permission dialog appears | Yes |\n| 5 | `PostToolUse` | After tool succeeds | Yes |\n| 6 | `SubagentStart` | When spawning a subagent | No |\n| 7 | `SubagentStop` | When subagent finishes | No |\n| 8 | `Stop` | Claude finishes responding | No |\n| 9 | `PreCompact` | Before context compaction | No |\n| 10 | `SessionEnd` | Session terminates | No |\n| 11 | `Notification` | Claude Code sends notifications | No |\n\n### Hook Types\n\n**Command Hooks** (`type: \"command\"`):\n- Execute bash commands with full stdin\u002Fstdout control\n- Available for all events\n\n**Prompt Hooks** (`type: \"prompt\"`):\n- Use LLM evaluation for intelligent, context-aware decisions\n- **Only supported for `Stop` and `SubagentStop` events**\n\n### Configuration Locations\n\n| File | Location | Scope | Committed |\n|------|----------|-------|-----------|\n| User settings | `~\u002F.claude\u002Fsettings.json` | All projects | No |\n| Project settings | `.claude\u002Fsettings.json` | Current project | Yes |\n| Local settings | `.claude\u002Fsettings.local.json` | Current project | No |\n\n### Configuration Structure\n\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"matcher\": \"Bash\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \".claude\u002Fhooks\u002Fvalidate-bash.sh\",\n            \"timeout\": 30\n          }\n        ]\n      }\n    ],\n    \"PostToolUse\": [\n      {\n        \"matcher\": \"Write|Edit\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"$CLAUDE_PROJECT_DIR\u002F.claude\u002Fhooks\u002Fformat-code.sh\"\n          }\n        ]\n      }\n    ],\n    \"Stop\": [\n      {\n        \"hooks\": [\n          {\n            \"type\": \"prompt\",\n            \"prompt\": \"Check if all requested tasks are complete.\",\n            \"timeout\": 30\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Matcher Syntax\n\n| Pattern | Description |\n|---------|-------------|\n| `Write` | Match exact tool name |\n| `Edit\\|Write` | Match multiple tools (regex OR) |\n| `Notebook.*` | Regex pattern matching |\n| `*` or `\"\"` | Match all tools |\n| (omitted) | Required for Stop, SubagentStop, UserPromptSubmit |\n\n### Input Schema (JSON via stdin)\n\nAll hooks receive this JSON structure:\n\n```json\n{\n  \"session_id\": \"abc123\",\n  \"transcript_path\": \"\u002Fpath\u002Fto\u002Ftranscript\",\n  \"cwd\": \"\u002Fproject\u002Froot\",\n  \"permission_mode\": \"default\",\n  \"hook_event_name\": \"PreToolUse\",\n  \"tool_name\": \"Bash\",\n  \"tool_input\": {\n    \"command\": \"npm test\",\n    \"description\": \"Run test suite\"\n  }\n}\n```\n\n### Exit Codes\n\n| Exit Code | Behavior |\n|-----------|----------|\n| 0 | Success - stdout shown to user or added as context |\n| 2 | Blocking error - stderr shown, action blocked |\n| Other | Non-blocking error - stderr shown in verbose mode |\n\n### Output Schemas\n\n**PreToolUse Decision Control:**\n```json\n{\n  \"hookSpecificOutput\": {\n    \"hookEventName\": \"PreToolUse\",\n    \"permissionDecision\": \"allow|deny|ask\",\n    \"permissionDecisionReason\": \"Reason for decision\",\n    \"updatedInput\": {\n      \"command\": \"modified command\"\n    },\n    \"additionalContext\": \"Context for Claude\"\n  }\n}\n```\n\n**Stop\u002FSubagentStop Control:**\n```json\n{\n  \"decision\": \"block\",\n  \"reason\": \"Tasks incomplete: missing test coverage\"\n}\n```\n\n### Environment Variables\n\n| Variable | Description | Available In |\n|----------|-------------|--------------|\n| `CLAUDE_PROJECT_DIR` | Absolute path to project root | All hooks |\n| `CLAUDE_CODE_REMOTE` | \"true\" if remote session | All hooks |\n| `CLAUDE_ENV_FILE` | Path to persist env vars | SessionStart only |\n| `CLAUDE_FILE_PATHS` | Space-separated file paths | PostToolUse (Write\u002FEdit) |\n\n### Practical Hook Examples\n\n**Security Firewall (PreToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n\n# Block dangerous patterns\nif echo \"$cmd\" | grep -qE 'rm -rf|git reset --hard|curl.*\\|.*sh'; then\n  echo '{\"decision\": \"block\", \"reason\": \"Dangerous command blocked\"}' >&2\n  exit 2\nfi\n\nexit 0\n```\n\n**Auto-Formatter (PostToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n\nfiles=$(jq -r '.tool_input.file_path \u002F\u002F \"\"')\n\nfor file in $files; do\n  case \"$file\" in\n    *.py) black \"$file\" 2>\u002Fdev\u002Fnull || true ;;\n    *.js|*.ts) prettier --write \"$file\" 2>\u002Fdev\u002Fnull || true ;;\n  esac\ndone\n\nexit 0\n```\n\n**Command Logger (PreToolUse):**\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\nprintf '%s %s\\n' \"$(date -Is)\" \"$cmd\" >> .claude\u002Fbash-commands.log\nexit 0\n```\n\n**Workflow Orchestration (SubagentStop - prompt type):**\n```json\n{\n  \"hooks\": {\n    \"SubagentStop\": [\n      {\n        \"hooks\": [\n          {\n            \"type\": \"prompt\",\n            \"prompt\": \"Review the subagent's work. Did it complete all tasks?\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n---\n\n## Detection Patterns\n\n### 1. Frontmatter Validation (HIGH Certainty)\n\n**Required:**\n- YAML frontmatter with `---` delimiters\n- `name` field in frontmatter\n- `description` field in frontmatter\n\n**Recommended:**\n- `timeout` for command hooks (default: 30s)\n- Hook type specification\n\n**Flag:**\n- Missing frontmatter delimiters\n- Missing name or description\n\n### 2. Script Safety (HIGH Certainty)\n\n**Required Safety Patterns:**\n- `set -euo pipefail` at script start\n- Error handling for jq\u002FJSON parsing\n- Proper quoting of variables\n\n**Dangerous Patterns to Flag:**\n\n| Pattern | Risk | Certainty |\n|---------|------|-----------|\n| `rm -rf` | Destructive without confirmation | HIGH |\n| `git reset --hard` | Data loss risk | HIGH |\n| `curl \\| sh` | Remote code execution | HIGH |\n| `eval \"$input\"` | Arbitrary code execution | HIGH |\n| `rm -r` | Recursive delete (may be intentional) | MEDIUM |\n| `git push --force` | Force push (may be intentional) | MEDIUM |\n\n### 3. Exit Code Handling (HIGH Certainty)\n\n**Check:** Scripts use correct exit codes\n\n**Flag:**\n- Missing `exit 0` for success path\n- Using exit code 1 for blocking (should be 2)\n- No exit code at end of script\n\n### 4. Hook Type Appropriateness (HIGH Certainty)\n\n**Check:** Hook type matches event\n\n**Flag:**\n- Prompt hooks used for events other than Stop\u002FSubagentStop\n- Missing type specification\n\n### 5. Lifecycle Event Appropriateness (MEDIUM Certainty)\n\n| Event | Appropriate Use Cases |\n|-------|----------------------|\n| `PreToolUse` | Security validation, command blocking, input modification |\n| `PostToolUse` | Formatting, logging, notifications |\n| `Stop` | Completion checks, cleanup, summary |\n| `SubagentStop` | Workflow orchestration, result validation |\n| `SessionStart` | Environment setup, initialization |\n\n**Flag:**\n- PostToolUse hooks trying to block actions (too late)\n- PreToolUse hooks doing heavy processing (should be fast)\n- Prompt hooks on unsupported events\n\n### 6. Timeout Configuration (MEDIUM Certainty)\n\n**Guidelines:**\n- Default: 30 seconds for command hooks\n- Network operations: Always set explicit timeout\n- External service calls: Set timeout based on expected latency\n\n**Flag:**\n- No timeout for network operations\n- Timeout missing for external service calls\n- Unreasonably long timeouts (>60s without justification)\n\n### 7. Output Format (MEDIUM Certainty)\n\n**PreToolUse Output Fields:**\n- `permissionDecision`: allow, deny, or ask\n- `permissionDecisionReason`: Explanation for decision\n- `updatedInput`: Modified tool input (optional)\n- `additionalContext`: Context for Claude (optional)\n\n**Flag:**\n- Invalid permissionDecision values\n- Missing reason for deny decisions\n- Malformed JSON output\n\n### 8. Matcher Patterns (MEDIUM Certainty)\n\n**Check:** Matcher syntax is valid\n\n**Flag:**\n- Invalid regex patterns\n- Too broad matchers (`*` without justification)\n- Matcher on events that don't support it (Stop, SubagentStop)\n\n### 9. Anti-Patterns (LOW Certainty)\n\n- Complex logic in hooks (should be simple and fast)\n- Missing documentation\u002Fcomments\n- Hardcoded paths (should use `$CLAUDE_PROJECT_DIR`)\n- Network calls without error handling\n- Secrets\u002Fcredentials in hook scripts\n\n---\n\n## Auto-Fix Implementations\n\n### 1. Missing safety header\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n```\n\n### 2. Missing exit code\nAdd `exit 0` at end of script\n\n### 3. Missing frontmatter fields\n```yaml\n---\nname: hook-name\ndescription: Hook description\ntimeout: 30\n---\n```\n\n### 4. Wrong blocking exit code\nReplace `exit 1` with `exit 2` for blocking errors\n\n---\n\n## Output Format\n\n```markdown\n## Hook Analysis: {hook-name}\n\n**File**: {path}\n**Type**: {command|prompt|config}\n**Event**: {PreToolUse|PostToolUse|Stop|...}\n\n### Summary\n- HIGH: {count} issues\n- MEDIUM: {count} issues\n\n### Frontmatter Issues ({n})\n| Issue | Fix | Certainty |\n\n### Safety Issues ({n})\n| Issue | Fix | Certainty |\n\n### Exit Code Issues ({n})\n| Issue | Fix | Certainty |\n\n### Lifecycle Issues ({n})\n| Issue | Fix | Certainty |\n\n### Output Format Issues ({n})\n| Issue | Fix | Certainty |\n```\n\n---\n\n## Pattern Statistics\n\n| Category | Patterns | Auto-Fixable |\n|----------|----------|--------------|\n| Frontmatter | 3 | 2 |\n| Safety | 6 | 2 |\n| Exit Code | 3 | 2 |\n| Hook Type | 2 | 0 |\n| Lifecycle | 5 | 0 |\n| Timeout | 3 | 0 |\n| Output | 3 | 0 |\n| Matcher | 3 | 0 |\n| Anti-Pattern | 5 | 0 |\n| **Total** | **33** | **6** |\n\n---\n\n\u003Cexamples>\n### Example: Missing Safety Header\n\n\u003Cbad_example>\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n```\n**Why it's bad**: Missing `set -euo pipefail` means errors may silently pass.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ncmd=$(jq -r '.tool_input.command \u002F\u002F \"\"')\n```\n**Why it's good**: Fails fast on errors, unset variables, and pipe failures.\n\u003C\u002Fgood_example>\n\n### Example: Wrong Exit Code for Blocking\n\n\u003Cbad_example>\n```bash\nif [[ \"$cmd\" == *\"rm -rf\"* ]]; then\n  echo \"Blocked dangerous command\" >&2\n  exit 1  # Wrong!\nfi\n```\n**Why it's bad**: Exit code 1 is non-blocking. Action will still proceed.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nif [[ \"$cmd\" == *\"rm -rf\"* ]]; then\n  echo '{\"decision\": \"block\", \"reason\": \"Dangerous command\"}' >&2\n  exit 2  # Correct blocking exit code\nfi\n```\n**Why it's good**: Exit code 2 blocks the action. JSON output provides context.\n\u003C\u002Fgood_example>\n\n### Example: Prompt Hook on Wrong Event\n\n\u003Cbad_example>\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"hooks\": [{ \"type\": \"prompt\", \"prompt\": \"Is this safe?\" }]\n      }\n    ]\n  }\n}\n```\n**Why it's bad**: Prompt hooks only work for Stop and SubagentStop events.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"hooks\": [{ \"type\": \"command\", \"command\": \".\u002Fvalidate.sh\" }]\n      }\n    ]\n  }\n}\n```\n**Why it's good**: Command hooks work for all events.\n\u003C\u002Fgood_example>\n\n### Example: Dangerous Command Pattern\n\n\u003Cbad_example>\n```bash\nif echo \"$cmd\" | grep -q 'rm'; then\n  exit 2\nfi\n```\n**Why it's bad**: Too broad - blocks legitimate `rm file.tmp`.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nif echo \"$cmd\" | grep -qE 'rm\\s+(-rf|-fr)\\s+\u002F'; then\n  exit 2\nfi\n```\n**Why it's good**: Specific pattern targets actual dangerous commands.\n\u003C\u002Fgood_example>\n\n### Example: Hardcoded Path\n\n\u003Cbad_example>\n```bash\nlog_file=\"\u002Fhome\u002Fuser\u002Fproject\u002F.claude\u002Fcommands.log\"\n```\n**Why it's bad**: Hardcoded path breaks on other machines.\n\u003C\u002Fbad_example>\n\n\u003Cgood_example>\n```bash\nlog_file=\"$CLAUDE_PROJECT_DIR\u002F.claude\u002Fcommands.log\"\n```\n**Why it's good**: Uses environment variable for portability.\n\u003C\u002Fgood_example>\n\u003C\u002Fexamples>\n\n---\n\n## Constraints\n\n- Only apply auto-fixes for HIGH certainty issues\n- Be cautious about security patterns - false negatives worse than false positives\n- Never remove content, only suggest improvements\n- Validate against embedded knowledge reference above\n",{"name":5,"version":30,"description":7,"argument-hint":31},"5.1.0","[path] [--fix]","master","c73386b305dec167db7654e0e6feacb462d4f9dc","assets\u002Fskills\u002Fthinking\u002Fenhance-hooks",1,"https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code","https:\u002F\u002Fgithub.com\u002FAntifragileTech","2026-10-02 14:22:14",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add AntifragileTech\u002Fantifragile-claude-code --skill enhance-hooks",{"tool":45,"command":46},"bunx","bunx skills add AntifragileTech\u002Fantifragile-claude-code --skill enhance-hooks",{"tool":48,"command":49},"pnpm","pnpm dlx skills add AntifragileTech\u002Fantifragile-claude-code --skill enhance-hooks","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fenhance-hooks\u002FSKILL.md",true,[53],{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"index.json","REFERENCE","参考文档",559,"https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Flinux-svc-dbus-msgs-exploit\u002Findex.json",[60,85,100,115,128,141],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":79,"publishedAt":25},"01M6DT9Q6VYA615SCXR757TZZ7","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwriting-skills\u002FSKILL.md",[66,71,74],{"categoryNo":67,"categoryName":68,"taxonomyType":69,"taxonomyTypeDesc":70},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":75,"categoryName":76,"taxonomyType":77,"taxonomyTypeDesc":78},"01JBSEEDCAT000000000000036","内容创作者","PROFESSION","适用职业",[80,81,24,82,83,84],"writing skills","writing","editing","work","deployment",{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":93,"publishedAt":25},"01M6DT9GFHDNY90P41WGAE1TV0","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwriting-plans\u002FSKILL.md",[91,92],{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},{"categoryNo":75,"categoryName":76,"taxonomyType":77,"taxonomyTypeDesc":78},[94,95,81,96,97,24,98,99],"plans","writing plans","requirements","task","code","spec",{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":108,"publishedAt":25},"01M6DT9C6PFGD86WS3HY7YE3XG","docs:write-concisely","Apply writing rules to any documentation that humans will read. Makes your writing clearer, stronger, and more professional.","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwrite-concisely\u002FSKILL.md",[106,107],{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},{"categoryNo":75,"categoryName":76,"taxonomyType":77,"taxonomyTypeDesc":78},[109,110,111,112,113,114,81],"docs:write concisely","write","docs","read","Rules","documentation",{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":121,"publishedAt":25},"01M6DT98AWQ27P0N1CG97WAG66","kaizen:why","Iterative Five Whys root cause analysis drilling from symptoms to fundamentals","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwhy\u002FSKILL.md",[],[117,122,123,124,125,126,127],"why","kaizen","issue","five whys","analysis","root cause analysis",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":25},"01M6DT93EH25NAX19R3WGE1P53","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fverification-loop\u002FSKILL.md",[],[135,136,137,138,98,139,140],"verification loop","verification","loop","sessions","claude code sessions","system",{"skillNo":142,"name":143,"nameZh":6,"description":144,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":145,"categories":146,"keywords":147,"publishedAt":25},"01M6DT90GW7Z7VCN98P9DVYSNC","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fverification-before-completion\u002FSKILL.md",[],[148,136,149,83,24,150,151,152],"verification before completion","commands","evidence","claim","complete"]