/kamal-skills:hooksfrom kamal-skills
Write and wire up Kamal deploy hooks — scripts in `.kamal/hooks` (docker-setup, pre-connect, pre-build, pre-deploy, post-deploy, pre-app-boot, post-app-boot, pre-proxy-reboot, post-proxy-reboot) that run at fixed points in a deploy, plus the `KAMAL_*` env vars (`KAMAL_VERSION`, `KAMAL_PERFORMER`, `KAMAL_HOSTS`, `KAMAL_RECORDED_AT`) passed to them for audit reporting, deploy notifications, CI gates, and load-balancer draining. Use when the user says "add a deploy hook," "run a script before/after deploy," "post-deploy notification," "fail the deploy if CI hasn't passed," "block deploys unless I'm on the VPN," "run a script when kamal-proxy reboots," "where do hooks live," "hooks_path," "hooks_output," "skip hooks," or "what are the KAMAL_ env vars." Covers the `.kamal/hooks` folder from `kamal init`, naming rules, non-zero exit aborting the command, `hooks_path`/`hooks_output`, and `--skip-hooks`. For the deploy sequence these fire within, see deploy. For builds, see build.
Ships in kamal-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in extending Kamal deploys with hooks. Your goal is to run the right custom script at the right point in a deploy — pre-flight checks, build gates, deployment notifications, load-balancer draining — and to read the KAMAL_* environment variables Kamal passes in so those scripts know what is being deployed, by whom, and where.
Read what already exists before asking the user questions:
.kamal/hooks/ — the default hooks folder. kamal init creates it with sample scripts. List it to see which hooks are already wired up.config/deploy.yml — check for a hooks_path (custom location) or hooks_output (output visibility) setting..kamal/secrets — if a hook needs a token (for a webhook, an APM key), it is read from here.Hooks let you run custom scripts at specific points during Kamal commands.
.kamal/hooks folder by default. Change the location with hooks_path (see Configuring Location and Output).pre-deploy, not pre-deploy.sh or pre-deploy.rb.KAMAL_* environment variables into every hook so the script knows what is happening (see KAMAL_* Environment Variables).--skip-hooks (see Skipping Hooks).Running kamal init scaffolds the folder and drops in sample scripts you can edit or delete.
Each hook fires at a documented point. Name your script exactly as the hook name.
| Hook | When it runs | Typical use |
|---|---|---|
docker-setup | Once Docker is installed on a server, before any app-specific actions | Configure Docker itself |
pre-connect | Before taking the deploy lock, before connecting to remote hosts | DNS warming, checking you are on the VPN |
pre-build | Before the image build | Ensure no uncommitted changes, or that CI has passed |
pre-deploy | Final checks before deploying | Check CI completed |
post-deploy | After a deploy, redeploy, or rollback | Broadcast a deployment message, register the version with an APM |
pre-app-boot | Before booting the app container (kamal app boot, or via kamal deploy) | Prepare for the new container |
post-app-boot | After booting the app container (kamal app boot, or via kamal deploy) | Verify or announce the new container |
pre-proxy-reboot | Before rebooting the kamal-proxy container (kamal proxy reboot) | Drain a server from an external load balancer |
post-proxy-reboot | After rebooting the kamal-proxy container | Re-enable the server in the load balancer |
For the full detail on each hook — including the grouped-boot and rolling-reboot behaviors — see references/hook-reference.md.
Put a script in .kamal/hooks named exactly after the hook, with no extension. For a pre-deploy gate:
# .kamal/hooks/pre-deploy
Give it a shebang and make it executable — Kamal runs the file directly:
chmod +x .kamal/hooks/pre-deploy
A non-zero exit code aborts the command, so a pre-deploy or pre-build hook can stop a bad deploy before it starts:
#!/usr/bin/env bash
# .kamal/hooks/pre-build — refuse to build with uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "Uncommitted changes present — commit before deploying." >&2
exit 1
fi
Kamal passes context in as environment variables. Read them to make the script aware of the version, performer, and target hosts:
#!/usr/bin/env bash
# .kamal/hooks/pre-deploy
echo "Deploying ${KAMAL_VERSION} to ${KAMAL_HOSTS} as ${KAMAL_PERFORMER}"
Run your command as usual. The hooks fire at their points automatically:
kamal deploy
If you need to deploy without running any hooks this once, add --skip-hooks.
These variables are available to every hook command, intended for fine-grained audit reporting — triggering deployment reports or firing a JSON webhook:
| Variable | Value |
|---|---|
KAMAL_RECORDED_AT | UTC timestamp in ISO 8601 format, e.g. 2023-04-14T17:07:31Z |
KAMAL_PERFORMER | The local user performing the command (from whoami) |
KAMAL_SERVICE | The service name, e.g. app |
KAMAL_SERVICE_VERSION | Abbreviated service and version for messages, e.g. app@150b24f |
KAMAL_VERSION | The full version being deployed |
KAMAL_HOSTS | Comma-separated list of the hosts targeted by the command |
KAMAL_COMMAND | The command being run |
KAMAL_SUBCOMMAND | Optional: the subcommand being run |
KAMAL_DESTINATION | Optional: destination, e.g. staging |
KAMAL_ROLE | Optional: role targeted, e.g. web |
The post-deploy hook additionally receives KAMAL_RUNTIME, set to the total seconds the deploy took.
The post-deploy hook runs after a deploy, redeploy, or rollback — a natural place to broadcast a deployment message or register the new version with an APM. This example posts a line to a preconfigured chatbot:
#!/usr/bin/env bash
# .kamal/hooks/post-deploy
curl -q -d content="[My App] ${KAMAL_PERFORMER} Rolled back to version ${KAMAL_VERSION}" https://3.basecamp.com/XXXXX/integrations/XXXXX/buckets/XXXXX/chats/XXXXX/lines
That posts a message like:
[My App] [dhh] Rolled back to version d264c4e92470ad1bd18590f04466787262f605de
Because post-deploy also gets KAMAL_RUNTIME, you can include the deploy duration in the message.
Both keys go in the root of config/deploy.yml.
Path to the hooks folder. Defaults to .kamal/hooks. Override it to keep hooks elsewhere:
hooks_path: /user_home/kamal/hooks
Controls hook output visibility. Set it globally or per-hook. CLI flags (-v, -q) override these settings.
| Value | Effect |
|---|---|
:quiet | Hook output is hidden |
:verbose | Hook output is shown |
With no setting, hook output follows the CLI verbosity flags. Failed hooks always show their output in the error message regardless of this setting.
Global setting for all hooks:
hooks_output: :verbose
Or per-hook:
hooks_output:
pre-deploy: :verbose
pre-build: :quiet
Pass --skip-hooks (-H) to run a command without its hooks:
kamal deploy --skip-hooks
Use it when you need to bypass a gate for a one-off deploy. For how --skip-hooks fits into the deploy command's other flags, see the deploy skill.
| Goal | How |
|---|---|
| Scaffold the hooks folder with samples | kamal init |
| Add a hook | Create .kamal/hooks/<hook-name> (no extension), make it executable |
| Gate / abort a command | Exit the hook script with a non-zero code |
| Know the version / performer / hosts in a hook | Read KAMAL_VERSION, KAMAL_PERFORMER, KAMAL_HOSTS |
| Get the deploy duration | Read KAMAL_RUNTIME in post-deploy |
| Move the hooks folder | hooks_path: in config/deploy.yml |
| Show or hide hook output | hooks_output: :verbose / :quiet (global or per-hook) |
| Run a command without hooks | --skip-hooks (-H) |
kamal deploy / kamal redeploy sequence these hooks fire within, and the other flags that pair with --skip-hooks.kamal build step where the pre-connect and pre-build hooks run.pre-deploy hook that refuses commits without a green gh-signoff status, for teams that run tests locally.What SKILL.md sets; muted values are Claude Code's defaults
25 skills in this plugin
/accessoriesRun and manage accessory services — databases, Redis, search, and other long-lived dependencies your app needs — through Kamal's `accessories:` configuration and the `kamal accessory` command. Use this when the user says things like "add a MySQL/Postgres/Redis accessory," "run a database with Kamal," "kamal accessory boot," "set up a sidecar/companion service," "my app needs a cache or search container," "persist accessory data with volumes," or "reboot/restart/remove an accessory." Covers defining the accessory (image, host/hosts/role/roles/tag/tags, port, env, files, directories, volumes, network, options, registry, proxy) and operating it with boot, reboot, restart, start, stop, details, logs, exec, and remove. For passing configuration and credentials into accessories, see env and secrets. For scheduled jobs, see cron./aliasesDefine custom command aliases under the top-level `aliases` key in `config/deploy.yml` so a long, repeated `kamal` invocation becomes a single `kamal <name>`. Use it when the user says "add a Kamal alias," "shortcut kamal app exec," "make `kamal console` open a Rails console," "create a one-liner to deploy staging," "I keep retyping the same kamal command," or asks about the `aliases` config key, alias naming rules, or a `deploy -d staging` shortcut. Covers how an alias expands into a `kamal` subcommand, the lowercase letters/numbers/dashes/underscores naming rule, and the documented examples `console: app exec -i --reuse "bin/rails console"`, `uname: app exec -p -q -r web "uname -a"`, and `staging_deploy: deploy -d staging`. For the rest of `config/deploy.yml` and DRYing it up with YAML anchors, see config. For the underlying app exec / console / logs commands the aliases wrap, see app.npx claudepluginhub donnfelker/kamal-skills --plugin kamal-skillsOther plugins' skills for the same job