Chezmoi Script Maintainer
Use this skill for .chezmoiscripts/ work so behavior stays fast, quiet, and repeatable.
Required Script Contract
Follow the patterns in references/script-patterns.md.
For new scripts:
- •Use
#!/usr/bin/env bashandset -euo pipefailunlessshcompatibility is required. - •Define
VERBOSE,vecho, andeechowith quiet-by-default output. - •Use
STATE_DIR="${STATE_DIR:-$HOME/.cache/chezmoi-state}". - •Add an early state-file exit when the task is one-time setup.
- •Prefer fast checks before installers (for example, command existence + version check).
- •Keep non-interactive defaults; only use interactive sudo when explicitly gated.
Implementation Workflow
- •Inspect adjacent scripts to match naming and ordering:
- •
run_before_*.shfor prerequisites. - •
run_after_*.shfor post-apply setup.
- •Reuse existing helpers and guard patterns:
- •Installer trust gate (
TRUST_ON_FIRST_USE_INSTALLERS). - •Role gate (
CHEZMOI_ROLE=serverskip rules where applicable). - •Optional interactive sudo gate (
CHEZMOI_BOOTSTRAP_ALLOW_INTERACTIVE_SUDO).
- •Keep changes idempotent:
- •Repeated
chezmoi applymust not re-run expensive work unnecessarily.
- •Keep docs aligned if behavior changes:
- •Update
README.mdandCLAUDE.mdwhen setup, role logic, or commands change.
Validation
bash
bash -n .chezmoiscripts/*.sh chezmoi apply --dry-run
When editing .tmpl scripts, validate rendered output:
bash
chezmoi execute-template < .chezmoiscripts/run_after_25-setup-uv.sh.tmpl | bash -n chezmoi execute-template < .chezmoiscripts/run_after_30-setup-node.sh.tmpl | bash -n