Keep this file, AGENTS.md, up to date when Storybook's architecture, tooling, workflows, or contributor guidance changes.
This file is the canonical instruction source for coding agents. Files like CLAUDE.md should point here instead of duplicating instructions.
Storybook is a large TypeScript monorepo. The git root is the repo root, the main code lives in code/, and build tooling lives in scripts/. The default branch is next.
- Base branch:
next(all PRs should targetnext, notmain) - Node.js:
22.21.1(see.nvmrc) - Package Manager: Yarn Berry
- Task orchestration: NX plus the custom
yarn taskrunner - CI environment: Linux and Windows
storybook/
├── .github/ # GitHub configs and workflows
├── .nx/ # NX workflow state
├── code/ # Main codebase
│ ├── .storybook/ # Internal Storybook UI config
│ ├── core/ # Core package published as "storybook"
│ ├── addons/ # Core addons
│ ├── builders/ # Builder integrations
│ ├── renderers/ # Renderer integrations
│ ├── frameworks/ # Framework integrations
│ ├── lib/ # Supporting libraries
│ ├── presets/ # Webpack-oriented presets
│ └── sandbox/ # Internal build artifacts
├── scripts/ # Build and development scripts
├── docs/ # Documentation
├── test-storybooks/ # Test repos
└── ../storybook-sandboxes/ # Generated sandboxes outside repo
| Concept | Role | Example |
|---|---|---|
| Renderer | Mounts UI framework to the DOM | @storybook/react |
| Builder | Bundles and serves Storybook | @storybook/builder-vite |
| Framework | Renderer + builder + framework config | @storybook/react-vite |
The main package is code/core/src/. The most important areas are:
core-server/for dev server, static build, and presetsmanager/andmanager-api/for the Storybook UIpreview/andpreview-api/for story renderingchannels/for manager <-> preview communicationcsf-tools/for AST-based story indexingcommon/for shared Node.js utilitiestest/andinstrumenter/for testing support
Public exports include:
storybook/actionsstorybook/preview-apistorybook/manager-apistorybook/themingstorybook/test
Internal exports include:
storybook/internal/core-serverstorybook/internal/csf-toolsstorybook/internal/commonstorybook/internal/channels
.storybook/main.tsis loaded at startup.storybook/preview.tsis bundled into preview.storybook/manager.tsis bundled into manager*.stories.*files are indexed by AST before runtime- Story selection loads the module, prepares the story, and renders it
AST indexing keeps the sidebar fast and prevents one broken story file from breaking the whole UI.
Run commands from the repository root unless stated otherwise.
For routine agent work, prefer the faster non-production commands first. Add -c production only when you need sandbox-related NX tasks or you are explicitly matching CI behavior.
yarn
yarn task compile
yarn nx run-many -t compile
yarn nx compile <package-name>yarn lint
yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fix
yarn task check
yarn nx run-many -t checkcd code && yarn storybook:ui
cd code && yarn storybook:ui:build
yarn test
yarn test:watch
yarn storybook:vitest| Scenario | Command |
|---|---|
| Compile everything quickly | yarn nx run-many -t compile |
| Compile one package | yarn nx compile <package-name> |
| Check TypeScript errors quickly | yarn nx run-many -t check |
| Start the internal Storybook UI | cd code && yarn storybook:ui |
| Build the internal Storybook UI | cd code && yarn storybook:ui:build |
| Run unit tests | yarn test |
| Run Storybook Vitest tests | yarn storybook:vitest |
| Generate a sandbox | yarn task sandbox --template react-vite/default-ts --start-from auto |
| Run sandbox E2E tests | yarn task e2e-tests-dev --template react-vite/default-ts --start-from auto |
| Run sandbox test-runner tests | yarn task test-runner-dev --template react-vite/default-ts --start-from auto |
Use NX when you want better caching and dependency tracking. Prefer these faster defaults first, and only add -c production or --no-link when you specifically need sandbox parity or CI-like behavior.
# Compile all packages
yarn task compile
yarn nx run-many -t compile
# Check all packages
yarn task check
yarn nx run-many -t check
# Run E2E tests for a template
yarn task e2e-tests-dev --template react-vite/default-ts --start-from auto
yarn nx e2e-tests-dev react-vite/default-ts -c production
# Jump to a later step
yarn task e2e-tests-dev --start-from e2e-tests --template react-vite/default-ts
yarn nx e2e-tests-dev -c production --exclude-task-dependenciesKey points:
-c productionis required for sandbox-related NX commands and CI-parity runsreact-vite/default-tsis the default sandbox template--no-linkis opt-in, not the default- NX handles task dependencies via
nx.json
Sandboxes are generated outside the repository at ../storybook-sandboxes/ by default.
STORYBOOK_SANDBOX_ROOT=./sandboxforces local output, but is usually not preferred./sandboxinside the repo mainly exists for NX outputs, not CI sandboxes- If sandbox generation fails, fall back to
cd code && yarn storybook:ui
Generate and use a sandbox with the same sandbox command shape used elsewhere in this file:
yarn task sandbox --template react-vite/default-ts --start-from auto
# Same sandbox step via NX
yarn nx sandbox react-vite/default-ts -c production
cd ../storybook-sandboxes/react-vite-default-ts
yarn install
yarn storybookCommon templates:
react-vite/default-tsreact-webpack/default-tsangular-cli/default-tssvelte-vite/default-tsvue3-vite/default-tsnextjs/default-ts
- Install if needed:
yarn - Compile with NX:
yarn nx run-many -t compile - Make changes
- Recompile affected packages
- Validate there are no TypeScript errors with
yarn nx run-many -t check - Run relevant lint and tests
- Validate behavior in the internal Storybook UI first, then switch to sandbox or
-c productionflows only if you need template or CI parity
- Edit the relevant package under
code/addons/,code/frameworks/, orcode/renderers/ - Recompile with NX, starting without
-c production - Generate a matching sandbox
- Run the relevant test-runner, E2E, or Storybook UI validation flow
- Use
yarn testfor unit tests - Use Storybook UI or Chromatic for visual validation
- Use
yarn task e2e-tests --start-from autooryarn task e2e-tests-dev --start-from autofor E2E coverage - Use
yarn task test-runner --start-from autooryarn task test-runner-dev --start-from autofor test-runner scenarios - Use
yarn task smoke-test --start-from autofor smoke checks
Watch-mode commands:
yarn test:watch
yarn storybook:vitestWhen writing tests:
- Export functions that need direct tests
- Test real behavior, not just syntax patterns
- Use coverage when useful:
yarn vitest run --coverage <test-file> - Mock external dependencies like file system access and loggers
After changing files:
- Format with
cd code && oxfmt - Lint with
yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fixorcd code && yarn lint:js:cmd <file-relative-to-code-folder> - Run relevant tests before submitting a PR
Use Storybook loggers instead of raw console.* in normal code paths:
- Server-side:
storybook/internal/node-logger - Client-side:
storybook/internal/client-logger
Avoid console.log, console.warn, and console.error unless the file is isolated enough that importing the logger is not reasonable.
- Build failures are often fixed by rerunning
yarnandyarn nx run-many -t compile - Storybook UI uses port
6006by default - Large compiles may require more Node.js memory
- Sandbox paths are
../storybook-sandboxes/, not./sandboxorcode/sandbox/ - Use
--debugfor verbose CLI output - Check generated sandbox directories and
.cache/for build artifacts
| Variable | Purpose |
|---|---|
IN_STORYBOOK_SANDBOX |
Set during sandbox creation |
STORYBOOK_DISABLE_TELEMETRY |
Disable telemetry |
STORYBOOK_TELEMETRY_DEBUG |
Log telemetry events |
DEBUG |
Enable debug logging |
- DO NOT RUN
yarn task devwithout an explicit sandbox template - DO NOT RUN
yarn start
These usually start long-running development servers and are the wrong default for agents.
- Use this file as the canonical instruction source
- Update
AGENTS.mdwhen architecture, commands, versions, release flows, or contributor guidance changes - Keep
CLAUDE.mdand other agent entrypoints as thin references toAGENTS.md - Do not reintroduce duplicated instruction files when a reference will do