Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Production-ready patterns for the Figma REST API and Plugin API. Use when building reusable Figma client wrappers, extracting design tokens, traversing node trees, or creating typed API helpers. Trigger with phrases like "figma patterns", "figma best practices", "figma client wrapper", "figma typed API".
.claude/skills/jeremylongshore-figma-sdk-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 43% | 0% |
| case-03 | ✗→✓ | ▲ Improved | -4% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 25% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 238% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 114% | 0% |
Production patterns for the Figma REST API (external tools) and Plugin API (in-editor plugins). Figma has no official Node.js SDK -- you call https://api.figma.com directly with fetch. These patterns give you type safety, error handling, and reusable abstractions.
FIGMA_PAT environment variable settypescript// src/figma-client.ts export class FigmaClient { private baseUrl = 'https://api.figma.com'; constructor(private token: string) { if (!token) throw new Error('Figma token is required'); } private async request<T>(path: string, init?: RequestInit): Promise<T> { const res = await fetch(`${this.baseUrl}${path}`, { ...init, headers: { 'X-Figma-Token': this.token, 'Content-Type': 'application/json', ...init?.headers, }, }); if (res.status === 429) { const retryAfter = parseInt(res.headers.get('Retry-After') || '60'); throw new FigmaRateLimitError(retryAfter); } if (res.status === 403) throw new FigmaAuthError('Invalid or expired token'); if (res.status === 404) throw new FigmaNotFoundError(path); if (!res.ok) throw new FigmaApiError(res.status, await res.text()); return res.json(); } async getFile(fileKey: string) { return this.request<FigmaFileResponse>(`/v1/files/${fileKey}`); } async getFileNodes(fileKey: string, nodeIds: string[]) { const ids = encodeURIComponent(nodeIds.join(',')); return this.request<FigmaNodesResponse>(`/v1/files/${fileKey}/nodes?ids=${ids}`); } async getImages(fileKey: string, nodeIds: string[], opts?: ImageOptions) { const params = new URLSearchParams({ ids: nodeIds.join(','), format: opts?.format ?? 'png', scale: String(opts?.scale ?? 2), }); return this.request<FigmaImagesResponse>(`/v1/images/${fileKey}?${params}`); } async getComments(fileKey: string) { return this.request<FigmaCommentsResponse>(`/v1/files/${fileKey}/comments`); } async postComment(fileKey: string, message: string, nodeId?: string) { return this.request(`/v1/files/${fileKey}/comments`, { method: 'POST', body: JSON.stringify({ message, ...(nodeId && { client_meta: { node_id: nodeId } }), }), }); } async getLocalVariables(fileKey: string) { return this.request<FigmaVariablesResponse>( `/v1/files/${fileKey}/variables/local` ); } }
typescript// src/figma-errors.ts export class FigmaApiError extends Error { constructor(public status: number, public body: string) { super(`Figma API error ${status}: ${body}`); this.name = 'FigmaApiError'; } } export class FigmaRateLimitError extends FigmaApiError { constructor(public retryAfterSeconds: number) { super(429, `Rate limited. Retry after ${retryAfterSeconds}s`); this.name = 'FigmaRateLimitError'; } } export class FigmaAuthError extends FigmaApiError { constructor(message: string) { super(403, message); this.name = 'FigmaAuthError'; } } export class FigmaNotFoundError extends FigmaApiError { constructor(path: string) { super(404, `Resource not found: ${path}`); this.name = 'FigmaNotFoundError'; } }
typescript// src/figma-types.ts export interface FigmaNode { id: string; name: string; type: string; children?: FigmaNode[]; fills?: Paint[]; strokes?: Paint[]; absoluteBoundingBox?: { x: number; y: number; width: number; height: number }; characters?: string; // TEXT nodes style?: TypeStyle; // TEXT nodes componentId?: string; // INSTANCE nodes backgroundColor?: Color; // CANVAS nodes } export interface FigmaFileResponse { name: string; lastModified: string; version: string; thumbnailUrl: string; document: FigmaNode; components: Record<string, ComponentMeta>; styles: Record<string, StyleMeta>; } export interface FigmaNodesResponse { nodes: Record<string, { document: FigmaNode; components: Record<string, ComponentMeta> }>; } export interface FigmaImagesResponse { images: Record<string, string | null>; // nodeId -> URL (null = render failed) } export interface ImageOptions { format?: 'png' | 'svg' | 'jpg' | 'pdf'; scale?: number; // 0.01 to 4. SVG always exports at 1x. } interface Paint { type: string; color?: Color; opacity?: number } interface Color { r: number; g: number; b: number; a?: number } interface TypeStyle { fontFamily: string; fontSize: number; fontWeight: number } interface ComponentMeta { key: string; name: string; description: string } interface StyleMeta { key: string; name: string; style_type: 'FILL' | 'TEXT' | 'EFFECT' | 'GRID' }
typescript// Walk the Figma document tree with a visitor pattern function walkNodes(node: FigmaNode, visitor: (n: FigmaNode) => void) { visitor(node); if (node.children) { for (const child of node.children) { walkNodes(child, visitor); } } } // Example: find all TEXT nodes function findTextNodes(root: FigmaNode): FigmaNode[] { const results: FigmaNode[] = []; walkNodes(root, (n) => { if (n.type === 'TEXT') results.push(n); }); return results; } // Example: find all COMPONENT nodes function findComponents(root: FigmaNode): FigmaNode[] { const results: FigmaNode[] = []; walkNodes(root, (n) => { if (n.type === 'COMPONENT') results.push(n); }); return results; }
typescript// Singleton instance with automatic retry on transient errors let client: FigmaClient | null = null; export function getFigmaClient(): FigmaClient { if (!client) { client = new FigmaClient(process.env.FIGMA_PAT!); } return client; } export async function withRetry<T>( fn: () => Promise<T>, maxRetries = 3 ): Promise<T> { for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await fn(); } catch (err) { if (err instanceof FigmaRateLimitError) { await new Promise(r => setTimeout(r, err.retryAfterSeconds * 1000)); continue; } if (attempt === maxRetries) throw err; await new Promise(r => setTimeout(r, 1000 * Math.pow(2, attempt))); } } throw new Error('Unreachable'); }
| Pattern | Use Case | Benefit | |---------|----------|---------| | Typed errors | catch (e) { if (e instanceof FigmaRateLimitError) } | Targeted recovery | | Node walker | Traversing arbitrarily deep trees | Handles any file structure | | Retry wrapper | Transient 429/5xx errors | Automatic recovery | | Singleton | Shared client across modules | Consistent config, one token |
Use the typed client (Step 1) with the custom error classes (Step 2) — call sites stay clean:
typescriptimport { FigmaClient, FigmaRateLimitError, FigmaAuthError } from './figma'; const figma = new FigmaClient(process.env.FIGMA_PAT!); try { const file = await figma.getFile(process.env.FIGMA_FILE_KEY!, { depth: 1 }); console.log(`${file.name} — ${file.document.children.length} pages`); } catch (err) { if (err instanceof FigmaRateLimitError) scheduleRetry(err.retryAfterSeconds); else if (err instanceof FigmaAuthError) alertOps('figma token invalid'); else throw err; }
Count every TEXT node with the tree walker (Step 4) instead of hand-rolled recursion:
typescriptconst textCount = walkNodes(file.document, (n) => n.type === 'TEXT').length;
Full type definitions and the retry-wrapped singleton: references/type-definitions.md, references/singleton-with-retry.md.
Apply patterns in figma-core-workflow-a for real-world file inspection.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 25,455 | 28,550 | +12% | 1 | 1 | 0% | 5,888 | 8,449 | +43% | 0 | 0 | — |
case-02 | fail→fail | 25,838 | 19,800 | -23% | 1 | 1 | 0% | 4,402 | 6,813 | +55% | 0 | 0 | — |
case-03 | fail→pass | 28,259 | 16,522 | -42% | 1 | 1 | 0% | 6,085 | 5,863 | -4% | 0 | 0 | — |
case-04 | pass→pass | 15,968 | 20,492 | +28% | 1 | 1 | 0% | 3,432 | 6,016 | +75% | 0 | 0 | — |
case-05 | pass→pass | 13,304 | 13,593 | +2% | 1 | 1 | 0% | 2,749 | 5,285 | +92% | 0 | 0 | — |
case-06 | pass→pass | 11,997 | 11,645 | -3% | 1 | 1 | 0% | 2,337 | 4,810 | +106% | 0 | 0 | — |
case-07 | pass→pass | 9,706 | 119,249 | +1129% | 1 | 1 | 0% | 1,566 | 3,212 | +105% | 0 | 0 | — |
case-08 | pass→pass | 8,307 | 3,894 | -53% | 1 | 1 | 0% | 1,291 | 2,933 | +127% | 0 | 0 | — |
case-09 | fail→pass | 743,443 | 11,396 | -98% | 1 | 1 | 0% | 3,365 | 4,222 | +25% | 0 | 0 | — |
case-10 | fail→pass | 6,357 | 2,828 | -56% | 1 | 1 | 0% | 834 | 2,822 | +238% | 0 | 0 | — |
case-11 | fail→pass | 7,813 | 2,320 | -70% | 1 | 1 | 0% | 1,333 | 2,847 | +114% | 0 | 0 | — |
case-12 | pass→pass | 9,977 | 7,821 | -22% | 1 | 1 | 0% | 1,927 | 3,944 | +105% | 0 | 0 | — |
case-13 | fail→pass | 4,390 | 3,251 | -26% | 1 | 1 | 0% | 764 | 3,078 | +303% | 0 | 0 | — |
case-14 | fail→fail | 10,098 | 4,468 | -56% | 1 | 1 | 0% | 1,982 | 3,144 | +59% | 0 | 0 | — |
case-15 | pass→pass | 9,925 | 7,531 | -24% | 1 | 1 | 0% | 1,989 | 3,952 | +99% | 0 | 0 | — |
case-16 | pass→pass | 4,186 | 2,342 | -44% | 1 | 1 | 0% | 712 | 2,741 | +285% | 0 | 0 | — |
case-17 | pass→pass | 11,664 | 9,032 | -23% | 1 | 1 | 0% | 2,172 | 4,185 | +93% | 0 | 0 | — |
case-18 | fail→pass | 10,123 | 6,855 | -32% | 1 | 1 | 0% | 1,844 | 3,655 | +98% | 0 | 0 | — |
case-19 | pass→pass | 9,637 | 5,329 | -45% | 1 | 1 | 0% | 1,869 | 3,390 | +81% | 0 | 0 | — |
case-20 | pass→pass | 13,063 | 8,255 | -37% | 1 | 1 | 0% | 2,360 | 3,759 | +59% | 0 | 0 | — |
case-21 | fail→pass | 6,869 | 2,187 | -68% | 1 | 1 | 0% | 1,225 | 2,751 | +125% | 0 | 0 | — |
case-22 | fail→fail | 20,001 | 13,964 | -30% | 1 | 1 | 0% | 3,968 | 4,960 | +25% | 0 | 0 | — |
case-23 | pass→pass | 3,463 | 2,537 | -27% | 1 | 1 | 0% | 570 | 2,809 | +393% | 0 | 0 | — |
case-24 | pass→pass | 4,420 | 1,952 | -56% | 1 | 1 | 0% | 725 | 2,740 | +278% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 24 cases were attempted. The headline lift of +33 percentage points is the difference between those two pass rates over the 24 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.