measuring-text — Claude Code rule: text dimensions in Remotion
measuring-text — a rule to calculate text size, fit fonts to containers, and detect overflow. Use it when building dynamic text in Remotion and need precise dimensions to avoid clipping or wrong scaling.
no license ★ 849 updated 2026-01-24
.claude/rules/measuring-text.mdWhat measuring-text does
The rule brings @remotion/layout-utils functions into your Claude Code workflow: measureText() computes text width and height for a given font and size, fitText() finds the right font size to fit text within a width limit, fillTextBox() tracks whether text exceeds a box as you add words line by line.
Three examples cover the main scenarios: measuring a single string, scaling text to fit a container with a maximum size, and adding words one at a time while checking for overflow. Measurement results are cached, so repeated calls are fast.
Fonts must be loaded before measuring—otherwise results won't match the rendered output. The rule shows how to load fonts from Google Fonts and enable validation with validateFontIsLoaded. Font properties like size, weight, and letter spacing must stay consistent between measurement and render, or numbers and visuals will diverge.
What it helps with
- calculate text dimensions with a specific font and weight
- find the right font size to fit text in a fixed width
- check if text exceeds a box by width or line count
- build text line by line and stop before overflow
Example prompts for the agent
- Get the height of the text 'Final frame' in Arial 24
- Fit a product description into 500 pixels wide by picking the best font size
- Verify that 3 lines of copy fit in a 400×600 box at size 18
How to install measuring-text
Manually: put the files in place
.claude/rules/measuring-text.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/measuring-text.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/measuring-text.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/measuring-text.mdManually: put the files in place
.clinerules/measuring-text.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about measuring-text
How do I install measuring-text in Claude Code?
Copy the rule content to .claude/rules/measuring-text.md at your project root. For Cursor, use .cursor/rules/measuring-text.mdc. Other editors use their own paths—check the install docs.
What does this rule do?
It adds Remotion text measurement functions to Claude Code: measureText() gets text size, fitText() scales font to fit a width, fillTextBox() tracks overflow as you add text. Results cache for speed.
Why do I need to load fonts before measuring?
Font metrics change based on which font file is loaded. Measure before fonts load and your numbers won't match the rendered output. Use waitUntilDone() or validateFontIsLoaded: true to catch timing issues.