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.
npx skills add vercel-labs/json-render --skill codegen -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/codegen/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/codegen/
1Skills CLI (Vercel)
npx skills add vercel-labs/json-render --skill codegen -a codex2Manually: put the files in place
.agents/skills/codegen/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add vercel-labs/json-render --skill codegen -a cursor2Manually: put the files in place
.cursor/skills/codegen/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install vercel-labs/json-render codegen2Manually: put the files in place
.github/skills/codegen/SKILL.md1Skills CLI (Vercel)
npx skills add vercel-labs/json-render --skill codegen -a gemini-cli2Platform CLI
gemini skills install https://github.com/vercel-labs/json-render --path skills/codegenManually: put the files in place
.devin/skills/codegen/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add vercel-labs/json-render --skill codegen -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set5
The whole set →Similar
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