Receber por email
← Voltar para o catálogo

claude-code-hooks

Claude Code hook system for pre/post tool execution. Triggers on: hooks, PreToolUse, PostToolUse, hook script, tool validation, audit logging.

367estrelas
Atualizado há 4 meses

Ver no GitHub ↗

Como adicionar

/plugin marketplace add aiskillstore/marketplace

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/claude-code-hooks/svg)](https://www.skillteca.com.br/skills/claude-code-hooks)

Skills relacionadas

Ver todas de Segurança →

Alerta por categoria

Receba novas skills de Segurança toda segunda

1 email curto, só com as skills novas de Segurança. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

Claude Code Hooks

Execute custom scripts before/after Claude Code tool invocations.

Quick Reference

| Event | When | Has Matcher | |-------|------|-------------| | PreToolUse | Before tool execution | Yes | | PostToolUse | After tool completes | Yes | | PermissionRequest | Permission dialog shown | Yes | | Notification | Notifications sent | Yes | | UserPromptSubmit | User submits prompt | No | | Stop | Agent finishes | No | | SubagentStop | Subagent finishes | No | | PreCompact | Before context compaction | No | | SessionStart | Session begins/resumes | No | | SessionEnd | 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 | |---------|---------| | "Write" | Only Write tool | | "" or "" | All tools | | "mcp__" | All MCP tools | | "Bash" | 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: "$VAR" not $VAR
  • [ ] Validate paths (no .. traversal)
  • [ ] Use $CLAUDE_PROJECT_DIR for paths
  • [ ] 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

  • ./references/hook-events.md - All events with input/output schemas
  • ./references/configuration.md - Advanced config patterns
  • ./references/security-patterns.md - Production security

See Also: claude-code-debug for troubleshooting, claude-code-headless for CLI automation

Compartilhar X LinkedIn