Hooks

Hooks

7 pre-configured hooks for Laravel code quality and security

How Hooks Work

Hooks are shell scripts that run automatically in response to Claude Code events. They enforce code quality standards, prevent security issues, and automate common tasks.

UserPromptSubmit

Runs before user prompts are processed (e.g., git commit)

PostToolUse

Runs after tools like Edit/Write modify files

pre-commit.sh

UserPromptSubmit

Comprehensive pre-commit validation with PHP syntax, Pint formatting, PHPStan analysis, security scanning, and Blade template checks.

PHP syntax validation
Laravel Pint auto-formatting
PHPStan static analysis
Security scanning

post-edit.sh

PostToolUse

Auto-formats PHP files after edit/write operations and updates IDE helper files for better autocompletion.

Auto-format PHP with Pint
Update IDE helper models

security-scan.sh

PostToolUse

Scans for secrets, API keys, passwords, and debug functions. Detects AWS, Stripe, GitHub tokens and more.

API keys (AWS, Stripe, GitHub)
Private keys and JWT tokens
Debug functions (dd, dump)

migration-safety.sh

PostToolUse

Warns about destructive migration operations like dropColumn, dropTable, and truncate. Checks for down() methods.

dropColumn, dropTable, drop
truncate operations
Missing down() method

blade-lint.sh

PostToolUse

Validates Blade templates for security and best practices. Checks CSRF tokens, XSS prevention, and directive usage.

Missing @csrf in forms
Unescaped output ({!! !!})
Missing @method for PUT/DELETE

test-runner.sh

PostToolUse

Automatically runs related tests when files are modified. Supports both Pest and PHPUnit test frameworks.

Detect related test files
Run Pest or PHPUnit
Block on test failures

env-check.sh

PostToolUse

Validates environment files and blocks .env commits. Checks for secrets in .env.example and duplicate keys.

Block .env file commits
Check .env.example for secrets
Detect duplicate keys

Installation

Add hooks to your project's .claude/settings.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "git commit",
        "command": "bash .claude-plugins/laravel-agent/hooks/scripts/pre-commit.sh"
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit",
        "command": "bash .claude-plugins/laravel-agent/hooks/scripts/post-edit.sh \"$TOOL_INPUT_FILE_PATH\""
      },
      {
        "matcher": "Write",
        "command": "bash .claude-plugins/laravel-agent/hooks/scripts/post-edit.sh \"$TOOL_INPUT_FILE_PATH\""
      }
    ]
  }
}

Exit Codes

0

Success - all checks passed

1

Warning - non-blocking issues

2

Error - blocks the operation