Skip to content

feat(docs): read this guide one section at a time - #41

Open
clementcopper wants to merge 1 commit into
silships:mainfrom
clementcopper:feat/docs-topics
Open

feat(docs): read this guide one section at a time#41
clementcopper wants to merge 1 commit into
silships:mainfrom
clementcopper:feat/docs-topics

Conversation

@clementcopper

Copy link
Copy Markdown

Where the tokens actually go

The README makes the case that figma-cli costs an agent far fewer tokens than an API-based MCP. Measuring a session end to end, the commands hold up their side — but the guide dominates everything:

Item Tokens When
CLAUDE.md (the guide) ~10,200 every session that follows "read the guide first"
REFERENCE.md ~6,100 on demand
canvas info / var list / find 40–500 each per call
verify (PNG on disk, not base64) ~40 per call

So the per-command work is already lean, and verify writing the PNG to disk instead of inlining base64 was the right call. What's left is the guide: an agent pays ~10k tokens up front even when the task is "render one frame" and it needs the JSX section and nothing else.

The change

figma-cli docs <topic> prints one ## section. figma-cli docs lists what's available with each topic's cost:

$ figma-cli docs

  CLAUDE.md — 19 topics, ~10,211 tokens in full

  quick-reference               1456 tok  Quick Reference
  key-rules                     1851 tok  Key Rules
  jsx-syntax                     924 tok  JSX Syntax (render command)
  critical-pitfalls              917 tok  Critical Pitfalls
  motion                         927 tok  Motion (Figma Animation, Config 2026 Beta)
  …

Measured against reading the whole guide:

Task Topics needed Tokens Saved
render a component jsx-syntax + critical-pitfalls 1,850 −82%
general session start key-rules + quick-reference 3,317 −68%
add an animation motion 932 −91%
set up validation deterministic-validation 722 −93%

Behavioural details:

  • Ranked matching — exact slug, then whole word (plural-tolerant), then substring, then heading text. jsx, jsx-syntax and render all reach the JSX section.
  • Ambiguity is reported, not guessed. docs token matches both Design Tokens and Token Hygiene, so it lists both and exits 1 rather than silently picking one.
  • Pipes cleanly — the section goes to stdout, listings and errors to stderr, so figma-cli docs jsx-syntax > /tmp/jsx.md works.
  • --file <path> overrides the guide location; without it the command looks for docs/FIGMA-USAGE.md first, then CLAUDE.md, so a checkout that keeps a short CLAUDE.md for repo instructions still works.

Two bullets in the guide point at it: one in Token Hygiene, one in Other Commands.

Implementation

Splitting and matching are pure functions in src/lib/doc-sections.js, following the browserDebugArgs / connect-plan pattern, with 10 unit tests in tests/doc-sections.test.js — no disk access, no Figma. src/commands/docs.js only does I/O, and src/lib/command-map.js gains the two lines the lazy loader needs (tests/lazy-command-map.test.js enforces that).

npm test → 531 passing.

Notes

### subsections deliberately stay inside their parent topic — they're detail of that topic, not topics of their own. If you'd rather have deeper granularity, or different topic names than the auto-slugs, both are a small change.

CLAUDE.md is ~10,200 tokens. An agent that follows "read the guide first"
pays that on every session, even when the task needs one 930-token
section — and it is by far the largest fixed cost in a figma-cli session,
since the commands themselves return 40-500 tokens each.

`figma-cli docs` lists the 19 topics with their token cost; `figma-cli
docs <topic>` prints one. Matching is ranked (exact slug, whole word,
substring, heading text) and reports ambiguity instead of guessing:
"token" names both Design Tokens and Token Hygiene, so it lists both.
Section text goes to stdout so it pipes; listings and errors to stderr.

Splitting and matching are pure functions in src/lib/doc-sections.js with
10 unit tests. The guide is found by convention (docs/FIGMA-USAGE.md,
then CLAUDE.md), overridable with --file, so a checkout that keeps a
short CLAUDE.md for repo instructions still works.

Measured against the full guide (~10,283 tok):

  jsx-syntax + critical-pitfalls    1,850 tok   -82%
  key-rules + quick-reference       3,317 tok   -68%
  motion                              932 tok   -91%
  deterministic-validation            722 tok   -93%

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clementcopper added a commit to clementcopper/figma-claude that referenced this pull request Sep 3, 2026
Seven branches became one on 2026-09-03. The skill's first line still said the
default was v2, and it is the file you read right before merging from upstream.

What the cleanup was based on: `feat/swift-host` was v2 plus 26 commits with v2
fully contained, the only tree difference being `swift-host/`, and `app/` sitting
in both. The Electron app is a directory, not a branch — `make-app.sh` reads
`app/build/icon.icns` — so a second branch beside the trunk would have been a
copy of the same CLI falling behind. v2 had stood still since 22.08.

`v2` and `archive/draft-v1` are now the tags `v2-final` and `draft-v1`. The four
PR branches stay on origin because deleting them there closes PRs silships#40, silships#41, silships#43
and silships#44; that is written down so nobody tidies them away later.

Also noted: CI triggers on `branches: [main]`, which this fork has never had, so
it has never run on a push here. Left alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QuvZuDad3hi3CVwNDbTvr2
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.

1 participant