figma-messages

figma-messages is a cursor rule for Cursor from hoshikitsunoda/figma-plugins-vibe-coding-template. It costs 0 tokens per session (562 once invoked), scanned A, original, MIT.

A message-based communication rule for a Figma plugin's user interface and sandbox, the isolated part that runs plugin code.

In plain words
What is it for?
Use it to define messages for reading selections, creating or updating objects, reporting readiness, and sending errors.
Why use it?
It keeps communication predictable and type-checked, while avoiding direct references that cannot be sent between the two environments.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it to define messages for reading selections, creating or updating objects, reporting readiness, and sending errors.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-messages
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/hoshikitsunoda/figma-plugins-vibe-coding-template

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for figma-messages

README.md
[![agentmods](https://agentmods.dev/badge/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-messages.svg)](https://agentmods.dev/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-messages)
Your own site
<a href="https://agentmods.dev/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-messages"><img src="https://agentmods.dev/badge/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-messages.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 562 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00562
Opus 5 $0.00000 $0.00281
Sonnet 5 $0.00000 $0.00112
Haiku 4.5 $0.00000 $0.00056

Measured 8d ago against content hash 8d468dcfb2e3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

figma-messages scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/figma-messages.mdc · 95 lines

How it starts

The opening of the file, as written. The whole thing — 95 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Figma Plugin Message Protocol

Messages are the only way to communicate between the plugin sandbox and UI iframe.

Message Type Definitions

Define all messages in src/shared/messages.ts using discriminated unions:

/**
 * Messages sent from UI thread to Main thread (plugin sandbox)
 */
export type PluginMessage =
  | { type: "get-selection" }
  | { type: "create-rectangle"; width: number; height: number }
  | { type: "update-node"; nodeId: string; properties: NodeProperties };

/**
 * Messages sent from Main thread to UI thread
 */
export type UIMessage =
  | { type: "selection-changed"; nodes: SelectionNode[] }
  | { type: "plugin-ready" }
  | { type: "error"; message: string };

Design Principles

1. Use Discriminated Unions

The type field enables type-safe message handling:

// TypeScript narrows the type based on msg.type
switch (msg.type) {
  case "create-rectangle":
    // msg is now typed as { type: 'create-rectangle'; width: number; height: number }
    createRect(msg.width, msg.height);
    break;
}

2. Serialize Data, Not References

Never include Figma node references in messages:

// ❌ BAD - node references can't be serialized
{ type: 'node-selected', node: figma.currentPage.selection[0] }

// ✓ GOOD - plain data only
{ type: 'node-selected', nodeId: '1:23', name: 'Frame 1', width: 100 }

3. Keep Payloads Small

Only send the data you need:

// ❌ BAD - sending entire node tree
{ type: 'document-data', root: serializeEntireDocument() }

// ✓ GOOD - send only what UI needs
{ type: 'frame-list', frames: frames.map((f) => ({ id: f.id, name: f.name })) }

4. Define Serialized Types

Create interfaces for serialized node data:

/**
 * Serialized node data safe for postMessage
 */
export interface SelectionNode {
  id: string;
  name: string;
  type: string;
  width: number;
  height: number;
}

Adding New Messages

When adding a new message type:

Read the full file on GitHub · 95 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 95 lines · 0 tokens per session scan A 8d468dcfb2e3

Subscribe to this mod's changes

figma-messages is a cursor rule published in the GitHub repository hoshikitsunoda/figma-plugins-vibe-coding-template (21 stars, last pushed 8mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 562 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.