# AI coding with Master CSS

Connect an agent to your Master CSS project, request a scoped change, verify the rendered result, and review shared style changes.

<a id="overview"></a>

## Overview

Give your coding agent the same styling context you use: the CSS entry, theme tokens, component classes and the project's checks. Connect the Master CSS MCP server, ask for a scoped UI change, and require evidence from the final source and the rendered result. This guide takes you from project setup through a first repair and a later change to a shared definition.

---

<a id="set-up-the-project-first"></a>

## Set up the project first

The [installer](/guide/installation) prepares a project for agents by default. Alongside the framework integration, `npm create @master/css@2.1.8` adds:

- `@master/eslint-config-css` and an `eslint.config.js` that spreads it, so agent output is checked by [Code linting](/guide/code-linting).
- `@master/css-mcp` as a dev dependency, and prints the stdio command for registering it in your MCP client.
- A `## Master CSS` rules block in `AGENTS.md` that points agents at the documentation, the project's vocabulary, MCP and ESLint.

Pass `--no-eslint`, `--no-mcp` or `--no-ai` to skip one of them, or `--minimal` for the framework setup only. Add the project's actual validation commands below the generated `AGENTS.md` block so the agent does not have to infer them.

To have your coding agent run this setup, give it the [setup prompt](/guide/installation#set-up-with-an-ai-agent) from the installation guide.

Then give the project a vocabulary the agent can reuse. Theme tokens make repeated values explicit, and component classes give shared product patterns a stable name:

```css name=app.css
@import '@master/css';

@theme {
  --color-brand: #4f46e5;
  --spacing-card: 1.5rem;
}

@layer components {
  .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding-inline: var(--spacing-md);
    border-radius: var(--radius-md);
  }
}
```

---

<a id="connect-the-mcp-server"></a>

## Connect the MCP server

The MCP server runs locally over stdio and reads the workspace passed to `--root`. For a client that accepts `mcpServers` JSON, add this entry to its MCP configuration file:

```json name=mcp-client-config.json
{
  "mcpServers": {
    "master-css": {
      "command": "npx",
      "args": ["-y", "@master/css-mcp@2.1.8", "--root", "/absolute/path/to/project"]
    }
  }
}
```

Clients with their own registration command use the same stdio command:

```bash
# Claude Code (add --scope project for a shared .mcp.json)
claude mcp add --transport stdio master-css -- npx -y @master/css-mcp@2.1.8 --root /absolute/path/to/project

# Codex
codex mcp add master-css -- npx -y @master/css-mcp@2.1.8 --root /absolute/path/to/project
```

Use an absolute `--root`; review a committed project-scoped config, because that path is machine-specific. Restart the client or open a new session, then ask the agent to call `mastercss_workspace_info` and confirm that the returned root and stylesheet entries belong to this project. A manifest load failure means the project context needs fixing; the server does not silently answer from the preset.

The [MCP tool catalog](/reference/tools/mcp) lists every tool, the built-in prompts such as `debug-missing-css`, and the machine-readable result envelope. When a client cannot use MCP, run the [CLI](/reference/tools/cli) from the project root instead, for example `master-css lint --format json --exit-code never` or `master-css inspect --format json --exit-code never`.

Enjoying Master CSS? [Star it on GitHub](https://github.com/master-co/css) to help other developers find it.

---

<a id="use-the-master-css-skill"></a>

## Use the Master CSS skill

The official `master-css` skill reads the relevant guidance for your task. Use it
for these workflows in a Master CSS project:

| Workflow | When to use it |
| --- | --- |
| Build and edit UI | Create or refine components using project tokens, utilities and native CSS. |
| Review and debug styles | Review styling changes or investigate missing and unexpected styles, from source extraction to browser behavior. |
| Optimize CSS delivery | Assess production CSS, improve route and component loading boundaries, and verify selective pruning. |

Install it from your project directory and choose your coding agent:

```sh
npx skills add master-co/css --skill master-css
```

The [Skills CLI](https://github.com/vercel-labs/skills) supports selecting an agent
such as Codex, Claude Code or Cursor. Check the skill's compatibility metadata
against the installed Master CSS version. The skill reads relevant references
as needed; it does not install Master CSS or register an MCP server for you.
The installer's `--ai` option prints this command without running it.

<a id="ask-for-one-observable-change"></a>

## Ask for one observable change

Ask the agent to inspect the project before it edits, then make one focused change. For example, ask it to refine an existing card and describe the result you expect:

**Refine one component**

```text
Update the existing notes card so its padding follows the project's shared card spacing. Keep the card's links and keyboard behavior working, and verify the narrow layout.

You are working in a Master CSS project.

Read the installed package/language/binding versions and project manifest first. Use documentation that matches those versions.
Consult the Guide and Reference for the installed Master CSS version.

Before editing, inspect the framework, package manager, CSS entry, theme tokens, component classes, nearby UI patterns, and available validation commands.

When styling markup:
- use valid Master CSS syntax
- prefer existing theme tokens and component classes
- prefer fixed utilities and numeric functions, such as flex and p(16), over equivalent native declarations
- use canonical token families for project values and full native property names when a native declaration is needed
- do not invent Master CSS APIs, directives, package names, or Tailwind-style syntax
- keep semantic HTML and accessibility behavior unchanged
- explain any value that should become a shared token

After editing, inspect the final classes against the project manifest and run the relevant project checks. Verify computed styles and the affected states in the browser. Report changed files, styling decisions, checks actually run, and anything still unverified.
```

---

<a id="verify-a-repair"></a>

## Verify a repair

Ask the agent to preserve the current working behavior and show what evidence
supports its repair. Keep a source snapshot before editing, then inspect and
rebuild the final files, including after lint autofixes. A rejected proposal is
useful evidence, but it is not the source to start the next repair from.

Different checks answer different questions:

| Evidence | What to check |
| --- | --- |
| Lint report | Read `coverage.checkedFiles` and the enabled rules. `summary.checkedFiles` counts checked inputs; `summary.filesWithDiagnostics` counts those with diagnostics. Empty diagnostic `files` does not mean nothing ran. |
| Class inspection | Check the final markup against the loaded project stylesheets. Distinguish generated utilities, native CSS selector hooks and unresolved spellings. |
| Browser verification | Compare computed values and matched rules in the affected states, including previously working states. A generated rule does not establish which declaration wins. |

<a id="a-generated-rule-can-still-lose"></a>

### A generated rule can still lose

Both classes in this example reach valid CSS. The preset's `p-md` generates 1rem of padding, but `.notice` sets 8px in an **unlayered** native rule. For normal declarations, that rule wins over the layered utility:

**Present in the output does not mean winning in the browser**

- **Generated rule.** The preset p-md utility supplies padding: var(--spacing-md) inside the utilities layer. Its default value is 1rem.
- **Competing rule.** The unlayered native rule .notice { padding: 8px; } takes precedence over the layered utility for normal declarations.
- **Observed result.** An element with both notice and p-md has 8px padding on every side. Fixing its spacing requires reviewing the winning native rule, not generating the same utility again.

Both rules are valid and present. Normal unlayered CSS outranks normal layered CSS, so inspecting generated output alone cannot prove the intended spacing.

```css
.notice {
padding: 8px;
}
```

```html
<p class="w-fit m(0) p-md r-md text-sm bg-surface-raised fg-text-strong notice">Saved locally</p>
```

```css disclosure=generated-css
.notice {
  padding: 8px;
}

@layer theme{:root,:host{--color-zinc-90:oklch(24.6% .0022 265);--color-zinc-100:oklch(15% .0016 265)}:root,:host{--color-surface-raised:light-dark(var(--color-white), var(--color-zinc-90));--color-text-strong:light-dark(var(--color-zinc-100), var(--color-white))}:root,:host{--color-white:oklch(100% 0 none)}:root,:host{--font-size-sm:.875rem;--text-sm:var(--font-size-sm);--text-sm--line-height:1.5;--text-sm--letter-spacing:0;--radius-md:.375rem;--spacing-md:1rem}}@layer utilities{.text-sm{font-size:var(--text-sm);line-height:var(--text-sm--line-height, normal);letter-spacing:var(--text-sm--letter-spacing, normal)}.bg-surface-raised{background-color:var(--color-surface-raised)}.r-md{border-radius:var(--radius-md)}.fg-text-strong{color:var(--color-text-strong)}.m\(0\){margin:calc(0 * 1px)}.p-md{padding:var(--spacing-md)}.w-fit{width:fit-content}}
```

The notice has 8px of padding on every side. Inspect it in the browser, then compare the native rule with p-md in Generated CSS. Both rules exist; only one supplies the computed padding.

Generating another `p-md` rule would not fix this result. If the notice should follow the shared spacing, remove the competing padding declaration, or intentionally place the component rule in `@layer components`. Check other notices before changing a shared rule. See [CSS layer ordering](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@layer#description).

<a id="read-inspection-coverage"></a>

### Read inspection coverage

Default lint permits unknown authored CSS names, so a clean lint result does not
prove every class is a registered utility. CLI inspection can report a native
selector in both `discovered.invalid` and `discovered.usedNative`: it does not
generate a utility, but its stylesheet rule can still be present. For an explicit
`inspect --classes` request, read the `missingCSS` presence reasons alongside the
markup and native rules. An empty `missingCSS.checked` list is not a completed
class check. The [CLI catalog](/reference/tools/cli#inspect) documents inspection.

When a native rule and a utility affect the same property, follow the
[cascade diagnosis](/guide/cascade-layers#diagnose-a-competing-declaration) with the project's
actual layer order. Keep the inspection result and the browser's winning
declaration together in the repair report.

A conflict warning also needs review when both class names are recognized. Using
a registered utility as a native hover selector hook does not restrict its
separate generated rule to hover. Check the resting state, hover condition,
keyboard focus, disabled state and touch behavior that the component supports.
Rerun the project's relevant checks after the last edit; preserve checks that
passed before the repair rather than accepting a new failure elsewhere.

**A checked set is smaller than the whole project**

A project boundary contains three sources; a bracket encloses only the two inspected sources and leaves the third outside.

Report checked files and context explicitly. A clean result for a subset is not evidence about every source.

<a id="verification-limits"></a>

### Report the result and its limits

Ask for a short final report identifying changed behavior, retained native CSS
and dependencies, the files and states actually checked, and unresolved diagnostics.
If lint fails on three files but passes on a narrower selection, both results
belong in the report. Informational unknown-value diagnostics should remain
visible without being described as invalid values. Separate static expectations
from browser-observed results, and say when browser verification is outstanding.

The skill supplies instructions; it does not automatically run a browser or enforce
a repair rollback. Your agent and project checks must provide those operations.
Dynamic class construction, runtime changes and untested environments can remain
outside static inspection. A successful build, an empty diagnostic list or one
passing visual state does not guarantee a complete repair. Keep any incomplete
repair explicit and stop at the agreed scope and validation budget.

---

<a id="safe-write-previews"></a>

## Review a tool-generated fix

Read-only tools never write files. A fix goes through two calls, so the agent can show you the diff first:

1. `mastercss_preview_fixes` or `mastercss_preview_directive_format` returns a diff and a confirmation token without touching the workspace.
2. Once the diff is accepted under your project’s review workflow, `mastercss_apply_preview` writes it, but only if the token is valid, every path stays inside the workspace and each file still matches the hash it had at preview time.

For example, a class-order preview for one file:

```json name=mastercss_preview_fixes
{
  "mode": "lint-fixes",
  "patterns": ["src/button.html"],
  "rules": "sort-classes"
}
```

If a file changes after the preview, applying it fails instead of overwriting newer work. Create a fresh preview when its files or server session change. See [preview lifetime](/reference/tools/mcp#preview-lifetime) for token validity and write guarantees.

---

<a id="translate-a-declaration-when-the-class-is-unclear"></a>

## Translate a declaration when the class is unclear

When reading an MCP class inspection, check `matchStatus`, `cssSyntaxStatus`, `cssValueStatus` and `browserSupport` separately: an unknown value is not a failed match, and `not-checked` browser support is not verified support.

When a class spelling is uncertain, the [CLI](/guide/installation#cli) can suggest
classes from an isolated CSS declaration block without an MCP connection. Run
the project's installed version from the app root:

```bash
master-css suggest 'display:flex; align-items:center; padding:16px; gap:1rem;'
```

Read `result.classes`, `result.remainingCss`, `validation` and `diagnostics` in the
JSON response. Check `manifest.entries` for the expected CSS entry; an empty list
means the preset was used. Use `--cwd` to select another project root or `--stdin`
to read declarations from standard input. See the [command contract](/reference/tools/cli#suggest)
for exit statuses and preserved blocks. If your installed CLI lacks `suggest`,
keep using its available checks instead of mixing package versions.

With MCP connected, `mastercss_suggest_classes` accepts the same declaration block:

```json
{
  "declarations": "display:flex; align-items:center; padding:16px; gap:1rem;"
}
```

With the default preset, this proposes `flex items-center p(16) (gap:1rem)`.
Project definitions can change those suggestions. The result includes generated
CSS, separate value-validation statuses, and `remainingCss` for blocks that need
to stay in native CSS. The tool preserves an entire uncertain block, including
duplicate declarations and potentially overlapping properties. It does not edit
files or convert a stylesheet's selectors.

Review the cascade before applying a suggestion: moving a declaration from a
selector or inline style into a utility can change which rule wins. The tool's
declaration check does not verify surrounding styles or browser rendering.

---

<a id="contracts-of-a-design-system"></a>

## Contracts of a design system

When the project depends on a design system that ships contracts, such as [`@master/ui`](https://ui.master.co), the same MCP server serves them. A contract states a component's classes and where they go, its states, public properties and smallest correct markup. Ask the agent to read the contract before it writes a component's markup, then check the result:

1. `mastercss_contract_list` finds the component; filter with `query`, `tier` or `category`.
2. `mastercss_contract_get` returns the full contract by its name or by any of its classes, so `btn-primary` returns the button contract.
3. `mastercss_contract_check` checks an unsaved buffer or project files with the checker the library ships.

For example, a button that is missing its base class:

```json name=mastercss_contract_check
{
  "content": "<button class=\"btn-primary\">Save</button>",
  "filePath": "src/button.html"
}
```

With `@master/ui` this reports `missing-base`, because `btn-primary` modifies `btn`. A component the project owns keeps its contract in the project; that contract replaces the library's contract of the same name, and every result names its `source`. A library declares its contracts and checker in its `package.json`; see [contracts of a design system](/reference/tools/mcp#contracts-of-a-design-system) for that field and for project-owned contracts. The check reads markup as written. It does not replace lint or a look at the rendered result.

---

<a id="review-the-second-change"></a>

## Check the reach of a shared change

A first draft that looks right does not show what the next edit will affect. Before changing a shared definition such as `--color-brand`, save a project snapshot, then compare after editing, even when markup has not changed:

```bash
master-css inspect --snapshot > before.json
master-css inspect --compare before.json > impact.json
```

`impact.json` lists changed definitions, known class consumers and files, before/after generated rules, native stylesheet references and output delivery. Read its `coverage` even when nothing changed: dynamic sources, remote content and final browser behavior are not exhaustively checked. In MCP, call `mastercss_scan_project` with `includeSnapshot: true` before and after, and pass both snapshots to `mastercss_css_compare`.

For native component CSS, inspect token references across the managed stylesheet graph. Route and component stylesheets imported from JavaScript are outside that graph; name them as source paths:

```bash
master-css inspect --design-system --design-system-options design-system.options.json "app/**/*.css"
```

The report lists each `var()` token reference with its source range, selector and at-rule ancestry, importers and shared-prefix collisions. Its `components` list gives each component class's attribute vocabulary, read from selectors such as `.button[data-variant="primary"]`, so an agent can write variants the CSS actually styles. The optional [options file](/reference/tools/cli#design-system-options) adds token descriptions, deprecations with suggested replacements, and a raw-value policy for selected properties; the same object is accepted by `mastercss_scan_project.designSystem`, with route stylesheets in `routeStylesheets`, and the [Language Service](/guide/language-service) `designSystem` setting. These reports are authored-syntax evidence: check affected layouts and states in the browser.

<a id="optimize-delivery-with-an-agent"></a>

## Optimize delivery with an agent

For a loading refactor or performance assessment, give the agent [Optimizing CSS delivery](/guide/optimizing-css-delivery), the target routes, existing rendering mode and checks. Ask it to baseline production assets, move feature styles to their owners, then verify the output and interactions on both the feature page and an unrelated page. Preserve the mode unless the task requires changing it.

The public Master CSS skill routes this work through its delivery reference. Source and manifest inspection remain useful, but neither establishes browser transfer costs or correct later states. An ordinary component change needs its local checks, not an automatic whole-site audit.
