| name | sops-setup |
| description | Set up SOPS + age encryption for sharing .env files securely across machines. Detects existing state, installs tools, generates age keys, creates .sops.yaml, and encrypts .env files as YAML (avoids SOPS dotenv bug #1435). Use when user mentions "sops setup", "encrypt env", "share secrets", "secure env files", "sops age setup", "env encryption", "setup sops", "share env across machines". |
| disable-model-invocation | true |
SOPS + age Setup Wizard
Interactive setup for SOPS + age encryption. Detects current state and guides through configuration.
Important: This skill uses YAML format for encrypted files (not dotenv) because SOPS has a known bug (#1435) where the dotenv store corrupts backslash and \n sequences on decrypt. A helper script handles dotenv↔YAML conversion transparently.
Pre-flight
Run the detection script to understand current state:
python3 ${CLAUDE_SKILL_DIR}/scripts/detect_sops.py <project-root>
Two-Phase Workflow
Phase 1: Detect
-
Run the detector on the project root:
python3 ${CLAUDE_SKILL_DIR}/scripts/detect_sops.py <project-root>
-
Summarize findings — show a status table:
| Component | Status | Detail |
|---|
| sops binary | installed/missing | version, path |
| age binary | installed/missing | version, path |
| age key | exists/missing | public key (truncated) |
| .sops.yaml | exists/missing | # of authorized keys |
| .env files | N found | list of filenames |
| encrypted files | N found | list of *.enc.yaml files |
| .gitignore | ok/needs update | env ignored, enc.yaml not ignored |
Phase 2: Configure
Walk through each missing component. Skip steps where detection shows everything is already configured.
-
Install tools (if tools.sops.installed or tools.age.installed is false):
- Show install commands based on
os field:
- macOS:
brew install sops age
- Linux: Show download URLs for latest binaries from GitHub releases
- After user confirms installation, re-run detector to verify
-
Generate age key (if age_key.exists is false):
- Create directory:
mkdir -p ~/.config/sops/age
- Generate key:
age-keygen -o ~/.config/sops/age/keys.txt
- Set permissions:
chmod 600 ~/.config/sops/age/keys.txt
- Display the public key and tell user to save it somewhere safe (password manager, secure note)
-
Generate backup key (recommended):
-
Create .sops.yaml (if project.sops_yaml.exists is false):
-
Set up .gitattributes for diff-friendly encrypted files:
-
Update .gitignore (if needed):
- Ensure
.env* patterns are ignored (secrets must not be committed in plaintext)
- Ensure
*.enc.yaml is NOT ignored (encrypted files should be committed)
- Show proposed changes and confirm with user before writing
-
Encrypt files (if project.env_files is non-empty):
-
Confirmation summary — show table of all actions taken:
| Step | Action | Result |
|------|--------|--------|
| Tools | sops 3.9.4, age 1.2.0 | installed |
| Key | Machine key generated | age1abc...def |
| Key | Backup key generated | age1xyz...uvw (save offline!) |
| Permissions | chmod 600 keys.txt | done |
| Config | .sops.yaml created | 2 keys authorized |
| Git | .gitattributes updated | sopsdiffer configured |
| Git | .gitignore updated | .env* ignored |
| Encrypt | .env.local → .env.local.enc.yaml | done |
## Next Steps
- Commit .sops.yaml, .gitattributes, and *.enc.yaml files to git
- On another machine: clone, install sops+age, place age key, run /devtools:sops-decrypt
- To add another machine: /devtools:sops-add-key
- To encrypt after editing .env: /devtools:sops-encrypt
- To decrypt after pulling: /devtools:sops-decrypt
Key Rules
- Never overwrite existing files without asking. Always offer merge/replace/skip.
- Detect first — skip steps that are already configured.
- Use
AskUserQuestion for every decision. Do not assume user preferences.
- YAML format only — never use
--input-type dotenv. Use the dotenv_yaml.py helper for conversion.
- chmod 600 on age key files immediately after creation.
- Display public keys after generation — user needs them for multi-machine setup.
- Verify after each step — re-run relevant checks to confirm success.
References