Skip to content

feat(safe-mode): drive two open files at once, one daemon per session - #61

Closed
vfragkoulopoulou wants to merge 1 commit into
silships:mainfrom
vfragkoulopoulou:multi-session-ports
Closed

vfragkoulopoulou wants to merge 1 commit into
silships:mainfrom
vfragkoulopoulou:multi-session-ports

Conversation

@vfragkoulopoulou

Copy link
Copy Markdown

The problem

In Safe Mode every CLI session talks to the same daemon on port 3456, and that daemon holds one FigCli connection. With two files open and FigCli started in both, whichever window connected last takes over. The other session's commands then go silently to the wrong file. FIGMA_FILE doesn't help because it only applies to CDP.

A common case is two agent sessions open side by side, one per file (e.g. reading components from a library file while building in another). Today you have to close FigCli in one file before working in the other.

What this does

  • DAEMON_PORT (3456–3460) picks the daemon port in the CLI. Each port has its own PID file and token. With no DAEMON_PORT, paths and behaviour are unchanged.
  • The daemon turns away a FigCli window from a different file while it already serves a live one (busy). The window then tries the next port. A reconnect from the same window (same instance id) is accepted, and a connection that has gone stale (no ping for 10s) can be replaced.
  • FigCli tries ports in order and joins the first free one. It shows the port it's on. If every running daemon is busy, it keeps waiting and offers a Take over button (claim: true), which replaces the current connection deliberately.
  • Backwards compatible both ways. A plugin without an instance id keeps the old last-one-wins behaviour. A new plugin talking to an old daemon treats silence after connect as accepted.
  • figma-cli status shows which file the session is connected to (pluginFile in /health, kept separate from file so the FIGMA_FILE pin check never restarts a plugin daemon).
  • Fix: closing a replaced socket no longer clears the active plugin connection.

Usage

# session 1: unchanged (3456)
# session 2:
DAEMON_PORT=3457 figma-cli status

Then start FigCli in each file.

Testing

  • npm test: 549 passing.
  • Simulated plugins on two daemons: busy hand-off, same-window reconnect, take over, and parallel eval routed to the right file.
  • Live on Figma Desktop (macOS) with two files open: eval figma.root.name and canvas info run at the same moment on 3456 and 3457 each returned their own file.

🤖 Generated with Claude Code

… once

DAEMON_PORT (3456-3460) now picks the daemon port in the CLI, with a per-port
PID file and token. The daemon turns away a FigCli window from another file
while it serves a live one, so the window moves to the next free port; a
claim (Take over button) still replaces it. Plugins without an instance id
keep the old last-one-wins behaviour. status shows the connected file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silships

Copy link
Copy Markdown
Owner

Thank you for this! I am holding it back for now. It changes Safe Mode for people with only one open file too: a second FigCli window no longer takes over and shows a Take over button instead. I want to test that with two files first. figma-cli connect also defaults to Browser Mode now, where FIGMA_FILE pins the file. Happy to look at a rebased version

@silships silships closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants