From claude-ecosystem
Manages Claude Code repository hooks for adding, configuring, troubleshooting, enabling/disabling, and enforcing rules. Delegates to docs-management for official documentation.
npx claudepluginhub melodic-software/claude-code-plugins --plugin claude-ecosystemThis skill is limited to using the following tools:
> **STOP - Before providing ANY response about Claude Code hooks:**
references/architecture/design-principles.mdreferences/architecture/multi-language-strategy.mdreferences/audit-framework.mdreferences/configuration/hook-config-guide.mdreferences/development/best-practices.mdreferences/development/creating-hooks-workflow.mdreferences/development/testing-guide.mdreferences/inventory/active-hooks.mdreferences/inventory/hook-lifecycle.mdreferences/troubleshooting/common-issues.mdreferences/troubleshooting/debugging-guide.mdConfigures Claude Code hooks for lifecycle events like PreToolUse, SessionStart, and automation use cases such as formatting enforcement and permission control.
Manages hooks and automation for coding agents like Claude Code, Codex CLI, OpenCode. Add, list, remove, update, or validate hooks for 28 events including SessionStart, PreToolUse, and FileChanged.
Author Claude Code hooks for events like PreToolUse and PostToolUse using command, prompt, or agent types to automate workflows and validate operations.
Share bugs, ideas, or general feedback.
STOP - Before providing ANY response about Claude Code hooks:
- INVOKE
docs-managementskill- QUERY using keywords: hooks, PreToolUse, PostToolUse, hook events, hook configuration, or related topics
- BASE all responses EXCLUSIVELY on official documentation loaded
Skipping this step results in outdated or incorrect information.
Before responding, verify:
If ANY checkbox is unchecked, STOP and invoke docs-management first.
Central authority for managing Claude Code hooks in this repository. Automates enforcement of critical repository rules that were previously manual in CLAUDE.md.
Architecture: Vertical slice organization with externalized configuration, multi-language support, immediate config reload, and comprehensive testing.
Keywords: hooks, hook management, automation, validation, enforcement, PreToolUse, PostToolUse, SessionStart, SessionEnd, Setup hook, hook configuration, plugin hooks, local hooks, CLAUDE_HOOK_ENABLED, hook environment variables, enable hook, disable hook, --init, --init-only, --maintenance
Use this skill when:
For ALL Claude Code hooks capabilities, configuration patterns, and syntax, you MUST use the docs-management skill.
⚠️ STALENESS WARNING: Do NOT hardcode hook event names, decision values, or environment variables. ALWAYS query docs-management for the authoritative list of hook capabilities.
Query Patterns for Official Hook Documentation:
| Topic | Query Pattern | What You'll Find |
|---|---|---|
| Hook event types | "hooks.md hook events", "hook event types" | Complete list of available events |
| Hook configuration | "hooks.md configuration syntax" | JSON structure and required fields |
| Matchers | "hooks.md matchers tool names" | Tool matching patterns |
| Decision control | "hooks.md decision control", "hook return values" | Valid decision values and behavior |
| Exit codes | "hooks.md exit codes" | Exit code meanings |
| JSON output | "hooks.md JSON output schema" | Output schema for hook responses |
| Environment variables | "hooks.md environment variables" | Available env vars in hooks |
| Command vs prompt hooks | "hooks.md command prompt based" | Hook type differences |
| Plugin hooks | "hooks.md plugin hooks integration" | Plugin-specific patterns |
Example queries:
docs-management: "hooks.md hook event types"
docs-management: "hooks.md decision control values"
docs-management: "hooks.md environment variables available"
Frontmatter Hooks (v2.1.x):
frontmatter hooks, skill hooks, agent hooks, command hooks, once trueSessionStart Hook Input (v2.1.2+):
SessionStart, agent_type, --agent flagagent_type field when invoked with --agent CLI flagPreToolUse additionalContext Return (v2.1.9+):
PreToolUse, additionalContext, hook return, context injectionadditionalContext field to provide additional context to the modeldocs-management: "hooks.md PreToolUse additionalContext return"Setup Hook Event (v2.1.10+):
Setup hook, Setup event, --init, --init-only, --maintenance, repository setup--init, --init-only, or --maintenance CLI flagsdocs-management: "hooks.md Setup hook event"Organization-specific implementation:
What do you want to do?
plugin-development skill (see below)If you're working with plugin hooks (hooks bundled in a Claude Code plugin), use the plugin-development skill instead. Plugin hooks use a different configuration pattern:
| Aspect | Local Hooks (this skill) | Plugin Hooks |
|---|---|---|
| Location | .claude/hooks/ directory | Plugin hooks/hooks.json |
| Configuration | YAML files (config.yaml) | Environment variables |
| Consumer Control | Edit config files directly | Via settings.json env section |
For plugin hooks: Invoke plugin-development skill and see the Plugin Hook Configuration section.
All references in this skill are conditional load - they are loaded only when needed based on the workflow you're following.
Architecture References (load when understanding design):
references/architecture/design-principles.md → When understanding vertical slice, DRY, config-over-hardcoding principlesreferences/architecture/multi-language-strategy.md → When implementing or migrating to Python/TypeScriptInventory References (load when working with hooks):
references/inventory/active-hooks.md → When reviewing what hooks are active and their configurationsreferences/inventory/hook-lifecycle.md → When enabling/disabling hooks or changing enforcement modesConfiguration References (load when configuring):
references/configuration/hook-config-guide.md → When modifying global.yaml or config.yaml filesDevelopment References (load when creating/testing):
references/development/creating-hooks-workflow.md → When creating a new hook from scratchreferences/development/testing-guide.md → When writing tests for hooksreferences/development/best-practices.md → When ensuring code quality and following patternsTroubleshooting References (load when debugging):
references/troubleshooting/common-issues.md → When encountering problems (hook not running, config not applying, etc.)references/troubleshooting/debugging-guide.md → When performing advanced debugging or profilingdocs-management skill queries (always)This architecture ensures optimal token efficiency while maintaining comprehensive guidance coverage.
For complete details, see Active Hooks Reference.
All hooks use environment variables for configuration. See Configuration Guide for complete details.
Quick actions:
CLAUDE_HOOK_{NAME}_ENABLED=1 in .claude/settings.json env sectionCLAUDE_HOOK_{NAME}_ENABLED=0 or remove the variableCLAUDE_HOOK_ENFORCEMENT_{NAME} to block, warn, or logCLAUDE_HOOK_DEBUG=1Example configuration in .claude/settings.json:
{
"env": {
"CLAUDE_HOOK_MARKDOWN_LINT_ENABLED": "1",
"CLAUDE_HOOK_LOG_EVENTS_ENABLED": "1"
}
}
For environment variable patterns, default states, and legacy YAML configuration, see Configuration Reference.
.claude/hooks/
├── config/
│ └── global.yaml # Shared configuration
├── shared/ # Shared utilities (all hooks)
│ ├── json-utils.sh # JSON parsing helpers
│ ├── path-utils.sh # Path manipulation utilities
│ ├── config-utils.sh # Config loading utilities
│ └── test-helpers.sh # Test assertion framework
├── prevent-backup-files/ # Vertical slice: Hook 1
│ ├── bash/ # Language-specific implementation
│ ├── config.yaml # User configuration (enabled, enforcement)
│ ├── hook.yaml # Hook metadata (name, version, description)
│ ├── README.md # Hook documentation
│ └── tests/ # Tests for THIS hook
├── require-gpg-signing/ # Vertical slice: Hook 2
│ ├── bash/
│ ├── config.yaml
│ ├── hook.yaml
│ ├── README.md
│ └── tests/
├── <other-hooks>/ # Additional hooks follow same pattern
├── test-runner.sh # Discovers & runs all *.test.sh files
└── README.md # Quick reference
Key principles:
For complete architecture details, see Design Principles.
All hooks have access to shared helper functions in .claude/hooks/shared/. See Best Practices for usage examples.
Note: Bash utilities maintained for legacy compatibility. New hooks should use Python with pathlib for cross-platform compatibility.
Disable all hooks temporarily:
# Edit .claude/hooks/config/global.yaml
enabled: false
View hook activity:
# Edit .claude/hooks/config/global.yaml
log_level: debug
Run all tests:
bash .claude/hooks/test-runner.sh
Test specific hook:
bash .claude/hooks/<hook-name>/tests/integration.test.sh
Test manually:
echo '{"tool": "Write", "file_path": "test.txt"}' | \
bash .claude/hooks/<hook-name>/bash/<hook-name>.sh
For complete workflow guidance, see Hook Lifecycle.
CLAUDE.md references hooks for automated enforcement. See Active Hooks for the complete list of rules automated by hooks.
This skill provides the validation criteria used by the hook-auditor agent for formal audits.
| Resource | Location | Purpose |
|---|---|---|
| Audit Framework | references/audit-framework.md | Query guides and scoring criteria |
| Category | Points | Key Criteria |
|---|---|---|
| Configuration Structure | 25 | Valid hooks.json, required fields, valid event types |
| Hook Scripts | 20 | Scripts exist, proper structure, exit codes |
| Matchers | 20 | Appropriate tool/path matchers |
| Environment Variables | 15 | Follows naming convention, documented |
| Testing | 20 | Has tests, tests pass, adequate coverage |
Thresholds: 85+ = PASS, 70-84 = PASS WITH WARNINGS, <70 = FAIL
The hook-auditor agent (Haiku model) performs formal audits using this skill:
skills: hook-management/audit-hooks commandWhen auditing hooks that use external technologies (scripts, packages, runtimes), the auditor MUST validate claims using MCP servers before flagging findings.
Technologies Requiring MCP Validation:
Validation Rule:
Never flag a technology usage as incorrect without first:
Stale Data Warning:
Detailed Documentation:
Quick Access:
.claude/hooks/.claude/hooks/shared/ (includes unit tests).claude/hooks/config/global.yaml.claude/hooks/README.md.claude/hooks/test-runner.shQuery: "Use the hook-management skill to add a new hook"
Expected Behavior:
Success Criteria: User receives step-by-step guidance for hook creation
Query: "My hook isn't running, help me debug it"
Expected Behavior:
Success Criteria: User identifies and resolves hook execution issue
Query: "How do I disable the GPG signing hook?"
Expected Behavior:
Success Criteria: User successfully disables specific hook
Query: "Explain the hooks directory structure"
Expected Behavior:
Success Criteria: User understands hook organization principles
Query: "What hook events are available in Claude Code?"
Expected Behavior:
Success Criteria: User receives current official documentation via docs-management
v1.4.3 (2026-01-16): Added Setup hook event keyword (v2.1.10)
v1.4.2 (2026-01-16): Added PreToolUse additionalContext keyword (v2.1.9)
v1.4.1 (2026-01-12): Added SessionStart agent_type keyword (v2.1.2)
v1.4.0 (2026-01-09): Added v2.1.x frontmatter hooks keyword registry entry
v1.3.0 (2025-12-01): Environment variable standardization
CLAUDE_HOOK_{NAME}_ENABLED patternv1.2.2 (2025-11-30): Plugin hooks delegation
.claude/hooks/), plugin hooks use different patternsv1.2.1 (2025-11-25): Audit improvements
v1.2.0 (2025-11-24): Configuration architecture clarification
config.yaml (user config) and hook.yaml (metadata)config.yaml for runtime configurationv1.1.0 (2025-11-18): Progressive disclosure refactoring
v1.0.0 (2025-11-18): Initial release
Date: 2026-01-16 Model: claude-opus-4-5-20251101