Join live: Storybook 11 AMA with the team
Docs
Storybook Docs

Set up Storybook with an agent

Your agent can add Storybook to your project, configure it to render your components, and write the first stories. Configuring Storybook for an existing app is repetitive, project-specific work, and agents do it well.

The setup skill needs the Vite builder, so it isn't available for every framework. See supported frameworks to check yours.

Set up Storybook

Copy this prompt into your agent's chat:

Set up Storybook for me with npm create storybook@latest (or pnpm --allow-build=esbuild create storybook@latest if this project uses pnpm, or yarn create storybook@latest if it uses yarn) and follow its instructions precisely

The agent runs storybook init, which adds Storybook and installs the skills. Then the agent follows the instructions from the /storybook-setup skill to configure Storybook for your project.

If Storybook is already installed, ask your agent to "Use the /storybook-setup skill". If your project uses a version of Storybook older than 11, the agent asks you before it upgrades.

What the agent does

The setup skill gives your agent instructions for your framework, renderer, language, and package manager. The agent:

  1. Studies your app: reads your entry file, providers, global CSS, data fetching, and portals.
  2. Configures the preview: adds your providers as decorators and imports your global styles.
  3. Adds portal roots: if your components render into portals, it adds the root elements in a decorator.
  4. Mocks only what stories need: it adds MSW only if a story makes network requests, and MockDate only if a story depends on the current date.
  5. Writes stories: up to 10 story files, from simple components to pages. It adds a story to an existing story file instead of writing a second one.
  6. Adds play functions where they prove something: interactions, async data, portals, and accessibility. Stories that only show a variant get no play function.
  7. Tests the stories: runs Vitest on all new stories and fixes the failures, then runs your type checker.
  8. Cleans up: removes debug code and the example stories that storybook init added.

The agent changes your existing stories, components, and configuration only to add to them. It doesn't delete or rewrite them.

Check the result

The agent tags each story file it writes:

  • ai-generated: the agent wrote this file.
  • needs-work: the agent couldn't make the stories in this file pass. Fix them yourself or ask your agent to try again.

The agent also adds one CssCheck story. Its play function checks a computed style from your components, which proves that the preview loads your styles.

Then:

  • Run Storybook and look at the new stories.
  • Check the main and preview configuration files.
  • Remove the ai-generated tag from each story file after you review it.

Next steps

Supported frameworks

The setup skill is available for these frameworks:

RendererFrameworks
Reactreact-vite, nextjs-vite, tanstack-react
Vue 3vue3-vite
Angularangular-vite

For other frameworks, install Storybook yourself. To see which frameworks the other skills support, see Connect your agent.

More AI resources