Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

ask-sonner — Claude Code skill: Sonner toast setup and fixes

A guide skill for Sonner, the React toast library: mount the Toaster, pick the right toast() call, style it, fix what breaks.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add emilkowalski/skills --skill ask-sonner -a claude-code
Open on GitHub

What ask-sonner does

The skill covers the two moving parts of Sonner and nothing else: one ` mounted once near the root (layout.tsx in Next.js), plus toast() called from client code. Then a table for choosing the call — plain message, toast.success, toast.loading when you track state yourself, toast.promise with loading/success/error, action and cancel buttons, custom JSX via toast.custom. Server actions get a warning: toast()` is client-only, so return the result and fire the toast where it lands.

Recipes follow: update a toast by passing the same id, keep it open with duration: Infinity, dismiss one or all, read the active list from useSonner() or toast.getActiveToasts(), target a specific toaster with toasterId, and remember onDismiss and onAutoClose are separate hooks. Styling is a ladder: richColors and invert first, then inline style, then classNames where every class needs !important (Tailwind: !text-red-900), then headless with toast.custom. Prop tables live in API.md next to the skill.

Its best section is the troubleshooting table: toasts that never appear, appear twice, render unstyled, ignore Tailwind, hide behind a modal, skip dark mode (theme defaults to 'light'), or hang on loading. On first invocation the skill answers with one line and waits for your question. Worth installing if Sonner is already in your stack or you're about to add it. Skip it if you need product-level guidance on notifications in general.

What it helps with

  • Mount a single Toaster at the root instead of one per page
  • Drive a loading → success toast from a promise
  • Fix a toast that never fires after a server action
  • Rebuild toasts against your own design system with toast.custom
  • Make toasts follow the app's dark theme

Example prompts for the agent

  • Wire up Sonner in `app/layout.tsx` and show a toast after the form saves
  • My toast doesn't appear after a server action. Why?
  • Rewrite our toasts with `toast.custom` using design-system styles

How to install ask-sonner

1Skills CLI (Vercel)

npx skills add emilkowalski/skills --skill ask-sonner -a claude-code

2Manually: put the files in place

~/.claude/skills/ask-sonner/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/ask-sonner/

From the same set15

The whole set →
emil-design-eng emilkowalski This skill guides UI polish, component details, and animation choices. Use it when an interface works but its states and transitions need closer review. Claude Code CX Codex Cursor +1 385,500installs review-animations emilkowalski Reviews UI animation and motion code against Emil Kowalski's design standards. Flags slow easings, non-GPU properties, and unnecessary transitions. Claude Code CX Codex Cursor +1 254,100installs apple-design emilkowalski Translates Apple's fluid interface principles from WWDC talks into web code with Pointer Events and spring physics. Essential for gesture-driven sheets, drags, and sliders. Claude Code CX Codex Cursor +1 242,100installs animation-vocabulary emilkowalski This skill maps a vague web animation description to the right term. Use it when you need wording for an AI prompt or a designer. Claude Code CX Codex Cursor +1 236,900installs improve-animations emilkowalski Surveys motion and animation code across your project, then generates self-contained fix plans. It spots janky keyframes and poor easing without altering source files. Claude Code CX Codex Cursor +1 222,000installs find-animation-opportunities emilkowalski Scans a codebase or UI for motion that would clarify states and interactions, while rejecting decoration that gets in the way. It is read-only. Claude Code CX Codex Cursor +1 206,800installs pick-ui-library emilkowalski A skill that maps a frontend task to one library from Emil Kowalski's curated list: toasts, charts, OTP fields, virtualization, drag and drop. Runs only when you call it. Claude Code CX Codex Cursor +1 183,400installs prototype emilkowalski The skill builds several genuinely different versions of one piece of UI and puts them behind a visual picker, so you flip through them live and keep the one that feels right. Claude Code CX Codex Cursor +1 172,400installs

Similar

migrate-radix-to-base shadcn-ui Migrates React components and full projects from Radix UI to Base UI (@base-ui/react). Useful when switching the underlying primitives in shadcn/ui projects. Claude Code CX Codex Cursor +1 30,100installs hallmark Nutlope Enforces strict frontend design constraints to stop coding assistants from producing generic, AI-looking web pages. Claude Code CX Codex Cursor +1 69,100installs design-system claudekit This skill builds design tokens, component specs, and presentation slides. Use it when an interface and its slides need to follow one visual system. Claude Code CX Codex Cursor +1 42,200installs remotion-best-practices remotion-dev Routes Remotion tasks to focused guidance for video creation, React markup, maps, multimedia, previews, and rendering. Claude Code CX Codex Cursor +1 678,800installs frontend-design official anthropics This skill guides intentional visual design for new interfaces and redesigns. Use it when a generic generated UI is not enough. Claude Code Claude.ai 1,025,790installs design-taste-frontend Leonxlnx This skill directs the design of public pages and work screens, then checks the result in a browser through screenshots. Use it when an interface feels generic or unfinished. Claude Code CX Codex Cursor +1 673,100installs prototype Matt Pocock Creates throwaway prototypes for checking state logic or exploring UI before committing the decision to the main codebase. Claude Code 986,201installs hyperframes heygen-com Instructs coding agents on creating, validating, and rendering HTML-based videos using the HyperFrames framework and CLI. Claude Code CX Codex Cursor +1 1,200,000installs

Questions about ask-sonner

How do I install ask-sonner in Claude Code?

Run npx skills add emilkowalski/skills --skill ask-sonner -a claude-code. The skill file lands at ~/.claude/skills/ask-sonner/SKILL.md.

What does ask-sonner do?

It answers Sonner questions: mounting the Toaster, choosing between toast(), toast.promise and toast.custom, updating or dismissing toasts, styling them, and diagnosing why one misbehaves.

Why does the same toast show up twice?

Usually two ` instances are mounted, or toast() sits in an effect that React StrictMode double-invokes in dev. Call it from the event handler instead, or pass a stable id` so the second call updates the existing toast rather than adding another.

Source text

SKILL.md · MIT
---
name: ask-sonner
description: Guide to Sonner, the React toast library — install and wire up the Toaster, pick the right toast() call, promise and loading toasts, updating, dismissing and persisting toasts, styling, theming and icons, positioning and multiple toasters. Use when working with Sonner or troubleshooting it — toasts that don't appear, appear twice, lose their styles, ignore Tailwind classes, sit behind a modal, or don't follow dark mode.
---

# Working With Sonner

## Initial Response

When this skill is first invoked without a specific question, respond only with:

> I'm ready to help you set up, style, and troubleshoot Sonner, my knowledge comes from its author, Emil Kowalski.

Do not provide any other information until the user asks a question.

A guide skill for [Sonner](https://sonner.emilkowal.ski), the toast library. When a task involves Sonner — wiring it up, rendering toasts, styling them, or fixing them — answer from this file first. Full prop tables for `<Toaster />` and `toast()` live in [API.md](API.md); read it when you need an exact prop name, type, or default.

## Setup

Two pieces, and only two:

1. **One `<Toaster />`, mounted once**, as close to the root as possible (in Next.js: `layout.tsx` — it works inside server components). Never render it per-page or conditionally; a second mounted Toaster duplicates every toast.
2. **`toast()` called from client code** — event handlers, effects, callbacks. It's a plain function, no hook or provider needed, but it does nothing on the server: in a server action, return the result and call `toast()` in the client code that receives it.

```jsx
import { Toaster } from 'sonner'; // once, in layout
import { toast } from 'sonner';   // anywhere client-side
```

## Picking the right call

| You want | Call |
| --- | --- |
| Plain message | `toast('Title')` — add `{ description }` for a second line |
| Success / error / info / warning icon | `toast.success('…')`, `toast.error('…')`, etc. |
| Spinner while you manage state yourself | `toast.loading('…')`, then update it by id |
| Loading → success/error tied to a promise | `toast.promise(promise, { loading, success, error })` — success/error accept functions receiving the resolved value/error |
| Button that does something | `{ action: { label, onClick } }` — closes the toast unless `onClick` calls `event.preventDefault()`; `cancel` is the secondary variant |
| Custom JSX, default toast shell | `toast(<jsx />)` |
| Custom JSX, no styles at all | `toast.custom((t) => <jsx />)` — headless, `t` gives you the id to dismiss |

## Recipes

**Update a toast** — call `toast()` again with the same `id`; only the props you pass change. Switching to `toast.success(…, { id })` changes the type. This is how loading → success flows work without `toast.promise`:

```jsx
const id = toast.loading('Uploading…');
toast.success('Uploaded', { id });
```

**Persist** — `{ duration: Infinity }`. **Dismiss** — `toast.dismiss(id)`, or `toast.dismiss()` for all. **Read active toasts** — `useSonner()` in React, `toast.getActiveToasts()` outside it.

**Links or components in the text** — pass a function for the title or description: `toast(() => <a href="…">View</a>)`.

**Multiple toasters** — give each an `id` and target with `toast('…', { toasterId: 'canvas' })`. Without `toasterId`, every toaster renders the toast.

**Close callbacks** — `onDismiss` fires on close button or swipe; `onAutoClose` fires on timeout. They are separate; there is no single "closed" callback.

## Styling — the escalation ladder

Climb only as far as the change requires; jumping to the top rung too early is fine (it's the recommended end state), lingering in the middle is not.

1. **Defaults** — plus `richColors` on the Toaster for colorful success/error, `invert` to flip against the theme.
2. **Inline tweaks** — `toastOptions={{ style: {…} }}` on the Toaster for all toasts, or `style` per `toast()` call.
3. **Classes on parts** — `toastOptions={{ classNames: { toast, title, description, actionButton, cancelButton, closeButton } }}`. Sonner's injected styles win the cascade, so every class needs `!important` (Tailwind: `!text-red-900`). If you're marking more than a few things important, stop — go headless.
4. **Headless** — `toast.custom()` with your own JSX, keeping Sonner's positioning, stacking, and swipe. The recommended approach for a design-system toast: wrap it in your own `toast()` abstraction. (`unstyled: true` exists as a halfway house, but headless gives more control for the same effort.)

**Icons** — swap defaults per-type with the Toaster's `icons` prop, per-toast with `icon`, remove with `null`.

**Theme** — `theme` defaults to `'light'` and does not track the OS. Pass `theme="system"`, or wire your theme provider: `<Toaster theme={resolvedTheme} />` from `next-themes`.

## Troubleshooting

| Symptom | Cause → fix |
| --- | --- |
| Toast never appears | No `<Toaster />` mounted, or it unmounted (conditional render, per-page placement). Mount one at the root. If calling from a server action: `toast()` is client-only — call it with the action's result on the client. |
| Same toast appears twice | Two Toasters mounted (layout **and** page) — keep one. Or `toast()` fired in an effect under React StrictMode's dev double-invoke — fire from the event handler instead, or pass a stable `id` so the second call updates rather than duplicates. |
| Tailwind/CSS classes have no effect | Default styles override them. Mark them `!important`, or use `unstyled` / headless (see the ladder above). |
| Toasts render completely unstyled (common in Astro, view transitions) | Sonner's injected stylesheet was lost — import it explicitly in a layout: `import 'sonner/dist/styles.css'`. |
| Unstyled inside Shadow DOM | Styles land in `document.head`, not the shadow root. Copy the style tag whose text includes `[data-sonner-toaster]` into the shadow root. |
| Toast behind a modal/overlay, or clipped | An ancestor creates a stacking context (`transform`, `filter`, `overflow`) or the overlay out-z-indexes the toaster. Move `<Toaster />` to the document root, outside any dialog/portal container. |
| Dark mode ignored | `theme` defaults to `'light'` — set `theme="system"` or pass the resolved theme (see Theme above). |
| Success/error look gray, not green/red | That's the default. Add `richColors` to the Toaster. |
| Toast never closes | `duration: Infinity`, `dismissible: false`, or a `toast.promise` whose promise never settles — the loading toast waits forever. |
| `toast.promise` stuck on loading | It needs a promise (or a function returning one) as its first argument, and the promise must actually resolve/reject. |
| Swipe-to-dismiss goes the wrong way / doesn't work | Directions derive from `position`. Override with `swipeDirections` on the Toaster. |
| Toast shows up in every toaster | Multiple toasters need targeting: give each Toaster an `id` and pass `toasterId` in the `toast()` call. |
| Toasts too close to the screen edge on mobile | `offset` (desktop, default 32px) and `mobileOffset` (<600px, default 16px) — numbers, CSS strings, or per-side objects. |

© emilkowalski · MIT · emilkowalski/skills

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor