Marketplace claude-code-hooks
Claude Code hook system for pre/post tool execution. Triggers on: hooks, PreToolUse, PostToolUse, hook script, tool validation, audit logging.
install
source · Clone the upstream repo
git clone https://github.com/aiskillstore/marketplace
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/aiskillstore/marketplace "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/0xdarkmatter/claude-code-hooks" ~/.claude/skills/aiskillstore-marketplace-claude-code-hooks && rm -rf "$T"
manifest:
skills/0xdarkmatter/claude-code-hooks/SKILL.mdsource content
Claude Code Hooks
Execute custom scripts before/after Claude Code tool invocations.
Quick Reference
| Event | When | Has Matcher |
|---|---|---|
| Before tool execution | Yes |
| After tool completes | Yes |
| Permission dialog shown | Yes |
| Notifications sent | Yes |
| User submits prompt | No |
| Agent finishes | No |
| Subagent finishes | No |
| Before context compaction | No |
| Session begins/resumes | No |
| Session ends | No |
Basic Configuration
Add to
~/.claude/settings.json or .claude/settings.local.json:
{ "hooks": { "PreToolUse": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/hooks/validate.sh", "timeout": 5000 }] }] } }
Matcher Patterns
| Pattern | Matches |
|---|---|
| Only Write tool |
or | All tools |
| All MCP tools |
| Bash commands |
Hook Script Requirements
#!/bin/bash # Receives JSON via stdin: { "tool_name": "...", "tool_input": {...} } INPUT=$(cat) TOOL=$(echo "$INPUT" | jq -r '.tool_name') # Exit codes: # 0 = Success (continue) # 2 = Block with error (stderr shown to Claude) # Other = Non-blocking error
Common Use Cases
| Use Case | Event | Example |
|---|---|---|
| Validate inputs | PreToolUse | Block dangerous commands |
| Audit logging | PostToolUse | Log all tool usage |
| Custom approval | PermissionRequest | Slack notification |
| Session init | SessionStart | Load project context |
Security Checklist
- Quote all variables:
not"$VAR"$VAR - Validate paths (no
traversal).. - Use
for paths$CLAUDE_PROJECT_DIR - Set reasonable timeouts
- Handle jq parsing errors
Troubleshooting
# Debug hook loading claude --debug # List registered hooks /hooks # Test script manually echo '{"tool_name":"Bash"}' | ./hooks/validate.sh
Official Documentation
- https://code.claude.com/docs/en/hooks - Hooks reference
- https://code.claude.com/docs/en/settings - Settings configuration
Additional Resources
- All events with input/output schemas./references/hook-events.md
- Advanced config patterns./references/configuration.md
- Production security./references/security-patterns.md
See Also:
claude-code-debug for troubleshooting, claude-code-headless for CLI automation