captainhook/hook-installer
Composer plugin for CaptainHook that automatically installs and updates your local Git hooks after composer install/update, helping ensure your whole team has hooks enabled. Supports custom config/executable paths and optional force/only-enabled settings.
Prerequisites:
captainhook/captainhook or captainhook/captainhook-phar in your project.Install the Plugin:
composer require --dev captainhook/hook-installer
This registers the Composer plugin automatically.
First Use Case:
After running composer install or composer update, CaptainHook hooks will be automatically activated in your .git/hooks directory.
No manual captainhook install command is needed.
Standard Laravel Workflow:
composer.json under require-dev:
"captainhook/hook-installer": "^1.0"
composer install, hooks are installed without manual intervention.Custom Hook Configuration:
captainhook.json in a non-default location (e.g., config/captainhook.json).composer.json:
"extra": {
"captainhook": {
"config": "config/captainhook.json"
}
}
CI/CD Pipelines:
composer install --no-dev in CI, then explicitly run:
composer hook-install # If needed for testing hooks
composer install --prefer-dist --no-interaction --optimize-autoloader
composer hook-install
Team Onboarding:
composer.json changes in your CONTRIBUTING.md.## Git Hooks
Run `composer install` to automatically set up CaptainHook. No additional steps required.
PHP Binary Path:
php is not in $PATH, the installer may fail. Fix by:
composer.json:
"extra": {
"captainhook": {
"exec": "/path/to/php tools/captainhook.phar"
}
}
php is in your system PATH.Disabled Plugin:
disable-plugin is set to true in composer.json, the installer silently skips hook installation.composer config extra.captainhook.disable-plugin
Hook Overwrites:
.git/hooks if they conflict. Backup hooks manually if needed:
mv .git/hooks .git/hooks.bak
Composer Version Conflicts:
"require": {
"composer-plugin-api": "~1.0"
}
-v to see installation steps:
composer install -v
composer hook-install --dry-run
Conditional Installation:
Use only-enabled: true to skip disabled hooks (e.g., for optional pre-commit checks):
"extra": {
"captainhook": {
"only-enabled": true
}
}
Force Install:
Override user preferences with force-install: true (useful for shared environments):
"extra": {
"captainhook": {
"force-install": true
}
}
Custom Scripts:
Extend the plugin by creating a post-install script in composer.json:
"scripts": {
"post-install-cmd": [
"@hook-installer",
"php artisan hook:verify" # Custom Laravel command
]
}
Artisan Integration: Create a custom Artisan command to verify hooks:
// app/Console/Commands/VerifyHooks.php
public function handle() {
$this->info('Checking CaptainHook status...');
$output = shell_exec('captainhook status');
$this->line($output);
}
Register it in app/Console/Kernel.php:
protected $commands = [
Commands\VerifyHooks::class,
];
Environment-Specific Hooks: Use Laravel’s environment files to toggle hooks:
// composer.json
"extra": {
"captainhook": {
"config": "config/captainhook.{{ env('APP_ENV') }}.json"
}
}
How can I help you explore Laravel packages today?