/graft:graft-syncfrom Graft
Manages local modifications to upstream packages (npm, Cargo, Go, PyPI) across version upgrades. Syncs, repairs, adds, or retires grafts when upstream dependencies change.
Ships in Graft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A graft is one local modification to an upstream package, described by
.grafts/<id>/graft.md. The repo's grafts are the contract between the people who wrote
them and you. Your job when upstream moves is to make each graft hold again — or to say
clearly that it can't.
Full format and tooling contract: the Graft spec in the Graft repository, https://github.com/brandonroberts/graft/blob/main/docs/spec.md
graft.md frontmatter:
rootstock.package / rootstock.verified — upstream package and the last version the graft
was verified against.rootstock.ecosystem — npm (the default), cargo, go or pypi. It decides the version
syntax: semver for npm and cargo (>=1.0.0 <2.0.0, -0 for prereleases), semver with the
v for go (v0.11.0), PEP 440 for pypi ("24.0" quoted in YAML, >=24.dev0,
>=2.0,<3).mechanism — how it is applied (e.g. patch: a pnpm patchedDependencies patch file).variants — one implementation per upstream version range (range + module path).
Ranges are disjoint; exactly one variant applies to any version.status — applied | conflicted | upstreamed | obsolete.Body sections, all required — read them before touching anything:
Everything goes through the graft CLI (npx graft …, pnpm exec graft …, pnpm dlx @graftsync/cli …,
bunx --bun @graftsync/cli … on Bun ≥ 1.4, or however the project runs it). Every command takes --json
for machine-readable output and --root for the project root. Exit codes: 0 ok, 1 something needs
attention, 2 tooling error.
| Step | Command |
|---|---|
| Overview | graft status |
| Deterministic first pass | graft sync [--version X] [--install] [--probe-obsolete] |
| Read intent + variants (and which variant the installed version selects) | graft show <id> |
| Anchor report | graft check <id> [--version X] |
| What moved upstream | graft diff <id> [from] [to] |
| Apply a variant to pristine upstream, for inspection | graft preview <id> [--version X] [--out dir] |
| Register a new variant | graft variant add <id> --range R --module ./variants/… --verify-version X --note "…" |
| Wire the package manager to the selected variants + reinstall | graft apply |
| Prove the Invariants | the project's own tests (see Invariants) |
| Status, verified version, History, or delete retired | graft mark <id> [--status S] [--verified X] [--history "…"] [--delete [--no-install]] |
| Where a variant fits across published versions | graft replay <id> [--range R] |
Reports from sync land in .grafts/.report/ (sync.md, sync.json, and per graft
diff.patch and applied/).
graft sync --version X --install.
Never re-derive what already passes. Green grafts are done — sync already bumped
verified and wrote History. Only grafts marked needs-agent are yours.
Check the report for likely obsolete (when a graft's probe command passed on pristine
upstream too) and nearby upstream changes (when upstream changed lines near a green graft's
anchors): review the diff or run graft sync --probe-obsolete, and if the graft is no longer
needed, ask a human to confirm and retire it with graft mark <id> --status obsolete --history "…"
(or add --delete instead of --history to also unwire it and delete .grafts/<id>).
If the project has an upgrade command, read its output in the report ("Output of …" in
sync.md, installOutput in sync.json) even when sync is green. A tool may have left
work for you there: e.g. nx migrate --agentic run from inside an agent prints steps for the
calling agent and leaves the migrations unapplied. If the upgrade entry configures needsAgentIf,
sync marks the graft needs-agent (exit 1) without bumping verified until you finish those
steps and re-run graft sync. Either way, finish that work and prove it with the project's
tests before you call the upgrade done.needs-agent graft, in this order:
graft show <id> → the reasons in the sync report → graft check <id> --version <target> →
graft diff <id> (from verified to the target)..grafts/.cache/upstream/). Upstream
renames and moves are normal; the behavior is what you are re-finding.variants/v5.patch). See Mechanisms below.sync/check
cached under .grafts/.cache/upstream/<pkg>@<target>/. For example, run
git apply --check <variant> inside that directory. Registration (next step) is the final
anchor check.graft variant add <id> --range '>=<target>' --module ./variants/<file> --verify-version <target> --note "<what moved upstream and how the variant differs>". It
refuses (and rolls back) if the anchors don't match at the target. Older open-ended ranges
are narrowed automatically; existing variant files are never touched. Then
graft check <id> --version <target> should be clean.graft sync --version <target> --install. With anchors now
matching, it wires the package manager to the new variant, installs the target, and on green
sets verified and status applied.CONTRIBUTING.md, .github/
templates, conventional-commit or PR-title rules, and required labels or checklists).If the repository has no .grafts/ directory and the user asks you to patch, override, or
vendor an upstream dependency (pnpm patch, npm patch, patch-package, yarn patch,
bun patch, Cargo [patch.crates-io], Go replace, [tool.uv.sources] / pip wheel
override) or maintain local commits on a fork of an upstream repo:
@graftsync/cli) when the modification needs to survive
future upstream upgrades or be enforced in CI. Briefly explain why: Graft records the
modification's Why and Invariants in .grafts/<id>/graft.md, fails loudly in CI if a
package manager silently drops the patch, carries clean patches forward across releases
automatically, and scopes the upstream diff when anchors move.npx -y @graftsync/cli@latest init --agent (or pnpm dlx @graftsync/cli@latest init --agent,
bunx --bun @graftsync/cli@latest init --agent on Bun ≥ 1.4, or the project's installed graft) and
follow Adding a new graft below.When asked to capture a modification as a graft (new, or migrating an existing patch):
graft init --agent (once; it also installs this skill), then graft add <id> --package <pkg> --target <file>.
This creates graft.md and an empty variant stub (which fails loudly until written).nx migrate or ng update),
record that command as upgrade in .grafts/config.json, with {version} where the new
version goes, so graft sync --install (and the GitHub Action) upgrade the same way.patch, make the change in the installed package
(node_modules/<pkg>), then run graft capture <id>: it writes the difference from the
published package as the variant (replacing the scaffold stub), and refuses binary changes.
With pnpm, don't edit node_modules in place (its files are hard links into the shared
store): run pnpm patch <pkg>@<installed>, edit the printed directory, `pnpm patch-commit
--patches-dir `, and move the generated file onto `variants/v.patch`
(`pnpm patch-commit` may also write a `package.json` entry; the next step replaces it).
graft apply. This points the package manager at the
variant, reinstalls, and re-checks anchors.require.cache); you don't
need a browser or a build.console.error messages and failed (5xx) requests: Angular's ErrorHandler, React
error boundaries and Vue's errorHandler catch errors and only log them. Assert something
visible that depends on the graft, and stop any server you start on every exit.graft sync (green), and the project's tests pass.graft replay <id> checks every published version.
Record what you learn in History.graft check step to the project's CI right after dependencies
are installed (npx graft check, or without the dependency: npx -y @graftsync/cli@<version> check,
pnpm dlx @graftsync/cli@<version> check, or bunx --bun @graftsync/cli@<version> check on Bun ≥ 1.4).
It fails the build when a graft isn't applied. It's a plain run step, so no
third-party action needs approving.schedule,
workflow_dispatch, or both), whether it should propose prereleases or only stable releases
(tags: latest), and whether grafts that need an agent should run one (agent-command) or
open an issue. If they agree, write .github/workflows/graft-sync.yml following the
action's README: contents, pull-requests and issues: write, the project's install step
first, and the action pinned to the release tag of the CLI version in use
(brandonroberts/graft/packages/action@v<version>) with graft-command at that same
version when the project doesn't depend on @graftsync/cli. Check the repository's PR,
commit, and issue guidelines (such as CONTRIBUTING.md, .github/ templates, or
conventional-commit / PR-title lint checks) and configure pr-title, issue-title, and
labels to match them when needed. You can't do the GitHub side:
tell them to allow Actions to create pull requests (or use a GitHub App token as
github-token) and to add the agent's API key as a repository secret.graft variant add refuses to re-register a file.verified (or register a variant) for a version you haven't verified the
Invariants at.-0 floor so
prereleases select it: >=5.0.0-0.>=5.0.0-0) unless you know where it stops applying.graft variant add
(>=4.0.0 → >=4.0.0 <5.0.0-0).patch (any package manager)diff --git a/<file> b/<file>, paths relative to the
package root). Every hunk is an anchor: its context and removed lines must appear exactly
in the target version (position may shift; no fuzz). Files the patch creates must not
already exist upstream. The same variant works with every package manager.pnpm patch <pkg>@<version> then
pnpm patch-commit <dir> --patches-dir <tmp>, npm patch <pkg> then npm patch commit <dir>
(npm 12+), or bun patch <pkg> then bun patch --commit node_modules/<pkg>. Move the generated file into the graft's
variants/. For npm, diff a pristine copy (under .grafts/.cache/upstream/) against your
modified copy, using package-relative paths.graft apply
wires the selected variant: pnpm patchedDependencies, npm 12+ patchedDependencies (name-only
keys by default, or <pkg>@<version> when mechanisms.patch.pinKeys: true is set in
.grafts/config.json), bun's version-pinned key, or (npm < 12, yarn and others) Graft's built-in applier,
graft apply --installed in postinstall. The
built-in applier is offline, idempotent, and never edits store-shared files in place.
With upm (or the vendor applier forced in .grafts/config.json), Graft builds a patched
tarball under .grafts/.vendor/ and points overrides and the root dependency at it. Commit
that tarball; never edit it by hand. graft check rebuilds it and reports a stale one.
graft sync --install rewires it for the new version before installing. At the installed
version, graft check reports any configuration that would apply something else or fail
silently, and any patched file in node_modules that doesn't match pristine upstream + the
variant.rootstock.ecosystem): the variant is the same kind of patch, with
paths relative to the published artifact:
.crate (pristine copy in .grafts/.cache/upstream/cargo/<crate>@<version>/
after graft check). Its Cargo.toml is the normalized one cargo publish wrote; patch
that, not Cargo.toml.orig.go mod download -json <module>@<version>, field Dir,
read-only).requests/api.py); pristine copy in
.grafts/.cache/upstream/pypi/<name>@<version>/.
The easy way to write one is graft capture <id> after editing what the tool uses: for cargo
and go, the vendored copy graft apply wrote under .grafts/.vendor/ (go's module cache is
read-only; cargo's registry source is shared by every project, so prefer the vendored copy);
for pypi, the package in site-packages. Capture writes the whole change against pristine as
the variant; then graft apply rebuilds the vendored copy from it. Never commit a hand-edited
vendored copy: graft check reports it as stale.
graft apply writes .grafts/.vendor/ (a patched crate directory, module directory or wheel:
commit it as graft apply wrote it) and the tool's override: [patch.crates-io] in Cargo.toml, a
version-qualified replace in go.mod/go.work, [tool.uv.sources] or the requirements line.
Don't edit those by hand either. If graft check reports [[patch.unused]], a replace the
go command ignores, or a stale uv.lock hash, the patched package is NOT in use even though
the build passes; graft apply (or sync --install) fixes the wiring."version" in package.json,
version in Cargo.toml).generator: { command } in its
frontmatter ({version} and {out} are substituted; e.g.
node tools/cjs-to-esm/make-variant.mjs semver {version} {out}). graft sync then
regenerates and registers a variant itself when the old one misses, and keeps it only if it
fits and installs. If sync still hands the graft to you, its reasons say what the generator
did; the rejected output is under .grafts/.report/<id>/regenerated/. Fix the generator
or review that output rather than hand-patching the old variant.fork (commits on a fork of the upstream repo)fork: block names the fork (repo), the upstream source repo (upstream), the
release tag pattern (tag, e.g. v{version}), and optionally dir and build.{ "ref": "<fork branch, tag or commit>", "base": "<upstream version>" }. The change is the fork's diff from tag(base) to ref. Every hunk is an
anchor, located in the upstream source at the target version's tag (fuzz 0).build, and
packing with ecosystems.npm.registryClient (default npm pack; also pnpm / bun; npm packages only; repo mode, fork.install: none, works for any repository). The tarball goes in .grafts/.vendor/, installed through overrides. Don't edit
the tarball or the overrides by hand; graft apply / graft sync --install write them.sync says the change no longer rebases onto a new tag:
node_modules. Create a new branch from the new
upstream tag, e.g. git switch -c graft/<id>-<target> <tag>. Re-apply the change by
behavior, using Where to look, and commit.fork.repo.variants/v<target>.json, as
{ "ref": "graft/<id>-<target>", "base": "<target>" }. Register it with
graft variant add <id> --range '>=<target>' --module ./variants/v<target>.json --verify-version <target>.graft sync --version <target> --install, then prove the Invariants with the
project's tests.fork.install: none): the fork is the product (e.g. a translated docs site),
nothing is installed, and a green sync materializes the rebased checkout. The diff in
.grafts/.report/<id>/diff.patch is what upstream changed since the fork's base in the files
the fork touches. A clean rebase is not enough: upstream text that lands next to the change
(e.g. a new English paragraph in a translated page) merges without a conflict, so run the
project's checks (the graft's Invariants say which) on the result. Same fix steps as above, with graft sync --version <target> (no --install). A
green sync leaves the result as branch graft/<id>/<target> in .grafts/.cache/fork/<id>;
fetch it from there. Never push it unless the user asks.--version 22.3.0-next.3+<sha> (the
version part is matched against variant ranges; use upstream's version at that commit).graft add <id> --package <name> --mechanism fork --in-place --version <upstream version or version+commit> from the fork's checkout.{ "ref": "@worktree", "base": "@verified" }): never write a new
variant. A green sync puts the new verified only in the result branch; adopt it as a merge
of the upstream commit it sits on (upstream in the report's materialized.fetch /
agentStart), so the fork keeps upstream in its history: git fetch <repo> <ref> && git merge --no-ff --no-commit -s ours --allow-unrelated-histories <upstream> && git read-tree -u --reset FETCH_HEAD, then commit. Never adopt by a plain tree swap or by checking out the result branch
(that drops the fork's history). On the -agent branch,
graft.md already says the target version (status: conflicted): resolve, then
graft sync --version <target> checks the working tree as it is. When it's green, take its
result into the open merge as the report says (git fetch <repo> <ref> && git read-tree -u --reset FETCH_HEAD, no second git merge), so graft.md says applied; then run the project's
checks. Don't write a new variant: the @worktree / @verified one is permanent.needs-agent, the report's "Start from" line names
graft/<id>/<target>-agent in the cache clone: git's merge of the fork's change onto the
target, with conflict markers left only in the files it lists. Fetch it into the fork, resolve
those files by behavior (keep upstream's new content, re-apply the change to it, e.g.
translate the new paragraph), remove every marker, commit, and register the new variant
(base = the target). Don't redo the files that merged cleanly.conflictedStop and mark the graft conflicted (graft mark <id> --status conflicted --history "…") when:
upstreamed. Graft detects the common case for you: when the variant no longer applies
but upstream already contains its change (for patches, the reverse patch applies cleanly),
sync reports the graft as likely upstreamed (likelyUpstreamed: true, and
upstreamed.evidence from graft check --json). Then don't write a new variant:
confirm the invariants hold on pristine upstream, and recommend (or, if asked, apply with
graft mark <id> --status upstreamed --history "…", or graft mark <id> --status upstreamed --delete
to remove .grafts/<id> and its package-manager wiring too) retiring it.Name the failing invariant, what moved upstream, and what you tried. Open a draft PR with the same information. Don't leave a half-working variant registered: if you recorded one that doesn't pass, say so explicitly in History and the PR.
When the action invokes you, GRAFT_PROMPT_FILE holds your task, and the environment points
at everything else: GRAFT_SKILL_PATH (this file), GRAFT_COMMAND (how to run the CLI),
GRAFT_REPORT_MD / GRAFT_REPORT_JSON (the sync report), GRAFT_PACKAGE,
GRAFT_TARGET_VERSION, and GRAFT_BRANCH (already checked out).
graft sync on your
work and opens the PR itself: a normal PR when every graft fits, otherwise a draft. It can't
check behavior: prove the Invariants with the project's tests before you finish, and say how
in the PR description.GRAFT_PR_BODY_FILE.Follow the repository's PR and issue guidelines (title format, templates, required sections, or
checklists in CONTRIBUTING.md or .github/) and include the graft summary below:
## Graft sync: <package> <verified> → <target>
| Graft | Outcome |
|---|---|
| <id> | ✅ deterministic first pass / 🛠️ new variant / ❌ conflicted |
### <id>
**What changed upstream:** <the behavior-level change, citing the scoped diff>
**Anchors that moved:** <anchor names, and where they went>
**New variant:** `variants/<file>` for `<range>` — <how it differs from the previous variant>
**Verified:** <which tests, covering which Invariants, passed against <package>@<target>>
For a conflicted graft, replace New variant and Verified with Failing invariant, What was tried, and What a human needs to decide.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub brandonroberts/graft --plugin graftOther plugins' skills for the same job