/kamal-skills:cronfrom kamal-skills
Run recurring, scheduled, or cron jobs on a Kamal deployment. Use when the user says "run a cron job," "schedule a recurring task," "nightly job," "hourly job," "periodic task," "set up cron with Kamal," "scheduled jobs," "run cron in a container," or asks how to keep a crontab running on their servers. Covers defining a dedicated `cron` role under the `servers:` key with a `cmd` that loads a `config/crontab` file and runs `cron -f`, and propagating environment variables into the crontab (cron does not pass them through on its own). For configuring web and worker job roles or targeting hosts/roles, see servers. For running databases, Redis, or other supporting services, see accessories. For setting `env:` values and secrets the jobs need, see env.
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 running recurring and scheduled jobs on Kamal deployments. Your goal is to get a reliable crontab running in its own container, with the environment variables your jobs need.
Kamal does not have a dedicated cron command. Instead, you run cron jobs in a dedicated container defined as a role under the servers: key. That container runs the system cron daemon in the foreground (cron -f) and loads its schedule from a config/crontab file in your app.
Because it is a separate role, the cron container:
Two facts drive the whole setup:
config/crontab.If the project is already set up, read what exists before asking questions:
config/deploy.yml — see whether a servers: block uses a plain host list or named roles, and whether a cron role already exists.config/crontab — see whether a schedule file is already present..kamal/secrets and the env: block — note which variables your jobs will need (see env).Add a config/crontab file to your repo with the jobs you want to run. This uses standard Unix cron syntax (not Kamal-specific):
# config/crontab
# ┌ minute ┌ hour ┌ day-of-month ┌ month ┌ day-of-week
# │ │ │ │ │
0 2 * * * cd /rails && bin/rails db:cleanup
*/15 * * * * cd /rails && bin/rails reports:refresh
Each line runs inside your app's container, so use the same commands you would run there. Commit this file — Step 2's boot command reads it with cat config/crontab inside the container, so it must be baked into your app image.
For a refresher on the schedule fields and more examples, see references/cron-role-config.md.
Define a cron role under servers: with the hosts to run on and the boot command from the Kamal docs:
servers:
cron:
hosts:
- 192.168.0.1
cmd:
bash -c "(env && cat config/crontab) | crontab - && cron -f"
This assumes the cron settings are stored in config/crontab.
If your servers: block is currently just a plain list of hosts (the implicit web role), you will need to convert it to named roles to add cron alongside web. See servers.
The cmd is the heart of the setup. Read left to right:
| Part | What it does |
|---|---|
env | Prints the container's current environment as NAME=value lines |
cat config/crontab | Prints your schedule file |
( ... ) piped to crontab - | Installs the combined output as the container's crontab |
cron -f | Runs the cron daemon in the foreground so the container stays up |
Prepending env matters because cron does not propagate environment variables. By writing them as NAME=value lines at the top of the crontab, every scheduled job inherits the same environment your app container has — the values from your env: config and secrets. Without this, jobs would run with an almost-empty environment.
The env in the boot command only copies variables that are already present in the container. Make sure the variables your jobs rely on are configured so the cron container receives them.
env:
clear:
RAILS_ENV: production
secret:
- DATABASE_URL
- RAILS_MASTER_KEY
Top-level env applies to all roles, including cron. You can also set role-specific env under the cron role. Secrets are read from .kamal/secrets. See env for the full model.
Deploy as usual to boot the cron container alongside your other roles:
kamal deploy
To act on the cron role only — for example after changing config/crontab or the role's config — target it with the global --roles option:
kamal deploy --roles cron
Because the boot command reads config/crontab from inside the image, updating the schedule means deploying a new version of the app that contains the edited file.
Check that the cron container is running:
kamal details
To inspect the crontab actually installed in the running cron container, reuse it and list the crontab:
kamal app exec --reuse --roles cron 'crontab -l'
For more on running one-off commands against a role or host, see servers.
(env && ...) part of the boot command, or the variables were never in the container's env:. Cron will not inherit them otherwise.config/crontab and redeploy — editing it locally does nothing until a new version ships.config/crontab exists at the path the boot command reads and is part of the built image.cron -f to keep cron in the foreground; if you change the command, keep a foreground process so the container stays up.For the full set of configuration keys you can set on the cron role (and any role), a breakdown of the boot command, and a standard crontab syntax primer, see references/cron-role-config.md.
Official docs: Cron configuration.
web and worker roles, and targeting hosts/roles with --hosts and --roles.env: values and secrets the cron container needs to copy into the crontab.kamal deploy workflow that boots the cron role.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.Other plugins' skills for the same job
npx claudepluginhub donnfelker/kamal-skills --plugin kamal-skills