sveltejs avatar

Svelte Core Bestpractices

Opinionated Svelte 5 guidance that steers components toward runes, derived state, and modern event and snippet patterns.

CCM score
78 of 100
skills.sh installs
12.8K
GitHub stars
344
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers reactivity, events, snippets, keyed each blocks, styling child components, context, and async Svelte
  • Includes rules for $state versus $state.raw, $derived versus $effect, and {@attach} versus use:action
  • Enforces runes mode for new code and flags legacy syntax such as export let, $:, <slot>, and on:click
  • Designed for developers writing or reviewing Svelte components and modules inside an existing Svelte project

Install

$ npx -y skills add sveltejs/ai-tools --skill svelte-core-bestpractices -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

$state

Only use the $state rune for variables that should be reactive — in other words, variables that cause an $effect, $derived or template expression to update. Everything else can be a normal variable.

Objects and arrays ($state({...}) or $state([...])) are made deeply reactive, meaning mutation will trigger updates. This has a trade-off: in exchange for fine-grained reactivity, the objects must be proxied, which has performance overhead. In cases where you're dealing with large objects that are only ever reassigned (rather than mutated), use $state.raw instead. This is often the case with API responses, for example.

$derived

To compute something from state, use $derived rather than $effect:

// do this
let square = $derived(num * num);

// don't do this
let square;

$effect(() => {
	square = num * num;
});

[!NOTE] $derived is given an expression, not a function. If you need to use a function (because the expression is complex, for example) use $derived.by.

Deriveds are writable — you can assign to them, just like $state, except that they will re-evaluate when their expression changes.

Details

Repository
github.com/sveltejs/ai-tools
Categories
Frontend & UI Code, Code Review & Quality
First seen
Apr 16, 2026

More from sveltejs/ai-tools

All 2

Similar to Svelte Core Bestpractices

More Frontend & UI Code