Design ↔ Code
One of Pencil’s most powerful features is seamless synchronization between your designs and codebase.
Overview
Pencil enables a two-way workflow between design and code:
- Design → Code: Generate components from Pencil designs
- Code → Design: Import existing code into Pencil
- Sync: Keep design and code in sync as both evolve
Design → Code Workflow
Basic Export to Code
- Design in Pencil - Create your UI components, layouts, or screens
- Save the
.penfile in your project workspace - Open AI prompt - Press
Cmd/Ctrl + K - Ask for code generation:
"Generate React code for this design" "Create a TypeScript component from this frame" "Export this as a Next.js page component"
Example Prompts
Component generation:
Create a React component for this buttonGenerate TypeScript types for this formExport this card as a reusable componentFull pages:
Generate a Next.js page from this designCreate a landing page component with Tailwind CSSExport this dashboard as a React componentWith specific libraries:
Generate code using Shadcn UI componentsCreate this form using React Hook FormExport using Lucide icons instead of Material IconsCode → Design Workflow
Importing Existing Code
If you have existing components in your codebase, Pencil can recreate them visually.
Requirements:
- Keep the
.penfile in the same workspace as your code - The AI agent can access both files
Workflow:
- Open your
.penfile - Open AI prompt - Press
Cmd/Ctrl + K - Ask to import code:
Recreate the Button component from src/components/Button.tsxImport the LoginForm from my codebase into this designAdd the Header component from src/layouts/Header.tsx
What gets imported:
- Component structure and hierarchy
- Layout and positioning
- Styling (colors, typography, spacing)
- Basic interactions
Two-Way Sync
Keeping Design and Code in Sync
The most powerful workflow combines both directions:
- Start with code - Import existing components into Pencil
- Design improvements - Make visual changes in Pencil
- Update code - Ask AI to apply changes back to code
- Iterate - Repeat as needed
Variables & Design Tokens
CSS Variables ↔ Pencil Variables
Create a synchronized design token system:
Import CSS to Pencil:
-
Have a
globals.cssor similar file with CSS variables -
Ask the agent:
Create Pencil variables from my globals.cssImport design tokens from src/styles/tokens.css
Export Pencil to CSS:
-
Define variables in Pencil
-
Ask the agent:
Update globals.css with these Pencil variablesSync these design tokens to my CSS
Workflow Example
/* globals.css */
:root {
--color-primary: #3b82f6;
--color-secondary: #64748b;
--spacing-base: 1rem;
}In Pencil:
- “Create variables from globals.css”
- Update color-primary to #2563eb in Pencil
- “Sync variables back to globals.css”
Result:
/* globals.css - updated */
:root {
--color-primary: #2563eb; /* Updated! */
--color-secondary: #64748b;
--spacing-base: 1rem;
}Importing from Figma
You can bring design tokens from Figma into Pencil:
Token Import:
-
Copy tokens from Figma
-
Or take a screenshot of token tables
-
Paste in Pencil or share with AI agent
-
Ask:
Create Pencil variables from these Figma tokens
Components:
- Copy elements from Figma
- Paste into Pencil
- Note: Images don’t copy - use SVG or re-import separately
Best Practices
File Organization
Keep .pen files in your repo:
my-project/
├── src/
│ ├── components/
│ └── styles/
├── design.pen ← Design file
└── package.jsonBenefits:
- AI agent can see both design and code
- Version control tracks both together
- Easy to keep in sync
Workflow Recommendations
Start new features:
- Design in Pencil first
- Generate initial code
- Refine code implementation
- Update design if needed
Update existing features:
- Import component into Pencil
- Make design changes
- Sync changes back to code
Design system maintenance:
- Define variables in Pencil
- Sync to CSS
- Use variables in both design and code
- Update once, apply everywhere
Code Generation Options
Frameworks & Libraries
Pencil can generate code for:
- React (JavaScript or TypeScript)
- Next.js
- Vue
- Svelte
- Plain HTML/CSS
Styling:
- Tailwind CSS (recommended)
- CSS Modules
- Styled Components
- Plain CSS
Component Libraries:
- Shadcn UI
- Radix UI
- Chakra UI
- Material UI
- Custom components
Specifying in Prompts
Be specific about your tech stack:
Generate Next.js 14 code with Tailwind CSSCreate a Vue component using TypeScriptExport as React with CSS ModulesUse Shadcn UI components for this layoutIcon Libraries
Built-in vs Code Libraries
In Pencil:
- Built-in icons use Material Icons
- Custom SVG paths supported
For code generation:
- Specify your preferred library in prompts
- Common options: Lucide, Heroicons, FontAwesome, React Icons
Example:
Generate this design using Lucide iconsReplace Material Icons with Heroicons in the codeLimitations & Workarounds
Current Limitations
No auto-save:
- Save frequently with
Cmd/Ctrl + S - Commit to Git often
Export issues:
- If export fails with “process exited with code 1”, check Claude Code auth
- Try running the export in a separate Claude Code session
Canvas vs export mismatch:
- If exported code doesn’t match the canvas, report the issue
- Try re-exporting or adjusting the design
Workarounds
Permissions:
- If Claude can’t access folders, update permissions
- Accept permission prompts when they appear
Complex components:
- Break down complex designs into smaller pieces
- Export in stages
- Combine in code
Example Project Setup
# 1. Create project with design file
mkdir my-app && cd my-app
touch design.pen
npm init -y
# 2. Open in IDE
code .
# 3. Start Claude Code
claude
# 4. Open design.pen and start designing
# 5. Use Cmd + K to generate code