Scaffold a new dotfiles-core overlay or extend an existing one. Use when the user types /overlay-init, asks to 'create an overlay', 'scaffold an overlay', 'set up a new overlay', 'add an overlay skill', 'configure my overlay', or 'add an overlay fragment'. Bare invocation scaffolds; add-skill / add-fragment / add-context configure.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Overlay Init?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/flopperj-overlay-init)
---
name: overlay-init
description: "Scaffold a new dotfiles-core overlay or extend an existing one. Use when the user types /overlay-init, asks to 'create an overlay', 'scaffold an overlay', 'set up a new overlay', 'add an overlay skill', 'configure my overlay', or 'add an overlay fragment'. Bare invocation scaffolds; add-skill / add-fragment / add-context configure."
user-invocable: true
---
# overlay-init — Overlay Scaffold & Configuration Skill
Scaffold a new dotfiles-core overlay from scratch, or extend an existing one
by adding skills, skill-fragments, or overlay-context sections.
---
## Step 1 — Parse subcommand and detect context
Determine mode from the arguments passed:
- If args begin with `add-skill`, `add-fragment`, or `add-context` → **configure mode**
(requires an existing overlay; refuses otherwise — see gate rules).
- All other invocations → **scaffold mode**.
**Overlay context detection** (same check as `/core-edit`):
```bash
git rev-parse --show-toplevel
```
Confirm two conditions:
1. The toplevel has `.gitmodules` referencing `dotfiles-core`.
2. `.claude/dotfiles-core/.git` exists (submodule initialized).
If both conditions pass → running inside an overlay. If either fails → not in an overlay.
**Configure mode with no overlay context:** refuse immediately:
```
ERROR: This subcommand requires an overlay context.
Current directory does not appear to be inside an overlay repo.
add-skill runs only in a git checkout of an overlay whose .claude/dotfiles-core is initialized; anywhere else it stops at /overlay-init Step 1 and changes nothing. Core does not script getting a skill into a home by any other route.
To scaffold a new overlay instead, run bare /overlay-init.
```
---
## Step 2 — Scaffold route (bare invocation)
Prompt for the two required values if not already supplied as arguments:
- **Target directory** — where to scaffold the overlay (default: `~/dotfiles`)
- **Overlay name** — human-readable name used in README and commit messages
(default: basename of the target directory)
Optional flags passed through to the engine:
- `--force` — overwrite a non-empty target dir instead of refusing
- `--core-url <url>` — explicit submodule URL (required when core's `origin` is a local path)
Locate the core engine. The engine lives at:
```bash
CORE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
ENGINE="$CORE_DIR/scripts/new-overlay.sh"
```
Invoke the engine:
```bash
bash "$ENGINE" "<target>" "<overlay-name>" [--force] [--core-url <url>]
```
**Surface the engine's output verbatim** — this includes the next-step command block
and the `--check` result printed by the engine.
**Reasoning layer added by this skill (not the engine):** if `--check` exits non-zero,
explain to the user the two most likely causes:
1. The submodule was not cloned with `--recurse-submodules`, so
`.claude/dotfiles-core/` is an empty dir without a valid HEAD.
Remedy: `git submodule update --init --recursive` inside the new overlay dir.
2. The install state that `--check` validates is the *current* `~/.claude` install,
not the freshly-scaffolded dir in isolation. A failure here means the existing
dotfiles install has a broken symlink or missing tool — not that the scaffold
itself is broken. Remedy: run `bash <target>/install.sh` once the overlay is
fully set up (after commit + push).
Do NOT auto-fix beyond what the engine did. Surface the failure and stop.
---
## Step 3 — add-skill route (overlay-local)
Usage: `/overlay-init add-skill <name>`
Refuse if not in an overlay (Step 1 gate). Run each command below from
inside the overlay's checkout; each finds the overlay's root itself, so it
works as a separate command. Choose the route by `<name>` before writing
anything, and take only that route: Step 3a for `dotfiles-sync`, Step 3b
for any other name.
### Step 3a — `add-skill dotfiles-sync`
dotfiles-core ships no sync skill; an overlay owns its own, written from
core's template by core's script:
```bash
root="$(git rev-parse --show-toplevel 2>/dev/null)"
engine="$root/.claude/dotfiles-core/scripts/add-sync-skill.sh"
if [ -z "$root" ]; then
echo "ERROR: not inside a git checkout of the overlay; add-skill runs only in one (see /overlay-init Step 1)."
elif ! grep -qs dotfiles-core "$root/.gitmodules" || [ ! -e "$root/.claude/dotfiles-core/.git" ]; then
echo "ERROR: this git checkout is not an overlay with an initialized .claude/dotfiles-core; add-skill runs only in one (see /overlay-init Step 1), and nothing was written."
elif [ -f "$engine" ]; then
bash "$engine" "$root"
else
echo "ERROR: .claude/dotfiles-core/scripts/add-sync-skill.sh is missing; move .claude/dotfiles-core to a release that ships it."
fi
```
Read the first word of the output:
- `ERROR:` — report the line and stop. Write nothing yourself.
- `FORMER:` — the overlay's skill is an unchanged copy of the
`dotfiles-sync` skill an older dotfiles-core shipped, which discards local
changes without asking. Show the line and ask whether to replace it. Only
if the user says yes, run this and read its output the same way. If the
user says no, stop and change nothing.
```bash
root="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -n "$root" ] && [ -f "$root/.claude/dotfiles-core/scripts/add-sync-skill.sh" ]; then
bash "$root/.claude/dotfiles-core/scripts/add-sync-skill.sh" "$root" --replace
else
echo "ERROR: not inside a checkout of the overlay, or .claude/dotfiles-core/scripts/add-sync-skill.sh is missing; nothing was replaced."
fi
```
- `Created` or `Replaced` — confirm:
```
<the script's line>
Next:
1. Add these routing rows to the overlay's CLAUDE.md fragments (claude-md.d/):
| **Sync, ...** | `/dotfiles-sync` | Check for dotfiles updates, preview changes, pull and re-run install.sh |
| "update my dotfiles", "sync dotfiles", "pull latest dotfiles", "are my dotfiles up to date" | `/dotfiles-sync` | Check for dotfiles updates, preview changes, pull and re-run install.sh |
2. If the overlay ships .claude/_shared/overlay-owned-paths.txt, add the line .claude/skills/dotfiles-sync
3. Commit it.
4. In a yadm-managed home with an untracked ~/.claude/skills/dotfiles-sync (core's link or a real folder), move it out of ~/.claude/skills before pulling this commit; git can refuse the pull while it is there. Do both by hand before running /dotfiles-sync in that home.
```
### Step 3b — any other `<name>`
Replace `<name>` in the block, then run it:
```bash
root="$(git rev-parse --show-toplevel 2>/dev/null)"
rel=".claude/skills/<name>"
dir="$root/$rel"
if [ -z "$root" ]; then
echo "ERROR: not inside a git checkout of the overlay; add-skill runs only in one (see /overlay-init Step 1)."
elif ! grep -qs dotfiles-core "$root/.gitmodules" || [ ! -e "$root/.claude/dotfiles-core/.git" ]; then
echo "ERROR: this git checkout is not an overlay with an initialized .claude/dotfiles-core; add-skill runs only in one (see /overlay-init Step 1), and nothing was written."
elif [ -L "$root/.claude" ] || [ -L "$root/.claude/skills" ]; then
echo "ERROR: .claude or .claude/skills is a symlink, so a skill written there would land outside the overlay; make it a real directory and run add-skill again."
elif [ -e "$dir/SKILL.md" ] || [ -L "$dir/SKILL.md" ] || [ -L "$dir" ]; then
echo "ERROR: $rel/SKILL.md already exists or the path is a symlink; edit it instead."
elif mkdir -p "$dir" && printf '%s\n' '---' 'name: <name>' 'description: "<name> — describe what this skill does and when to invoke it."' 'user-invocable: true' '---' '' '# <name>' '' 'TODO: Document this skill.' > "$dir/SKILL.md" && [ -f "$dir/SKILL.md" ]; then
echo "Created overlay skill: $rel/SKILL.md"
else
echo "ERROR: could not write $rel/SKILL.md."
fi
```
On `ERROR:`, report it and stop. On `Created`, confirm:
```
Created overlay skill: .claude/skills/<name>/SKILL.md
Next: edit the description and body, then commit it.
```
This is purely overlay-local: it writes only inside the overlay's own .claude/skills.
---
## Step 4 — add-fragment route (overlay-local)
Usage: `/overlay-init add-fragment <core-skill>`
Refuse if not in an overlay (Step 1 gate).
Create the fragment directory:
```bash
mkdir -p ".claude/skill-fragments/<core-skill>"
```
Append a complete, valid entry to `.claude/overlay-fragments.yaml`. The entry
must match the exact schema that `apply_manifest` parses (name / target / source):
```yaml
- name: <core-skill>-overlay-ext
target: ~/.claude/skills/<core-skill>/SKILL.md
source: .claude/skill-fragments/<core-skill>/ext.md
```
A half-entry must never be written. If the manifest does not yet exist, create it
with the empty manifest header first:
```yaml
fragments: []
```
Then append the entry. If it does exist, append after the last entry.
Confirm to the user:
```
Created fragment dir: .claude/skill-fragments/<core-skill>/
Appended entry to: .claude/overlay-fragments.yaml
name: <core-skill>-overlay-ext
target: ~/.claude/skills/<core-skill>/SKILL.md
source: .claude/skill-fragments/<core-skill>/ext.md
Next: write the fragment content to ext.md, then run install-overlay.sh.
```
If the manifest-append logic grows beyond a few lines, extract it into a
focused helper in `scripts/` and add bats coverage for that helper.
---
## Step 5 — add-context route (THE CENTERPIECE — bilateral contract)
Usage: `/overlay-init add-context <Section>`
This is the fully decidable bilateral contract operation. `<Section>` is the
exact heading name (e.g., `Jenkins MCP clone URL`).
Refuse if not in an overlay (Step 1 gate).
### 5a — Write the overlay half
Append a stub section to the overlay's `overlay-context.md`:
```markdown
## <Section>
TODO: Fill in your overlay-specific context for this section.
```
**Known section: `## Repo registry`.** If `<Section>` is `Repo registry`, the
section has a canonical machine-parsed format — it is the name→checkout oracle
read by `.claude/skills/ticket-pickup/scripts/repo-registry.sh` — so write real
entries in this shape instead of the TODO stub:
```markdown
## Repo registry
- example-web: /Users/me/Development/example-web | components=Web UI,Editor | prefixes=web/js/,src/ | depends_on=example-api
- example-api: /Users/me/Development/example-api
```
Grammar: entries are `- <name>: <absolute-path>` optionally followed by
pipe-separated `key=value` fields (`components`, `prefixes`, `depends_on`;
comma-split lists). Unknown keys are ignored with a stderr warning. Paths
must be absolute. Duplicate names resolve first-wins with a stderr warning
naming the ignored later entry — keep names unique.
### 5b — Verify the overlay half is present
Confirm the section heading now exists:
```bash
grep -Fxq "## <Section>" .claude/overlay-context.md
```
If absent, report the failure and stop.
### 5c — Check for the core-side gap
The bilateral contract requires two artifacts on the core side. Check them
using the same method the linters use:
**Artifact 1 — vocabulary entry:**
```bash
grep -Fxq "## <Section>" <core>/scripts/consult-vocabulary.txt
```
Reports: PRESENT or MISSING.
**Artifact 2 — core SKILL.md consult-instruction:**
Check whether any core SKILL.md contains a well-formed consult-instruction for
this section. The well-formed grammar is defined in PROTOCOL.md §Grammar. The
section name is the only variable component; the file path is fixed.
```bash
# The grammar requires the full form — section name AND the fixed trailing
# path. See scripts/check-consult-grammar.sh ~line 52 for the authoritative
# regex. Matching section name alone gives a false "PRESENT" when the
# trailing path is absent (make check-consult-grammar would still reject it).
SUFFIX='in `~/.claude/overlay-context.md`'
grep -rlE "consult \`## <Section>\` $SUFFIX" <core>/.claude/skills/*/SKILL.md 2>/dev/null
```
Reports: which core skill file contains it, or MISSING.
### 5d — Route core-side changes to /core-edit
Print the following TODO block verbatim, substituting `<Section>` with the
actual section name and `<core>` with the resolved core path:
```
add-context: wrote overlay half
## <Section> -> .claude/overlay-context.md [DONE]
CORE SIDE REQUIRED — use /core-edit to land both of these:
1. Add this line to <core>/scripts/consult-vocabulary.txt:
## <Section>
2. Add a consult-instruction to the relevant core SKILL.md.
The exact grammar is defined in PROTOCOL.md §Grammar:
consult `## <Section>` in
`~/.claude/overlay-context.md`
(That two-line representation is for readability; the actual
consult-instruction must appear on a single line in the core SKILL.md.)
Until both artifacts are present in core, `make check-consult-grammar`
(core) and the overlay's scripts/lint-consult-blocks.sh will report
## <Section> as an orphan.
```
Do NOT auto-edit core. Do NOT auto-commit. Route only.
### 5e — Optional: run the overlay's orphan linter
If `scripts/lint-consult-blocks.sh` exists in the overlay, offer to run it:
```
Offer: Run scripts/lint-consult-blocks.sh to see ## <Section> flagged as
an orphan? This confirms the core side is still missing. [y/n]
```
If the script is absent, skip this offer silently.
---
## Gate rules
- **Never auto-edit or auto-commit core.** The `add-context` route prints a TODO
and routes to `/core-edit`; it never touches core files directly.
- **Configure routes refuse outside an overlay.** All three configure subcommands
(`add-skill`, `add-fragment`, `add-context`) require overlay context (Step 1
gate). Fail loudly with the refusal from Step 1.
- **Scaffold never commits.** The engine stages files (`git add -A`) but does not
commit. Never add a commit step to the scaffold route.
- **`add-context` always prints the core-side TODO** — even if both artifacts are
already present in core (in that case, prefix with "Core side already wired:"
and confirm both checks pass instead of marking them MISSING).
- **Never write a half-entry to overlay-fragments.yaml.** The `add-fragment` route
either writes a complete `name`/`target`/`source` entry or writes nothing.
- **`add-skill` replaces a `SKILL.md` only with consent.** It never replaces
one unless it is an unchanged copy of a former dotfiles-core release's
skill and the user agreed, and then only after moving the old copy to the
backup store.