v2/bin/init/templates/commands/hooks/pre-command.md
Execute pre-command validations and safety checks before running shell commands.
npx claude-flow hook pre-command [options]
--command, -c <cmd> - Command to be executed--validate-safety - Check command safety (default: true)--check-permissions - Verify execution permissions--estimate-duration - Estimate command runtime--dry-run - Preview without executingnpx claude-flow hook pre-command --command "npm install express"
npx claude-flow hook pre-command -c "rm -rf node_modules" --validate-safety
npx claude-flow hook pre-command -c "sudo apt update" --check-permissions
npx claude-flow hook pre-command -c "git push origin main" --dry-run
This hook is automatically called by Claude Code when:
Manual usage in agents:
# Before running commands
npx claude-flow hook pre-command --command "your command here" --validate-safety
Returns JSON with:
{
"continue": true,
"command": "npm install express",
"safe": true,
"estimatedDuration": 15000,
"warnings": [],
"permissions": "user",
"affectedFiles": ["package.json", "package-lock.json"],
"dryRunOutput": "Would install 50 packages"
}
hook post-command - Post-command processingBash - Command execution toolterminal execute - Terminal operationssecurity scan - Security validation