/kamal-skills:envfrom kamal-skills
Configure environment variables in your Kamal deploy.yml — the `env` block with `clear` values, `secret` references loaded from `.kamal/secrets`, `tags` for per-host overrides, and per-role `env`. Use when the user says things like "add an env var to Kamal," "set DATABASE_URL in deploy.yml," "pass a secret to my container," "how do I keep my API key out of git," "different env vars per server or role," "clear vs secret env," "aliased secrets," or asks about `env.clear`, `env.secret`, `env.tags`, or `kamal secrets fetch`/`extract`. Covers how clear values are passed to `docker run` while secret values are written to an env file on the host. For managing the secret values themselves and password-manager helpers, see secrets. For tagging hosts and defining roles, see servers. For the overall deploy.yml structure, see config.
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 deploying applications with Kamal. Your goal is to help configure environment variables in deploy.yml correctly: keeping plain values readable, keeping secrets out of version control, and targeting specific hosts or roles when needed.
Environment variables can be set directly in the Kamal configuration or read from .kamal/secrets. When you deploy, Kamal passes them to the docker run command that starts your container.
Look at what already exists before asking the user questions:
config/deploy.yml and find the env block (and any env under servers roles or accessories)..kamal/secrets (and .kamal/secrets-common / .kamal/secrets.<destination> if present) to see which secret names are already defined.clear or secret.envFor non-sensitive variables, set them directly as key/value pairs. These are passed to the docker run command when deploying.
env:
DATABASE_HOST: mysql-db1
DATABASE_PORT: 3306
As soon as you need a secret, list the secret names under the secret key and move the other variables under the clear key.
env:
clear:
DB_USER: app
secret:
- DB_PASSWORD
Unlike clear values, secrets are not passed directly to the container — they are stored in an env file on the host.
clear | secret | |
|---|---|---|
| Declared as | key/value map | list of variable names |
| Where the value lives | the config file (deploy.yml) | .kamal/secrets, loaded by Kamal |
| How it reaches the container | passed directly to docker run | written to an env file on the host, not passed directly |
| Safe to commit | yes | no — keep the values out of version control |
clear (or use the simple form if you have no secrets at all).secret — names only, not values..kamal/secrets (see below).docker run and writes the secret values to an env file on the host..kamal/secretsKamal uses dotenv to automatically load environment variables from the configured secrets files. You can use variable substitution or command substitution in the file:
# .kamal/secrets
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
RAILS_MASTER_KEY=$(cat config/master.key)
Kamal looks for .kamal/secrets-common first, then .kamal/secrets, with later values overriding earlier ones. This file is where variables like KAMAL_REGISTRY_PASSWORD or database passwords live.
If you store secrets directly in .kamal/secrets, ensure that it is not checked into version control.
To pull values from a password manager instead of storing them in plain text, use the secret helpers — kamal secrets fetch and kamal secrets extract:
SECRETS=$(kamal secrets fetch ...)
REGISTRY_PASSWORD=$(kamal secrets extract REGISTRY_PASSWORD $SECRETS)
DB_PASSWORD=$(kamal secrets extract DB_PASSWORD $SECRETS)
For the secrets-file loading order with destinations, command/variable substitution, and the full list of password-manager adapters, see references/secrets-files.md.
When the env variable name differs from the secret name — or you need the same env name to map to different secrets in different contexts — alias them with a : separator (ENV_NAME:SECRET_NAME).
env:
secret:
- DB_PASSWORD:MAIN_DB_PASSWORD
This reads the secret MAIN_DB_PASSWORD and exposes it to the container as DB_PASSWORD. For a full example aliasing the same env name to different secrets across roles and accessories, see references/secrets-files.md.
Tags add extra env variables to specific hosts. First tag the hosts (see servers), then reference each tag under env.tags. The variables under a tag can use clear and secret values just like the top-level env.
env:
tags:
monitoring:
MYSQL_USER: monitoring
replica:
clear:
MYSQL_USER: readonly
secret:
- READONLY_PASSWORD
Tags are only allowed in the top-level env configuration — not under a role-specific env.
For multi-role deployments, you can set an env block under a specific role in servers. This applies those variables only to that role's containers.
servers:
web:
- 172.1.0.1
workers:
hosts:
- 172.1.0.3
cmd: "bin/jobs"
env:
clear:
MYSQL_USER: app
secret:
- MYSQL_PASSWORD
Remember: tags cannot be used inside a role-specific env. Use top-level env.tags for per-host overrides.
env:
clear:
MYSQL_USER: app
secret:
- MYSQL_PASSWORD
tags:
monitoring:
MYSQL_USER: monitoring
replica:
clear:
MYSQL_USER: readonly
secret:
- READONLY_PASSWORD
.kamal/secrets mechanics and the kamal secrets password-manager helpers.deploy.yml and where the env block fits.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub donnfelker/kamal-skills --plugin kamal-skills25 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