Agent skill

Svelte Core Best Practices

by rilldata in rilldata/rill

Rules for writing idiomatic Svelte 5 code: when to reach for runes like state, derived and effect, and how to handle props, attachments and bindings.

Apache-2.0Auto-check passedFrontend & Design

Install Svelte Core Best Practices

skills CLI
$ npx skills add rilldata/rill --skill svelte-core-bestpractices -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rilldata/rill svelte-core-bestpractices --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rilldata/rill.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/svelte-core-bestpractices .claude/skills/svelte-core-bestpractices && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
svelte-core-bestpractices
GitHub stars
2.9k
Used in
4 other repos
Token cost
~1.8k tokens
SKILL.md length
841 words
Files
10 (incl. references)
Skills in repo
1
Repo updated
First seen
Licence
Apache-2.0

At a glance

Rules for writing idiomatic Svelte 5 code: when to reach for runes like state, derived and effect, and how to handle props, attachments and bindings.

  • Writing or editing a Svelte component or module
  • SKILL.md covers $state, $derived, $effect and $props, plus 9 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Deciding whether to use state, derived or an effect

What it does

The skill tells the agent which Svelte rune fits a given situation. State should hold only values that must trigger reactivity, derived should replace effects for anything computed from state, and effects are called an escape hatch to avoid, especially for syncing state back into state. Props are treated as values that can change, so derived values built from them use $derived rather than being computed once.

Reference files go deeper on specific APIs: $inspect for debugging, @attach for syncing to external libraries like D3, @render and snippets, await expressions, bind for two-way and function bindings, each blocks, hydratable markup and the svelte-reactivity helpers such as createSubscriber. The skill warns against patterns like wrapping effect bodies in a browser check, since effects never run on the server anyway.

When your agent uses it

  • Writing or editing a Svelte component or module
  • Deciding whether to use state, derived or an effect
  • Syncing Svelte state to an external library such as D3

Example prompts

  • “Refactor this component to use $derived instead of an effect for the computed total.”
  • “Add a Svelte binding so the child component can update the parent's selected tab.”
  • “Why does my $effect run on the server? Fix it the idiomatic way.”

Requirements

  • A Svelte 5 project

What it can do on your machine

Read from SKILL.md and the folder at commit 8447fa4. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are svelte and javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Svelte Core Best Practices loads about 1.8k tokens when it runs, and up to ~8.6k if it reads all its reference files. Until then it costs about 68 tokens; SKILL.md has 841 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~68
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~8.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rilldata/rill at commit 8447fa4, republished under its Apache-2.0 licence (© rilldata). 841 words, ~1,802 tokens.

Download SKILL.mdSave it as .claude/skills/svelte-core-bestpractices/SKILL.md (or your agent's skills folder). This skill also uses 9 other files; get the full folder from GitHub.
name
svelte-core-bestpractices
description
Guidance on writing fast, robust, modern Svelte code. Load this skill whenever in a Svelte project and asked to write/edit or analyze a Svelte component or module. Covers reactivity, event handling, styling, integration with libraries and more.
glob
**/*.svelte{,.*}

$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:

js
// 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.

If the derived expression is an object or array, it will be returned as-is — it is not made deeply reactive. You can, however, use $state inside $derived.by in the rare cases that you need this.

$effect

Effects are an escape hatch and should mostly be avoided. In particular, avoid updating state inside effects.

  • If you need to sync state to an external library such as D3, it is often neater to use {@attach ...}
  • If you need to run some code in response to user interaction, put the code directly in an event handler or use a function binding as appropriate
  • If you need to log values for debugging purposes, use $inspect
  • If you need to observe something external to Svelte, use createSubscriber

Never wrap the contents of an effect in if (browser) {...} or similar — effects do not run on the server.

$props

Treat props as though they will change. For example, values that depend on props should usually use $derived:

js
// @errors: 2451
let { type } = $props();

// do this
let color = $derived(type === 'danger' ? 'red' : 'green');

// don't do this — `color` will not update if `type` changes
let color = type === 'danger' ? 'red' : 'green';

$inspect.trace

$inspect.trace is a debugging tool for reactivity. If something is not updating properly or running more than it should you can add $inspect.trace(label) as the first line of an $effect or $derived.by (or any function they call) to trace their dependencies and discover which one triggered an update.

Events

Any element attribute starting with on is treated as an event listener:

svelte
<button onclick={() => {...}}>click me</button>

<!-- attribute shorthand also works -->
<button {onclick}>...</button>

<!-- so do spread attributes -->
<button {...props}>...</button>

If you need to attach listeners to window or document you can use <svelte:window> and <svelte:document>:

svelte
<svelte:window onkeydown={...} />
<svelte:document onvisibilitychange={...} />

Avoid using onMount or $effect for this.

Snippets

Snippets are a way to define reusable chunks of markup that can be instantiated with the {@render ...} tag, or passed to components as props. They must be declared within the template.

svelte
{#snippet greeting(name)}
	<p>hello {name}!</p>
{/snippet}

{@render greeting('world')}

[!NOTE] Snippets declared at the top level of a component (i.e. not inside elements or blocks) can be referenced inside <script>. A snippet that doesn't reference component state is also available in a <script module>, in which case it can be exported for use by other components.

Show full SKILL.md (364 more words)Show less

Each blocks

Prefer to use keyed each blocks — this improves performance by allowing Svelte to surgically insert or remove items rather than updating the DOM belonging to existing items.

[!NOTE] The key must uniquely identify the object. Do not use the index as a key.

Avoid destructuring if you need to mutate the item (with something like bind:value={item.count}, for example).

Using JavaScript variables in CSS

If you have a JS variable that you want to use inside CSS you can set a CSS custom property with the style: directive.

svelte
<div style:--columns={columns}>...</div>

You can then reference var(--columns) inside the component's <style>.

Styling child components

The CSS in a component's <style> is scoped to that component. If a parent component needs to control the child's styles, the preferred way is to use CSS custom properties:

svelte
<!-- Parent.svelte -->
<Child --color="red" />

<!-- Child.svelte -->
<h1>Hello</h1>

<style>
	h1 {
		color: var(--color);
	}
</style>

If this is impossible (for example, the child component comes from a library) you can use :global to override styles:

svelte
<div>
	<Child />
</div>

<style>
	div :global {
		h1 {
			color: red;
		}
	}
</style>

Context

Consider using context instead of declaring state in a shared module. This will scope the state to the part of the app that needs it, and eliminate the possibility of it leaking between users when server-side rendering.

Use createContext rather than setContext and getContext, as it provides type safety.

Async Svelte

If using version 5.36 or higher, you can use await expressions and hydratable to use promises directly inside components. Note that these require the experimental.async option to be enabled in svelte.config.js as they are not yet considered fully stable.

Avoid legacy features

Always use runes mode for new code, and avoid features that have more modern replacements:

  • use $state instead of implicit reactivity (e.g. let count = 0; count += 1)
  • use $derived and $effect instead of $: assignments and statements (but only use effects when there is no better solution)
  • use $props instead of export let, $$props and $$restProps
  • use onclick={...} instead of on:click={...}
  • use {#snippet ...} and {@render ...} instead of <slot> and $$slots and <svelte:fragment>
  • use <DynamicComponent> instead of <svelte:component this={DynamicComponent}>
  • use import Self from './ThisComponent.svelte' and <Self> instead of <svelte:self>
  • use classes with $state fields to share reactivity between components, instead of using stores
  • use {@attach ...} instead of use:action
  • use clsx-style arrays and objects in class attributes, instead of the class: directive

© rilldata, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 9 other files (references) in .claude/skills/svelte-core-bestpractices of rilldata/rill.

  • SKILL.md
  • references/$inspect.md
  • references/@attach.md
  • references/@render.md
  • references/await-expressions.md
  • references/bind.md
  • references/each.md
  • references/hydratable.md
  • references/snippet.md
  • references/svelte-reactivity.md

Open the folder on GitHubat commit 8447fa4

Used in 4 other repositories

We found 4 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 4 other GitHub owners. This page covers the copy in rilldata/rill, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Svelte Core Best Practices next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Svelte Core Best Practices compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Svelte Core Best Practices this skillrilldata/rill2.9k4 repos~1.8kAutomated safety check: PassApache-2.0
GSAP in Vue, Nuxt and Sveltegreensock/gsap-skills16k4 repos~2.6kAutomated safety check: PassMIT
SvelteMindrally/skills268—~1.2kAutomated safety check: PassApache-2.0
Uncodixfypdsuwwz/chatgpt-vue3-light-mvp5782 repos~3kAutomated safety check: PassMIT
Design StyleCastor6/tactus3761 repos~2.1kAutomated safety check: PassApache-2.0
Frontend Patternskurealnum/dotfiles29019 repos~3.7kAutomated safety check: PassNone

Similar skills

  • GSAP in Vue, Nuxt and Svelte

    greensock/gsap-skills

    Shows how to use GSAP in Vue, Nuxt, Svelte and other lifecycle-based frameworks: create after mount, scope selectors to the component, and revert on unmount.

    16k GitHub starsUsed in 4 repos~2.6k tokens
    Frontend & DesignAuto-check passed
  • Svelte

    Mindrally/skills

    Modern Svelte 5 and SvelteKit development covering runes-based reactivity, snippets, SSR/SSG, and state management, including migration notes from legacy Svelte 4 syntax.

    268 GitHub stars~1.2k tokensUpdated 1 mo ago
    Frontend & DesignAuto-check passed
  • Uncodixfy

    pdsuwwz/chatgpt-vue3-light-mvp

    Prevents generic AI/Codex UI patterns when generating frontend code.

    578 GitHub starsUsed in 2 repos~3k tokens
    Frontend & DesignAuto-check passed
  • Design Style

    Castor6/tactus

    A skill your agent uses whenever the user asks to build, create, design, develop, improve, or style any frontend interface or visual element.

    376 GitHub starsUsed in 1 repo~2.1k tokens
    Frontend & DesignAuto-check passed
  • Frontend Patterns

    kurealnum/dotfiles

    Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.

    290 GitHub starsUsed in 19 repos~3.7k tokens
    Frontend & DesignAuto-check passed
  • Explains how LobeHub client code fetches data through services, SWR store hooks and cache keys, and when to avoid useEffect fetching or duplicated state.

    83k GitHub stars~1.7k tokensUpdated today
    Frontend & DesignAuto-check passed

Works with

Questions about Svelte Core Best Practices

What does Svelte Core Best Practices do?

Rules for writing idiomatic Svelte 5 code: when to reach for runes like state, derived and effect, and how to handle props, attachments and bindings. The skill tells the agent which Svelte rune fits a given situation. State should hold only values that must trigger reactivity, derived should replace effects for anything computed from state, and effects are called an escape hatch to avoid, especially for syncing state back into state.

When should I use Svelte Core Best Practices?

Svelte Core Best Practices fits situations like: writing or editing a Svelte component or module; deciding whether to use state, derived or an effect; syncing Svelte state to an external library such as D3.

How do I install Svelte Core Best Practices in Claude Code?

Run `npx skills add rilldata/rill --skill svelte-core-bestpractices -a claude-code`. Or copy the skill folder (.claude/skills/svelte-core-bestpractices in rilldata/rill) into .claude/skills/svelte-core-bestpractices in your project. Claude Code loads it when a task matches its description.

How do I install Svelte Core Best Practices in Codex?

Run `npx skills add rilldata/rill --skill svelte-core-bestpractices -a codex`. Or copy the skill folder (.claude/skills/svelte-core-bestpractices in rilldata/rill) into .agents/skills/svelte-core-bestpractices in your project. Codex loads it when a task matches its description.

Can I use Svelte Core Best Practices in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rilldata/rill --skill svelte-core-bestpractices -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/svelte-core-bestpractices, .gemini/skills/svelte-core-bestpractices, .github/skills/svelte-core-bestpractices and .opencode/skills/svelte-core-bestpractices in your project.

What does Svelte Core Best Practices need to run?

SKILL.md names no scripts, command-line tools or credentials: Svelte Core Best Practices is instructions for the agent only. Our summary lists: A Svelte 5 project.

Does Svelte Core Best Practices access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Svelte Core Best Practices safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Svelte Core Best Practices use?

Svelte Core Best Practices is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Svelte Core Best Practices use?

About 1.8k tokens (SKILL.md is roughly 7.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 6.8k tokens, read only when the agent opens those files.

What are the alternatives to Svelte Core Best Practices?

Skills that share tags, products or a category with Svelte Core Best Practices: GSAP in Vue, Nuxt and Svelte (greensock/gsap-skills, 16k stars), Svelte (Mindrally/skills, 268 stars), Uncodixfy (pdsuwwz/chatgpt-vue3-light-mvp, 578 stars) and Design Style (Castor6/tactus, 376 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Svelte Core Best Practices?

rilldata (a GitHub organization) maintains it in rilldata/rill, which has 2,932 GitHub stars. The repository was last updated on October 7, 2026.

Source: rilldata/rill on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.