Claude Code · HooksPostToolUse
smart-formatting
Formatea según el tipo de archivo con Prettier, Black y otros.
por davila7/claude-code-templates
PostToolUse
Licencia: MITVer original
Instalación
npx claude-code-templates@latest --hook development-tools/smart-formattingContenido
Dónde va: .claude/settings.json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "if [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.js || \"$CLAUDE_TOOL_FILE_PATH\" == *.ts || \"$CLAUDE_TOOL_FILE_PATH\" == *.jsx || \"$CLAUDE_TOOL_FILE_PATH\" == *.tsx || \"$CLAUDE_TOOL_FILE_PATH\" == *.json || \"$CLAUDE_TOOL_FILE_PATH\" == *.css || \"$CLAUDE_TOOL_FILE_PATH\" == *.html ]]; then npx prettier --write \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; elif [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.py ]]; then black \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; elif [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.go ]]; then gofmt -w \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; elif [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.rs ]]; then rustfmt \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; elif [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.php ]]; then php-cs-fixer fix \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; fi"
}
]
}
]
}
}
Más en Hooks
Formatear al editar
Ejecuta Prettier sobre cada archivo que Claude edita o crea.
Bloquear archivos .env
Impide que Claude lea o edite archivos de secretos.
Aviso al terminar
Notificación de escritorio en macOS cuando Claude termina.
Chequeo de tipos al editar
Corre tsc después de editar archivos TypeScript y muestra los errores.
Contexto al iniciar
Carga la rama y los últimos commits al abrir una sesión.
Registro de comandos
Guarda cada comando de shell en un log para auditoría.