Design to Code Synchronization
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 button”
- “Generate TypeScript types for this form”
- “Export this card as a reusable component”
Full pages:
- “Generate a Next.js page from this design”
- “Create a landing page component with Tailwind CSS”
- “Export this dashboard as a React component”
With specific libraries:
- “Generate code using Shadcn UI components”
- “Create this form using React Hook Form”
- “Export using Lucide icons instead of Material Icons”
Code → 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.tsx" "Import the LoginForm from my codebase into this design" "Add 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
Example Workflow
User: "Import my Header component into Pencil"
→ AI recreates Header.tsx visually in .pen file
User: "Change the header background to dark blue"
→ Make change in Pencil canvas
User: "Update Header.tsx with this new design"
→ AI updates the code file with new stylingVariables & 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.css" "Import design tokens from src/styles/tokens.css"
Export Pencil to CSS:
- Define variables in Pencil
- Ask the agent:
"Update globals.css with these Pencil variables" "Sync 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 CSS"
"Create a Vue component using TypeScript"
"Export as React with CSS Modules"
"Use Shadcn UI components for this layout"Icon 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 icons"
"Replace Material Icons with Heroicons in the code"Limitations & 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
Next Steps
- Learn about AI Integration for advanced workflows
- Explore Variables in detail
- Check Troubleshooting if you encounter issues
- See the FAQ for specific questions
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 codeYour design and code now live together, kept in sync by Pencil and AI.