Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

codegen — Claude Code skill: code generation from UI specs

Utilities for generating code from json-render UI trees. Build custom code exporters for Next.js, Remix, and other frameworks, traverse specs, and serialize props.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add vercel-labs/json-render --skill codegen -a claude-code
Open on GitHub

What codegen does

codegen provides a toolkit for working with UI specifications at the code level. It has three layers: tree traversal (traverseSpec), metadata collection (which components are used, what state paths and actions exist), and value serialization for JSX.

Traversal walks the entire UI tree depth-first so you can collect data: collectUsedComponents gets all component types, collectStatePaths finds state references like "analytics/revenue", collectActions lists action names. Serialization turns values into code strings: serializePropValue handles strings, state objects, and returns ready-to-insert JSX. The escapeString helper quotes and escapes strings for code output.

Install via npm install @json-render/codegen and load as a skill in your IDE. Works with json-render/core specs; needs Node.js and npm.

What it helps with

  • Extract metadata from UI spec: components, state paths, actions
  • Serialize values into JSX attributes with proper escaping
  • Walk the entire UI tree and process each element
  • Build a custom code generator for your framework
  • Turn a design spec into a working Next.js project

Example prompts for the agent

  • Collect all components used in the spec and export them as a list
  • Find all state paths in the UI and generate variable declarations
  • Generate a Next.js page from a json-render spec with correct props

How to install codegen

1Skills CLI (Vercel)

npx skills add vercel-labs/json-render --skill codegen -a claude-code

2Manually: put the files in place

~/.claude/skills/codegen/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/codegen/

From the same set5

The whole set →

Similar

flutter-add-widget-preview flutter Configures interactive Flutter widget previews with package:flutter/widget_previews.dart. Useful for testing UI components in isolation without launching the whole app. Claude Code CX Codex Cursor +1 36,600installs transitions-polish Jakubantalik This skill audits existing animations and maps timing, distance, scale, blur, and easing to motion tokens. Use it when motion feels off. Claude Code CX Codex Cursor +1 10,600installs explain-interface jakubkrehel Explains how a visual effect, animation, or website layout was built from a live page or a screenshot. It breaks down the underlying layer stack. Claude Code CX Codex Cursor +1 13,900installs interaction-design Seth Hobson This skill helps design microinteractions, transitions, and feedback states. Use it when polishing a UI or building loading and gesture patterns. Claude Code CX Codex Cursor 16,146installs design-system-patterns Seth Hobson Guides the design of design tokens, theme switching, and component library architecture. Use it when establishing shared UI foundations for a project. Claude Code CX Codex Cursor 15,953installs frontend-design official anthropics This skill guides intentional visual design for new interfaces and redesigns. Use it when a generic generated UI is not enough. Claude Code Claude.ai 1,025,790installs design-taste-frontend Leonxlnx This skill directs the design of public pages and work screens, then checks the result in a browser through screenshots. Use it when an interface feels generic or unfinished. Claude Code CX Codex Cursor +1 673,100installs prototype Matt Pocock Creates throwaway prototypes for checking state logic or exploring UI before committing the decision to the main codebase. Claude Code 986,201installs

Questions about codegen

How do I install codegen in Claude Code?

Run npx skills add vercel-labs/json-render --skill codegen -a claude-code. After installation, the skill will be available at ~/.claude/skills/codegen/SKILL.md.

What does codegen do?

It provides utilities to analyze and generate code from json-render UI specs. You can traverse specs, collect metadata (components, state, actions), and serialize values for JSX.

What dependencies are required?

You need @json-render/core for Spec types. The main package @json-render/codegen is installed via npm.

Source text

SKILL.md · Apache-2.0
---
name: codegen
description: Code generation utilities for json-render. Use when generating code from UI specs, building custom code exporters, traversing specs, or serializing props for @json-render/codegen.
---

# @json-render/codegen

Framework-agnostic utilities for generating code from json-render UI trees. Use these to build custom code exporters for Next.js, Remix, or other frameworks.

## Installation

```bash
npm install @json-render/codegen
```

## Tree Traversal

```typescript
import {
  traverseSpec,
  collectUsedComponents,
  collectStatePaths,
  collectActions,
} from "@json-render/codegen";

// Walk the spec depth-first
traverseSpec(spec, (element, key, depth, parent) => {
  console.log(`${" ".repeat(depth * 2)}${key}: ${element.type}`);
});

// Get all component types used
const components = collectUsedComponents(spec);
// Set { "Card", "Metric", "Button" }

// Get all state paths referenced
const statePaths = collectStatePaths(spec);
// Set { "analytics/revenue", "user/name" }

// Get all action names
const actions = collectActions(spec);
// Set { "submit_form", "refresh_data" }
```

## Serialization

```typescript
import {
  serializePropValue,
  serializeProps,
  escapeString,
  type SerializeOptions,
} from "@json-render/codegen";

// Serialize a single value
serializePropValue("hello");
// { value: '"hello"', needsBraces: false }

serializePropValue({ $state: "/user/name" });
// { value: '{ $state: "/user/name" }', needsBraces: true }

// Serialize props for JSX
serializeProps({ title: "Dashboard", columns: 3, disabled: true });
// 'title="Dashboard" columns={3} disabled'

// Escape strings for code
escapeString('hello "world"');
// 'hello \"world\"'
```

### SerializeOptions

```typescript
interface SerializeOptions {
  quotes?: "single" | "double";
  indent?: number;
}
```

## Types

```typescript
import type { GeneratedFile, CodeGenerator } from "@json-render/codegen";

const myGenerator: CodeGenerator = {
  generate(spec) {
    return [
      { path: "package.json", content: "..." },
      { path: "app/page.tsx", content: "..." },
    ];
  },
};
```

## Building a Custom Generator

```typescript
import {
  collectUsedComponents,
  collectStatePaths,
  traverseSpec,
  serializeProps,
  type GeneratedFile,
} from "@json-render/codegen";
import type { Spec } from "@json-render/core";

export function generateNextJSProject(spec: Spec): GeneratedFile[] {
  const files: GeneratedFile[] = [];
  const components = collectUsedComponents(spec);
  // Generate package.json, component files, main page...
  return files;
}
```

© vercel-labs · Apache-2.0 · vercel-labs/json-render

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor