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:

Terminal
# 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 CI

Configuration

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.

fragments.config.ts
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.

Terminal
npx @usefragments/cli doctor

Doctor 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.

doctor flags
Argument / flag
Description
Default
--jsonMachine-readable report for scripts and CI dashboardsNot set
--reset-debounceClear 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 directorycurrent 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.

Setup commands
Command
Does
Flags
hookInstall or remove the Fragments contract hook for an AI agentNone
hook installInstall the Fragments contract hook for an agent--agent --mode --scope +1
hook uninstallRemove Fragments contract hook entries for an agent--agent --scope --dry-run
initInstall local Fragments guardrails, agent hooks, and CI--token --path --cloud-url +20

Authentication

Sign in, inspect the active session, and sign out.

Authentication commands
Command
Does
Flags
authInspect CLI authenticationNone
auth statusVerify the stored exact-binding OAuth session--binding --access-token --cloud-url +2
loginAuthorize the CLI for one exact Fragments repository binding--binding --cloud-url --storage +1
logoutRevoke and remove the CLI session for one exact binding--binding --storage --cwd

Build & Compile

Compile, validate, and synchronize component metadata.

Build & Compile commands
Command
Does
Flags
buildBuild compiled fragments.json and .fragments/ directory-c -o --registry +7
scanZero-config fragments.json generation from source code-c -o --patterns +5
validateValidate fragment files-c --schema --coverage +6

Inspect & Discover

Inspect components, tokens, dependencies, and generated metadata.

Inspect & Discover commands
Command
Does
Flags
discoverPropose fragments.manifest.json from the design-system sources-d --write --json +2
tokensDesign token discovery, listing, and generationNone
tokens generateGenerate CSS, SCSS, Tailwind, or Figma output from a DTCG .tokens.json file--from --format --out +3
tokens listDiscover and list design tokens from CSS/SCSS/DTCG files-c --json --categories +3

Quality & Compliance

Check design-system governance, readiness, and metadata quality.

Quality & Compliance commands
Command
Does
Flags
bridgesManage confirmed package-to-local canonical bridgesNone
bridges addAppend validated canonical bridge entries to fragments.config.ts--root -c --from-conflicts +1
checkCheck source files for design-system drift-d -c -f +31
checkpointPin and manage dirty-worktree snapshots for scoped governanceNone
checkpoint clearDelete one checkpoint or all checkpoints--all
checkpoint createCreate a named checkpoint of the current worktree--label --force
checkpoint listList checkpoints and work changed since each snapshotNone
codemodMechanical source migrations for consumers of the component kitNone
codemod ui-vocabularyRewrite @usefragments/ui call sites to the ruled prop vocabulary (variant/tone/size/gap/status)--dry-run --source --json
conformConform source files to governance policy and prove a clean pass-d -c -f +19
contractEdit this repository's Fragments Cloud contract from the terminalNone
contract sourcesToken source files pinned by the Cloud contractNone
contract sources addAdd token source paths (applies when the repository scan already sees them)--binding --access-token --cloud-url +5
contract sources listShow the pinned token sources, canonical sources, and pending proposals--binding --access-token --cloud-url +3
contract sources removeRemove token source paths that no longer exist (applies immediately for admins)--binding --access-token --cloud-url +5
contract sources replacePoint a token source at the path the file moved to--binding --access-token --cloud-url +5
contract undoRestore the contract an applied edit replaced, while it is still the latest revision--binding --access-token --cloud-url +3
doctorProve the Fragments enforcement hook chain is armed--root --cloud-url --json +2
explainExplain a Fragments FUI code--print --open
identityInspect and decide local component identity--root -c --json +2
identity consolidatePropose proven usage-site swaps through the conform preflight--into
identity dismissDismiss a wrapper decision and classify it as a shadow--into --reason
identity migrate-reportCompare canonical finding reports without updating a baseline--before --after --json
identity promotePromote a component through the canonical contract authoring pathNone
identity sanctionSanction a review-tier wrapper as a local variant--all-wrappers --dry-run --into +1
statusInspect generated Fragments guardrail configuration--cwd --preset --sync-tolerance-hours +2

AI & Context

Generate AI-ready context and configure hosted MCP access.

AI & Context commands
Command
Does
Flags
mcpRun the local Fragments MCP server, or print hosted setup--stdio -d --url

Integrations & Registry

Connect external tools and manage source registry artifacts.

Integrations & Registry commands
Command
Does
Flags
addInstall source components from a registry (alias of `registry add`)--from --registry --api-key +8
registryGenerate and inspect Fragments Registry artifactsNone
registry addInstall source components from a registry (default: the public usefragments-ui)--from --registry --api-key +8
registry artifactGenerate a local installable source registry artifact--cwd -i -o +9
registry diffCompare installed registry source against a registry artifact--from --api-key --cloud-url +3
registry migrateMigrate an npm UI app to registry source install--from --api-key --cloud-url +7
registry statusInspect the local registry lockfile and installed source state--cwd --from --api-key +2
registry syncRefresh installed registry source using the existing lockfile selection--from --api-key --cloud-url +4

Utilities

Local maintenance helpers and the static HTML viewer.

Utilities commands
Command
Does
Flags
viewGenerate 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.