CLI
Build, validate, inspect, and manage your design system from the command line.
The Fragments CLI compiles your component metadata — .contract.json files alongside your components — into fragments.json, the structured catalog that powers MCP workflows, the static HTML viewer (npx @usefragments/cli view), and governance checks in CI — over whatever React components you point it at. The Fragments component docs (69 components) are one worked example of the metadata it produces; your own catalog is the real source of truth.
Quick start
Setup is one command: init detects your framework and existing UI library, writes the contract, installs the available agent integrations, and finishes by running doctor — the full walkthrough is in The loop in five minutes. After a local install (npm install -D @usefragments/cli), the short fragments bin is available in package scripts and via npx:
# one-time setup: contract, agent integrations, CI
npx @usefragments/cli init
npx @usefragments/cli build # Compile .contract.json files into fragments.json
npx @usefragments/cli view # Generate a static HTML viewer to browse components
npx @usefragments/cli doctor # Prove the enforcement hook chain is armed
npx @usefragments/cli check --changed --ci # Gate design-system drift in CIConfiguration
init writes a fragments.config.ts file in your project root with the detected app scope, component files, canonical sources, and token sources. The agent hooks and CI workflow it also installs are documented in Agents and Connect the gate.
import type { FragmentsConfig } from '@usefragments/core';
const config: FragmentsConfig = {
app: {
path: '.',
include: [
'**/*.{tsx,jsx}',
'**/*.{scss,css}',
],
},
include: [
'**/*.fragment.ts',
'**/*.fragment.tsx',
'**/*.contract.json',
],
exclude: ['**/node_modules/**'],
Doctor
The agent contract hook is fail-open by design: any error in the hook chain results in a silent allow, never a blocked agent. That is the right trade for your team's workflow, but it means a broken chain looks identical to a healthy one. npx @usefragments/cli doctor is the honest answer to "is it actually working?" — it proves the chain end to end instead of assuming it.
npx @usefragments/cli doctorDoctor runs a battery of configuration checks covering the whole chain. For Claude it checks the hook entries, pinned command and binary, dist freshness, contract and rules resolution, then executes clean and violating synthetic probes (the latter must surface findings). For an installed Codex integration, Doctor checks its config, global prerequisite, pinned binary and freshness, and a SessionStart contract-injection probe; it does not run a Codex violating-write probe. A required check for an installed integration that cannot run is reported as a failure, not assumed healthy. Optional Codex checks are skipped when Fragments has not installed a Codex integration.
Argument / flag | Description | Default |
|---|---|---|
--json | Machine-readable report for scripts and CI dashboards | Not set |
--reset-debounce | Clear the per-session hook debounce state before running checks (useful when the hook seems silent because it already fired for this session) | Not set |
--root <dir> | Project root directory | current directory |
init runs doctor automatically at the end of normal setup, so a fresh install terminates with proof for the integrations it installed. Exit code is non-zero when any required check fails.
Commands
Setup
Initialize and configure a design system project.
Command | Does | Flags |
|---|---|---|
| hook | Install or remove the Fragments contract hook for an AI agent | None |
| hook install | Install the Fragments contract hook for an agent | --agent --mode --scope +1 |
| hook uninstall | Remove Fragments contract hook entries for an agent | --agent --scope --dry-run |
| init | Install local Fragments guardrails, agent hooks, and CI | --token --path --cloud-url +20 |
Authentication
Sign in, inspect the active session, and sign out.
Command | Does | Flags |
|---|---|---|
| auth | Inspect CLI authentication | None |
| auth status | Verify the stored exact-binding OAuth session | --binding --access-token --cloud-url +2 |
| login | Authorize the CLI for one exact Fragments repository binding | --binding --cloud-url --storage +1 |
| logout | Revoke and remove the CLI session for one exact binding | --binding --storage --cwd |
Build & Compile
Compile, validate, and synchronize component metadata.
Command | Does | Flags |
|---|---|---|
| build | Build compiled fragments.json and .fragments/ directory | -c -o --registry +7 |
| scan | Zero-config fragments.json generation from source code | -c -o --patterns +5 |
| validate | Validate fragment files | -c --schema --coverage +6 |
Inspect & Discover
Inspect components, tokens, dependencies, and generated metadata.
Command | Does | Flags |
|---|---|---|
| discover | Propose fragments.manifest.json from the design-system sources | -d --write --json +2 |
| tokens | Design token discovery, listing, and generation | None |
| tokens generate | Generate CSS, SCSS, Tailwind, or Figma output from a DTCG .tokens.json file | --from --format --out +3 |
| tokens list | Discover and list design tokens from CSS/SCSS/DTCG files | -c --json --categories +3 |
Quality & Compliance
Check design-system governance, readiness, and metadata quality.
Command | Does | Flags |
|---|---|---|
| bridges | Manage confirmed package-to-local canonical bridges | None |
| bridges add | Append validated canonical bridge entries to fragments.config.ts | --root -c --from-conflicts +1 |
| check | Check source files for design-system drift | -d -c -f +31 |
| checkpoint | Pin and manage dirty-worktree snapshots for scoped governance | None |
| checkpoint clear | Delete one checkpoint or all checkpoints | --all |
| checkpoint create | Create a named checkpoint of the current worktree | --label --force |
| checkpoint list | List checkpoints and work changed since each snapshot | None |
| codemod | Mechanical source migrations for consumers of the component kit | None |
| codemod ui-vocabulary | Rewrite @usefragments/ui call sites to the ruled prop vocabulary (variant/tone/size/gap/status) | --dry-run --source --json |
| conform | Conform source files to governance policy and prove a clean pass | -d -c -f +19 |
| contract | Edit this repository's Fragments Cloud contract from the terminal | None |
| contract sources | Token source files pinned by the Cloud contract | None |
| contract sources add | Add token source paths (applies when the repository scan already sees them) | --binding --access-token --cloud-url +5 |
| contract sources list | Show the pinned token sources, canonical sources, and pending proposals | --binding --access-token --cloud-url +3 |
| contract sources remove | Remove token source paths that no longer exist (applies immediately for admins) | --binding --access-token --cloud-url +5 |
| contract sources replace | Point a token source at the path the file moved to | --binding --access-token --cloud-url +5 |
| contract undo | Restore the contract an applied edit replaced, while it is still the latest revision | --binding --access-token --cloud-url +3 |
| doctor | Prove the Fragments enforcement hook chain is armed | --root --cloud-url --json +2 |
| explain | Explain a Fragments FUI code | --print --open |
| identity | Inspect and decide local component identity | --root -c --json +2 |
| identity consolidate | Propose proven usage-site swaps through the conform preflight | --into |
| identity dismiss | Dismiss a wrapper decision and classify it as a shadow | --into --reason |
| identity migrate-report | Compare canonical finding reports without updating a baseline | --before --after --json |
| identity promote | Promote a component through the canonical contract authoring path | None |
| identity sanction | Sanction a review-tier wrapper as a local variant | --all-wrappers --dry-run --into +1 |
| status | Inspect generated Fragments guardrail configuration | --cwd --preset --sync-tolerance-hours +2 |
AI & Context
Generate AI-ready context and configure hosted MCP access.
Command | Does | Flags |
|---|---|---|
| mcp | Run the local Fragments MCP server, or print hosted setup | --stdio -d --url |
Integrations & Registry
Connect external tools and manage source registry artifacts.
Command | Does | Flags |
|---|---|---|
| add | Install source components from a registry (alias of `registry add`) | --from --registry --api-key +8 |
| registry | Generate and inspect Fragments Registry artifacts | None |
| registry add | Install source components from a registry (default: the public usefragments-ui) | --from --registry --api-key +8 |
| registry artifact | Generate a local installable source registry artifact | --cwd -i -o +9 |
| registry diff | Compare installed registry source against a registry artifact | --from --api-key --cloud-url +3 |
| registry migrate | Migrate an npm UI app to registry source install | --from --api-key --cloud-url +7 |
| registry status | Inspect the local registry lockfile and installed source state | --cwd --from --api-key +2 |
| registry sync | Refresh installed registry source using the existing lockfile selection | --from --api-key --cloud-url +4 |
Utilities
Local maintenance helpers and the static HTML viewer.
Command | Does | Flags |
|---|---|---|
| view | Generate a static HTML viewer for fragments.json | -i -o --open |
Next steps
- The loopinit, discover, and the first correction in five minutes.
- MCPHosted endpoint, per-editor configuration, and the design-system tools.
- Error codesEvery FUI diagnostic code with its own explain page.