env-sync
Skill0 starsChanged 49 days agoMITView on GitHub
Make every `.env*` file consistent by aligning it to the `.env.example` reference, line for line: each variable sits on the same line number in every file, comments and blank lines match byte-for-byte, every current value is preserved, and the operator gets a side-by-side comparison. Use when the user invokes @env-sync, says "make .env files consistent", "align the env files", "sync .env vars", "compare .env files side by side", "env drift", or asks to reconcile `.env`, `.env.dev`, `.env.prd` with `.env.example`. Backed by `scripts/env-sync.sh` (`status` / `verify` / `apply`).
- Reads credentials
3 other projects use a version of this.
Adopted by
Most recently taken up by
- qiaoshouqing/skillstheir own version, first seen Oct 13, 2026
- ieeecsopen/mcp-cstheir own version, first seen Aug 27, 2026
- FPVE-Webdev/claude-skillstheir own version, first seen Aug 17, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- ieeecsopen/mcp-cs★ 3same name
- qiaoshouqing/skills★ 1same name
- FPVE-Webdev/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- ai-directorSkill
- cicd-githubSkill
- code-implementationSkill
- code-repairSkill
- code-verifySkill
- concept-runSkill
- db-migrationSkill
- deploy-basicSkill
- deploy-filesSkill
- dev-stackSkill
- docsSkill
- feature-specSkill
- infra-terraformSkill
- plan-foundationSkill
- plan-masterSkill
- plan-repairSkill
- plan-syncSkill
- plan-verifySkill
- process-routerSkill
- project-bootstrapSkill
- project-query-setupSkill
- session-controlSkill
- tauri-developmentSkill
- x-directorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 3 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Keep every .env* file in one canonical line layout without ever touching a value.
- Distinctive: line 34
The reference layout is exact, comments included: Every non-key line (comment or blank) must be byte-identical at the same line number in …
- Very specific: line 39
Put comments that must exist in every file in .env.example.
- Very specific: line 49
Back up before writing: Default backup dir is outside the repo ($TMPDIR/env-sync-backup.*, mode 700, copies keep the original mode).
- Very specific: line 65
Operator handoff: every response that ends a turn follows the Operator handoff contract — terse output.
- Very specific: line 95
Run from the project root (or pass --dir):
- Very specific: line 119
Run env-sync.sh status (add --dir when the user named a path).
- Very specific: line 153
Run status first and read the file/issue rows.
- Distinctive: line 154
If the reference itself is invalid, stop with the blocked shape — do not guess a layout.
- Very specific: line 156
If a target is invalid (duplicate key, multiline value, CRLF, unparsable line), stop with the exact path:L<n> and the fix.
- Very specific: line 159
If status reports undeclared keys (present in a target, absent from the reference), stop before apply.
- Very specific: line 163
If status reports layout drift (comments, blank lines, or line count differ), that is normal after the reference changed: apply regenerates …
- Very specific: line 170
If the operator has not seen the drift yet, show the summary counts (missing / misplaced / layout / undeclared) and, when the change is …
- Very specific: line 242
Use verify in CI after apply.
- Distinctive: line 249
When the skill stops before writing:
- Very specific: line 260
When apply fails and restores, say FAIL (restored) and cite the backup path.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
env-sync
Keep every .env* file in one canonical line layout without ever touching a
value. .env.example is the layout authority — one reference, many target
files, identical line numbers for keys and comments/blank lines, and a
side-by-side comparison the operator can read without exposing secrets.
Tool-agnostic (Cursor, Claude Code, opencode, Codex, DSH). Pairs with:
dev-stack (.env creation), session-control (repo hygiene), project
.gitignore / protected-file rules.
Canonical path: .ai/skills/env-sync/skill.md · Detailed contract, exit
codes, test recipe: reference.md
Hard rules:
- Values are immutable.
applyreorders/inserts/pads lines only. It never rewrites the text after=and never edits the reference file. Before and after every write, SHA-256 fingerprints of every key value must match; a mismatch aborts and restores the backups. - The reference layout is exact, comments included. Every non-key line
(comment or blank) must be byte-identical at the same line number in every
target, and every file must have the reference's exact line count. Comment,
blank-line, or line-count drift is real drift:
statusshowslayout:N,verifyfails, andapplyrewrites the target from the reference skeleton. Put comments that must exist in every file in.env.example; target-only comments are not preserved when a rewrite is needed. - Never print or read values into chat. No
cat,source, or value diff.status/verifyreport line numbers,set/empty,layoutcounts, and same/diff fingerprints only..cursorrules§ Data Privacy applies. - Missing key → empty assignment (
KEY=) on its canonical line (operator decision 2026-11-10). Every reference key is present in every file, so the layout is greppable and strictly aligned. Caveat: this can change runtime semantics from unset to empty;applybacks up first and is the only writer, and existing values are still never modified. - Back up before writing. Default backup dir is outside the repo
(
$TMPDIR/env-sync-backup.*, mode 700, copies keep the original mode). Use--backup-dirwhen the operator needs the backup to survive a reboot. - Fail closed, never guess. Refuse (no writes) on a broken reference, duplicate keys, multiline/continued values, unparsable lines, or CRLF input. Report the exact line and stop.
- The reference owns the key set and the comments. A key present in any
target but absent from
.env.exampleis a hard error:applyaborts,status/verifyreport it. Add it to.env.examplefirst, with a comment explaining where it is enabled or disabled (environment-only keys must exist in every file, empty where unused). Together with the exact-layout rule, this guarantees identical line counts, identical key-to-line maps, and identical comment/blank lines in every file — no trailing extras block. status/verifyare read-only.applyis the only writer and is itself the same-message permission to modify.env*files (which are protected files). Never rewrite.env*outside an explicitapplyinvocation.- Operator handoff: every response that ends a turn follows the Operator
handoff contract — terse
output; approvals under
**Needs your approval:**citingpath:L<n>; questions numbered under**Needs your answer:**; exactly one**Next step:**; one line when nothing is needed (Form A). Decisions and questions never mixed; empty sections omitted.
Parse invocation
Normalize the user message to verb + optional directory.
| User says | Verb | Action |
@env-sync status · compare · diff | status | Status protocol — read-only side-by-side table |
@env-sync verify · check | verify | Verify protocol — strict pass/fail, exit 1 on drift |
@env-sync apply · sync · fix | apply | Apply protocol — backup, rewrite layout, verify |
@env-sync apply --dry-run | apply | Plan only; report what would change, write nothing |
@env-sync (no verb) | status | Default to the read-only comparison |
Target: an optional path after the verb (@env-sync status - /path/to/project)
becomes --dir /path/to/project. Without it, use the current repository root.
Aliases: compare/diff → status; check → verify; sync/fix → apply.
Step 0 — Resolve the script and modes
Run from the project root (or pass --dir):
# fat-client / self-hosted (self-hosted alias: .ai/scripts → scripts/)
bash .ai/scripts/env-sync.sh <verb> [--dir PATH]
# thin-client (no local .ai/): use the framework source
bash "${AGENT_OS_SOURCE}/scripts/env-sync.sh" <verb> [--dir PATH]| Mode | Writes | Use when |
status | nothing | Operator wants the side-by-side picture; first step of any invocation |
verify | nothing | CI/pre-commit gate, or after apply |
apply | target .env* files | Operator asked to make the files consistent |
Exit codes: 0 pass, 1 drift (keys or layout), aborted, or restored, 2
usage or reference error. status exits 0 even when the table shows drift —
use verify for a gate.
Status protocol
- Run
env-sync.sh status(add--dirwhen the user named a path). - Report the return code; do not paste the table if it is huge — summarize the file rows and link/copy the table.
- Explain the column legend once (it is in
reference.md):
| Cell | Meaning |
ok:N | key is on canonical line N |
at:N | key exists but sits on line N (must move) |
-- | key is not set in that file (drift; apply materializes KEY=) |
set / empty | value is non-empty / empty — the value itself is never shown |
VALUES same/diff/n/a | value fingerprints across files that have the key |
Per-file summary rows add layout:N: the number of comment/blank-line
mismatches plus the absolute line-count difference against the reference.
ALIGNED requires layout 0 as well as missing 0, misplaced 0, and
undeclared 0; anything else is DRIFT.
- Flag anything that needs a decision: missing keys (they become
KEY=on apply), undeclared keys (must be promoted into.env.examplewith a comment first), layout drift (comments/blank lines/line count differ; apply rewrites from the reference), and anyINVALIDfile. Do not propose value edits.
Apply protocol
Order: A1 preflight → A2 review/dry-run → A3 backup + apply → A4 verify → A5 backup proof → A6 report.
A1 — Preflight (mandatory)
- Confirm the reference exists (
.env.exampleunless--ref). - Run
statusfirst and read the file/issue rows. - If the reference itself is invalid, stop with the blocked shape — do not guess a layout.
- If a target is invalid (duplicate key, multiline value, CRLF, unparsable
line), stop with the exact
path:L<n>and the fix. Do not edit the file to make it parse unless the operator asked for that separately. - If
statusreports undeclared keys (present in a target, absent from the reference), stop beforeapply. Add each key to.env.examplewith a comment explaining where it is enabled/disabled, then re-run. Never accept a trailing extras block: line counts and key lines must stay identical. - If
statusreports layout drift (comments, blank lines, or line count differ), that is normal after the reference changed:applyregenerates those lines from.env.example. If a target has a custom comment that must survive, move it into.env.examplefirst — the reference owns comments.
A2 — Review gate
- If the operator has not seen the drift yet, show the summary counts
(
missing/misplaced/layout/undeclared) and, when the change is non-trivial, runapply --dry-runfirst (no writes). apply --dry-runis safe: it validates and prints per-file counts only.
A3 — Backup + apply
bash .ai/scripts/env-sync.sh apply --dir <path> --backup-dir <persistent-dir>- Omit
--backup-dirto use the OS temp dir; pass one under the project's git-ignoredtmp/when the backup must survive (never under version control; backups contain the original secrets). - Apply is idempotent: an already-aligned file (keys and full layout) is skipped and reported as such; a second run writes nothing.
A4 — Verify (mandatory)
bash .ai/scripts/env-sync.sh verify --dir <path>verify now checks the full 1-to-1 contract: key lines, comments, blank lines,
and line count. If it fails after a successful apply, treat the apply as failed:
report the file, the layout count, the backup path, and the restore command
(cp -p <backup>/<file> <dir>/<file>). The script already restores
automatically on its own post-write mismatch.
A5 — Backup proof
bash .ai/scripts/env-sync.sh verify --backup <backup-dir> --dir <path>This compares each backup to the current file key-by-key and confirms values are unchanged and the layout is aligned. Include the result in the report.
A6 — Report
## env-sync applied - <project>
**Directory:** <path> · **Reference:** .env.example (<N> keys, <L> lines)
**Result:** PASS | FAIL (restored)
**Layout:** <L> lines (comments included), <N> keys - identical in every file
| File | Before | After | Values |
|------|--------|-------|--------|
| .env.dev | missing 10, misplaced 48, layout 6 | aligned (10 empty, layout 0) | 51 unchanged |
| .env.prd | missing 7, misplaced 51, layout 4 | aligned (7 empty, layout 0) | 54 unchanged |
**Undeclared keys:** none (the reference owns the key set and comments)
**Backup:** <path> (mode 600 copies, 700 dir)
**Proof:** `verify` PASS (layout 0); `verify --backup` PASSEnd with the Operator handoff close per the contract.
Verify protocol
env-sync.sh verify [--dir PATH]— strict 1-to-1 check: key lines, comments, blank lines, and line count.env-sync.sh verify --backup DIR [--dir PATH]— prove the values in the current files match the pre-apply backup (the audit mode), and the layout is aligned.- Report per-file
ALIGNED/DRIFT(withmissing/misplaced/layout/undeclared) plus theverify: PASS|FAILline. Exit1on any drift or invalid input; surface that code, do not hide it.
Use verify in CI after apply; status remains the human comparison view.
layout 0 is mandatory for ALIGNED — a comment-only difference is a failure.
Blocked / failure shape
When the skill stops before writing:
## @env-sync <verb> - blocked
**Required:** <valid reference | parseable target | LF endings>
**Detected:** <path:L<n> — <issue>>
**Run first:** `<exact command>` (or fix the line above)
**Wrote:** nothingWhen apply fails and restores, say FAIL (restored) and cite the backup path;
never claim success from a partial layout.
Anti-patterns
- Editing a value (or an
.env.exampleplaceholder) to make files "match". - Printing raw values,
cat-ing.env*,source-ing them, or diffing values. - Editing or reflowing comments in a target and expecting them to survive — put shared comments in
.env.example, the reference owns the comment layout. - Adding comment lines to a target to "make the line numbers match" without copying the reference text;
layoutdrift will (correctly) failverify. - Leaving a key absent from a file when the operator asked for a full layout — apply materializes
KEY=. - Running
applywithout a backup or without a post-writeverify. - Expecting
applyto rewrite.env.example(it never does) or adding an environment-only key to a target without promoting it to the reference first. - Leaving a target-only key out of
.env.example, or accepting an extras block that breaks the identical line count. - Continuing after a
duplicate/multiline/CRLFfinding. - Claiming aligned without
verifyoutput as evidence, or claiming aligned whilelayout > 0.
Integration
| Situation | Use |
New .env from .env.example | Create it, then @env-sync apply to align |
.env.dev / .env.prd drift after adding a variable or comment | @env-sync status → apply → verify |
| Pre-commit / CI env gate | @env-sync verify (exit 1 blocks) |
| Suspect a bad apply | @env-sync verify --backup <dir> |
dev-stack init-env produced files | @env-sync status before starting the stack |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

