sync(places, host, options?) runs one sync. It fetches every source in the plan, links their skills and files into each agent's folders, merges their MCP servers and hooks into each agent's config, runs the plan's hooks, and returns a report.
import { sync } from "skillrc/sync";
const report = await sync(places, host);
if (!report.ok) console.error(report.errors.join("\n"));skillrc doesn't read your program's config. host does: it loads the plan, says where each agent keeps its skills, and names the command your users run. The engine does the rest.
The plan
Section titled "The plan"A Plan is the list of sources to sync, read from your program's config. Your program parses its own format and builds one.
import type { GitSource, LocalSource, Plan } from "skillrc/sync";
const file = "/home/me/.config/mytool/mytool.json";
const team: GitSource = {
kind: "git",
id: "team",
git: "https://github.com/acme/skills.git",
skills: "skills/*",
update: "auto",
origin: file,
};
const mine: LocalSource = {
kind: "local",
id: "mine",
local: "/home/me/skills",
adopt: false,
update: "auto",
origin: file,
};
const plan: Plan = {
root: { file, agents: "all", sources: [team, mine], forks: {}, hooks: [] },
sources: [team, mine],
warnings: [],
};root is what the user's own file says. sources is every source the sync runs: the root's first, then those of any file the root extends. failed lists extended files that didn't load; while it is set, sources missing from the plan keep what they last linked instead of being removed.
Sources
Section titled "Sources"| Kind | Field | What it is |
|---|---|---|
git | git, ref? | A repository skillrc keeps a copy of, fetched through the git cache |
npm | npm, registry? | A package from a registry, unpacked into the store |
index | index | A site that serves /.well-known/agent-skills/index.json |
clone | git, ref?, path | A repository you work in, updated by fetch and fast-forward and linked in place |
local | local | A folder on this machine, linked in place |
git, npm and index sources are vendored: their skills are copied into <state>/store/<id> and linked from there. clone and local sources are linked where they are, so an edit shows in every agent at once.
Every source has an id, an update mode and the origin file that declared it. The rest is optional:
| Field | What it does |
|---|---|
skills | A glob of skill folders inside the source, such as skills/* |
include, exclude | Skill names to keep or drop |
files | Instructions, subagents, commands, mcp and agentHooks files the source gives agents, as a glob per agent id |
update | "auto" applies upstream changes; "review" holds them until a sync passes apply with this source's id |
Only the root plan's sources may give mcp and agentHooks files, since an MCP server or a hook runs a command. See Definitions.
Two sources with a skill of the same name: the first one wins, and the report lists the other under shadowed. Names that differ only in case or Unicode form count as one, since macOS and Windows keep them in one folder.
Hooks in the plan
Section titled "Hooks in the plan"A plan hook runs a shell command after a sync changed files that match its patterns. Each pattern is <source id>:<glob>, or *:<glob> for any source.
const hooks = [{ name: "reindex", run: "mytool-index", on: ["team:skills/**"] }];The command gets the report as JSON on stdin, <PROGRAM>_HOOK with the hook's name and <PROGRAM>_CHANGED with the matched <source>:<file> lines. It is stopped after 5 minutes, and a non-zero exit is an error in the report. A sync stopped before its hooks ran leaves them due, and the next sync runs them.
The host
Section titled "The host"SyncHost is everything the engine asks of your program.
| Member | What it does |
|---|---|
load(ctx) | Reads the plan and returns { plan, name }. It runs inside the lock. name is what the report's manifest says. Throw to stop the sync. |
targets(agents, signal) | The global skills folders the plan's agents read, as { dir, agents, aliases? } |
formerTargets(targets) | Folders that are no longer targets, where links made earlier may remain |
replacementTargets?(targets) | For each former folder, the targets that took its place |
kinds | Where each agent reads instructions, subagents, commands, MCP servers and hooks, by agent id |
notes?(plan, state) | Warnings a real sync adds, such as a timer whose schedule drifted |
hookEnv?(hook, changed) | More variables for a plan hook's command |
beforeReport?(plan, signal) | Runs under the lock, after the hooks and before the report is saved and sent |
command | The command messages tell the user to run, such as mytool |
version | Your program's version, written into the report |
load gets offline, dryRun, signal, warnings to push to, only when one source was asked for, and cacheRoot in a dry run. Fetch any remote file the plan extends into cacheRoot then, so the real cache doesn't move.
Skills folders are found by the agents. An agent with no entry in kinds still gets its skills, but no files, servers or hooks.
const host: SyncHost = {
load: async () => ({ plan, name: file }),
targets: async () => [
{ dir: "/home/me/.claude/skills", agents: ["claude-code"] },
{ dir: "/home/me/.agents/skills", agents: ["codex", "opencode"] },
],
formerTargets: () => [],
kinds: {
codex: {
home: () => "/home/me/.codex",
mcp: { file: () => "/home/me/.codex/config.toml", format: "toml", key: ["mcp_servers"] },
},
},
command: "mytool",
version: "1.0.0",
};What a sync does
Section titled "What a sync does"- Takes the sync lock,
<state>/sync.lock. Another live sync makes it throwLockHeldError; a stale lock is broken and the report says why. - Calls
host.loadand readsstate.json. - Fetches each source in order, and saves the state after each one. A sync stopped later leaves nothing in the store that
state.jsondoesn't record. - Links each winning skill into every target folder. A folder that can't be written doesn't stop the others.
- Removes links it made in former folders, and keeps a skill there while a folder that replaced it has no usable copy.
- Links instructions, subagents and commands, then merges MCP servers and hooks into each agent's config.
- Saves the state, runs the plan's hooks, calls
beforeReport, and writes<state>/last-run.json. - Runs the plan's
report.runcommand with the report on stdin, and posts the report tohubwhen the plan names one.
A whole sync is stopped after 60 minutes. The error names the step it was on.
Options
Section titled "Options"| Option | What it does |
|---|---|
dryRun | Reports what the sync would do and writes nothing |
offline | Fetches nothing and syncs from what is on disk |
only | Fetches only this source; the others link from disk |
apply | Applies the held updates of this review source |
copy | Copies skills into agents' folders instead of linking them |
copy is for agents that skip a skill whose SKILL.md is a symlink. Codex and Cursor do. A copy that someone edits counts as an edit of the skill: the next sync moves the change back to where the skill came from.
Dry run
Section titled "Dry run"const preview = await sync(places, host, { dryRun: true });
console.log(preview.skills.added, preview.skills.removed);A dry run takes no lock and writes nothing outside a scratch folder. It fetches into a temporary cache, so the real cache never moves past what was synced. With offline too, it reads the real cache instead, since a scratch one would be empty.
It fails where the real run would. A source that can't be fetched is an error in both. Where the preview can't model a change in full, such as an edited copy that a real sync would move back first, previewLimitations in the report says so.
The report
Section titled "The report"sync returns a Report, and a real sync also writes it to <state>/last-run.json.
| Field | What it holds |
|---|---|
ok | No errors |
sources | Each source's status: installed, updated, unchanged, held, review, error or offline |
skills | total, names, and what was added, removed and updated |
files | Files linked into agents' folders, and those left alone because a person made them |
entries | MCP servers and hooks merged, held because someone edited them, or skipped because the file was locked |
pending | Updates not applied: waiting for review, held for a local edit, or made to a skill you forked |
shadowed, renamed | Skills a former source still had, and skills renamed upstream in case only |
hooks | Each plan hook that ran, its exit code and the end of its output |
warnings, errors | What to tell the user |
errors means something was not synced. warnings means it was, with something to know.
<state>/state.json records what each source last installed: its commit or version, each skill's hashes, the links and the config entries skillrc owns. It is how a sync tells an upstream change from a local edit, and which config entries are its own to change.
import { loadState, saveState } from "skillrc/sync";
const state = loadState(places);
console.log(Object.keys(state.skills));A state.json that doesn't parse, or that another version wrote, reads as empty. A sync then rebuilds what it can from the store, and treats vendored copies it can't vouch for as edited, so nothing local is overwritten. With backupInvalid, the old file is copied to <state>/backup first.
Commands that change the state between syncs, such as a fork or a merge, run under the same lock:
import { withSyncLock } from "skillrc/sync";
await withSyncLock(places, "merge", async () => {
// read state.json, change it, save it
});withSyncLock waits up to 10 seconds for a running sync, then throws a UserError that says to try again. A sync that the command runs inside it shares the lock.