/svelte-5:code-style-sveltefrom svelte-5
Enforces Svelte 5 code style rules for components, transitions, layout reads, and SvelteKit navigation guards. Auto-activates when editing .svelte files or component structure.
Ships in svelte-5. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
REQUIRED SUB-SKILL: invoke svelte-5:composition-svelte before you build or restructure a complex feature (wrapper or provider components, snippet APIs, shared state, third-party DOM bridging).
Ask the user whether to invoke svelte-5:composition-svelte to refactor a component when either holds:
.svelte file is longer than 300 lines, not counting its <style> blockUse {@render snippet?.()} instead of {#if snippet}{@render snippet()}{/if}. The optional chaining form is shorter and idiomatic Svelte 5.
$effect for setting stateNEVER use $effect to set state. If you need derived state, use $derived instead. Effects that write to state create unnecessary re-renders and are a sign of wrong reactive design.
async in onMount or $effectNEVER pass an async function directly to onMount or $effect:
// BAD — cleanup function is lost, dependency tracking breaks
onMount(async () => { ... });
$effect(async () => { ... });
// GOOD — async IIFE inside a sync wrapper
onMount(() => {
(async () => { ... })();
return () => { /* cleanup */ };
});
Two reasons:
onMount and $effect expect the callback to optionally return a teardown function. An async function always returns a Promise, so the teardown never runs: intervals won't clear, subscriptions won't unsubscribe, listeners won't detach.$effect only). $effect tracks reactive dependencies that are read synchronously. Anything read after an await is invisible to the tracker and won't trigger re-runs.addEventListener / removeEventListenerNEVER use addEventListener or removeEventListener in Svelte components. Svelte 5 has multiple declarative mechanisms for event handling, on* attributes, callback props, svelte:window, svelte:document, svelte:body, and the on action from svelte/events. These handle cleanup automatically and integrate with Svelte's reactivity.
When unsure which pattern to use, invoke the Svelte MCP autofixer (mcp__plugin_svelte_svelte__svelte-autofixer) or fetch the relevant docs via mcp__plugin_svelte_svelte__get-documentation (sections: svelte-events, svelte-window, svelte-document, svelte-body).
bind:clientWidth, bind:clientHeight, bind:offsetWidth, bind:offsetHeight, bind:contentRect), which Svelte measures with a ResizeObserver. The observer can't measure an element with display: inline, and CSS transforms don't trigger it.innerWidth.current and its siblings from svelte/reactivity/window (undefined on the server), or bind them on <svelte:window>.getBoundingClientRect() or read offsetHeight or scrollTop inside $effect or $derived: each read can force a synchronous reflow. For other DOM work, use {@attach} (svelte:svelte-core-bestpractices).prefersReducedMotion. Svelte runs transition:, in: and out: through the Web Animations API, so a global @media (prefers-reduced-motion: reduce) rule that zeroes transition-duration does not affect them. Read prefersReducedMotion.current from svelte/motion and shorten or drop the motion, for example transition:fly={{ y: prefersReducedMotion.current ? 0 : 200 }}.page.url.searchParams ($app/state) in components and from the url parameter in load. Change them with a link, a GET <form>, or goto('?key=value'). page.url is readonly, so copy it with new URL(page.url.href) before you change it. Disposable UI state, such as whether an accordion is open, stays out of the URL; use a snapshot if it should survive back and forward navigation.beforeNavigate. Call navigation.cancel() while the form has unsaved changes. For a leave navigation (closing the tab or leaving the app), cancel() shows the browser's own unload dialog. beforeNavigate also runs for shallow routing, so return early when navigation.shallow is true, unless that shallow navigation should be guarded too.slot=, not {#snippet}TODO: verify this is still needed after sveltejs/language-tools#2716 is resolved
When a Svelte 5 (runes mode) component renders a Svelte 4 child
that uses <slot name="...">, pass content with slot="name"
attribute syntax, NOT {#snippet name()}.
<!-- GOOD — slot= works in runes mode and passes svelte-check -->
<CollapsibleCard>
<div slot="header">Header content</div>
<div slot="body">Body content</div>
</CollapsibleCard>
<!-- BAD — runtime works but svelte-check rejects it -->
<CollapsibleCard>
{#snippet header()}Header content{/snippet}
{#snippet body()}Body content{/snippet}
</CollapsibleCard>
Why: svelte-check does not resolve named snippet props on
legacy components (sveltejs/language-tools#2716,
open as of 2026-04-09). The {#snippet} approach produces
'header' does not exist in type errors. The slot= attribute
is still valid in runes-mode components and passes all checks.
When to use {#snippet}: Only when the child component is
also Svelte 5 and accepts snippet props via $props().
Events from Svelte 4 children: on:click, on:change, etc.
still work in a Svelte 5 parent. Use on: for Svelte 4 children,
onclick/callback props for Svelte 5 children.
Verified 2026-04-09 with svelte ^5.55.2, svelte-check ^4.4.6.
Svelte supports standard HTML comments in component markup. <!-- stylelint-disable -->, <!-- svelte-ignore ... -->, and other tool-control comments work in .svelte files. frontend:editing decides when svelte-ignore is allowed.
@component)Every new .svelte component file MUST start with a <!-- @component --> comment block on the very first line that documents the component's purpose. This follows JSDoc conventions, the @component tag is picked up by the Svelte language server (svelte2tsx) to display documentation on hover in IDEs, similar to how /** @description */ works in JSDoc for JS/TS files.
Format:
<!--
@component
Brief description of what this component does.
Additional details if needed.
-->
The @component tag must appear inside the HTML comment. The description follows on subsequent lines, indented with a tab. Keep it concise but informative, someone reading this should understand the component's role without reading the implementation.
You can use other JSDoc tags inside the comment block where useful (e.g. @example, @see, @deprecated).
Excluded: pages, layouts, tests, and stories (.stories.svelte) do not need this comment.
frontend:css-nesting skill.:global() selectors unless told otherwise. This is a code smell. Either refactor the component, relocate the state or use global feature-specific stylesheets.frontend:code-style: General code style rules (variable naming, braces, data attributes). Applies to all code including Svelte.svelte:svelte-code-writer: Svelte 5 documentation lookup and code analysis. MUST invoke when creating or editing .svelte / .svelte.ts / .svelte.js files.svelte:svelte-core-bestpractices: Reactivity, events, styling, and integration patterns for modern Svelte.svelte:svelte-file-editor: Svelte 5 subagent. Delegate .svelte / .svelte.ts / .svelte.js create/edit/review to it (separate context window) instead of editing inline when practical.svelte-5:testing-svelte: Vitest + Playwright testing patterns for Svelte 5 components.frontend:css-nesting: CSS nesting rules.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub fubits1/svelte-skills --plugin svelte-58 skills in this plugin
/composition-svelteUse when composing a Svelte 5 feature from provider/wrapper components, content snippets, reactive state, or third-party DOM bridging (maplibre, leaflet, d3, tippy, popper). Covers overlay wrappers, snippet APIs, and state location./doc-componentDocument a Svelte component using @component JSDoc. Auto-invoke when asked to document a .svelte component. Reads the component, analyzes its interface, and writes a structured @component comment block./mswMocks HTTP with msw 3 in Svelte, Storybook, Vitest and SvelteKit. Use when writing http.get handlers or parameters.msw, upgrading from msw 2, or debugging blank stories, handler order, query strings, onUnhandledFrame or mockServiceWorker.js./storybookStorybook authoring and browser checks for Svelte: MCP instructions, previews, Svelte 4 store wrappers, CSS imports in preview.ts. Use when writing or reviewing .stories.svelte files, moving a CSS import that stories need, or a story renders empty./storybook-vitestSvelte CSF stories as Vitest browser tests via @storybook/addon-vitest: play, tags, decorators, asChild. Use when wiring or debugging them in Vitest/CI, or on 'Vitest failed to find the current suite' or props_invalid_value. Not for React/Vue./testing-svelteFix or write Svelte 5 tests with vitest-browser-svelte and Playwright. Use when debugging broken or flaky tests, 'Cannot connect to the iframe', strict mode violations, or writing unit/SSR/e2e tests.Other plugins' skills for the same job