Skip to main content
skill CX Codex

svelte5-best-practices — Claude Code skill for Svelte 5 and SvelteKit

A skill that feeds your coding agent Svelte 5 runes, snippets and SvelteKit patterns while you write or refactor components.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add ejirocodes/agent-skills --skill svelte5-best-practices -a claude-code
Open on GitHub

What svelte5-best-practices does

The skill gives the agent a reference on Svelte 5: runes $state, $derived, $effect, $props, $bindable, $inspect, snippets {#snippet} and {@render}, onclick handlers, callback props instead of createEventDispatcher, TypeScript prop typing and generic components. Separate sections cover SvelteKit data loading, form actions, SSR state isolation and performance.

Inside there is a quick-reference table plus files: references/runes.md, snippets.md, events.md, typescript.md, migration.md, sveltekit.md, performance.md. A common-mistakes list is included too. Plain let without $state stays non-reactive, $effect used for computed values should be $derived, on:click is the old syntax, <slot> gives way to snippets, and a missing $bindable() breaks bind:. Sequential await calls in load functions are flagged in favour of Promise.all.

If your project already runs Svelte 5, or you are porting code from Svelte 4, the migration notes on stores to runes and slots to snippets are the part worth reading first. Install is one npx skills command, and it works across Claude, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode.

What it helps with

  • port a component from Svelte 4 to runes
  • swap <slot> for snippets with {@render}
  • drop createEventDispatcher for callback props
  • type props and generic components in TypeScript
  • track down SSR state leaking between requests

Example prompts for the agent

  • Rewrite this component with Svelte 5 runes
  • Check my SvelteKit load function and remove the sequential awaits
  • Refactor these slots into snippets

How to install svelte5-best-practices

1Skills CLI (Vercel)

npx skills add ejirocodes/agent-skills --skill svelte5-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/svelte5-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/svelte5-best-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about svelte5-best-practices

How do I install svelte5-best-practices in Claude?

Run npx skills add ejirocodes/agent-skills --skill svelte5-best-practices -a claude-code. The skill then lands in ~/.claude/skills/svelte5-best-practices/SKILL.md.

What does svelte5-best-practices do?

It hands the agent a reference on runes, snippets, events, TypeScript and SvelteKit so generated and reviewed code follows Svelte 5 patterns instead of Svelte 4 syntax.

Does it cover migrating from Svelte 4?

Yes. references/migration.md walks through Svelte 4 to 5, including stores to runes and slots to snippets.

Source text

SKILL.md · MIT
---
name: svelte5-best-practices
description: "Svelte 5 runes, snippets, SvelteKit patterns, and modern best practices for TypeScript and component development. Use when writing, reviewing, or refactoring Svelte 5 components and SvelteKit applications. Triggers on: Svelte components, runes ($state, $derived, $effect, $props, $bindable, $inspect), snippets ({#snippet}, {@render}), event handling, SvelteKit data loading, form actions, Svelte 4 to Svelte 5 migration, store to rune migration, slots to snippets migration, TypeScript props typing, generic components, SSR state isolation, performance optimization, or component testing."
license: MIT
metadata:
  author: ejirocodes
  version: '1.0.0'
---

# Svelte 5 Best Practices

## Quick Reference

| Topic | When to Use | Reference |
|-------|-------------|-----------|
| **Runes** | $state, $derived, $effect, $props, $bindable, $inspect | [runes.md](references/runes.md) |
| **Snippets** | Replacing slots, {#snippet}, {@render} | [snippets.md](references/snippets.md) |
| **Events** | onclick handlers, callback props, context API | [events.md](references/events.md) |
| **TypeScript** | Props typing, generic components | [typescript.md](references/typescript.md) |
| **Migration** | Svelte 4 to 5, stores to runes | [migration.md](references/migration.md) |
| **SvelteKit** | Load functions, form actions, SSR, page typing | [sveltekit.md](references/sveltekit.md) |
| **Performance** | Universal reactivity, avoiding over-reactivity, streaming | [performance.md](references/performance.md) |

## Essential Patterns

### Reactive State

```svelte
<script>
  let count = $state(0);           // Reactive state
  let doubled = $derived(count * 2); // Computed value
</script>
```

### Component Props

```svelte
<script>
  let { name, count = 0 } = $props();
  let { value = $bindable() } = $props(); // Two-way binding
</script>
```

### Snippets (replacing slots)

```svelte
<script>
  let { children, header } = $props();
</script>

{@render header?.()}
{@render children()}
```

### Event Handlers

```svelte
<!-- Svelte 5: use onclick, not on:click -->
<button onclick={() => count++}>Click</button>
```

### Callback Props (replacing createEventDispatcher)

```svelte
<script>
  let { onclick } = $props();
</script>

<button onclick={() => onclick?.({ data })}>Click</button>
```

## Common Mistakes

1. **Using `let` without `$state`** - Variables are not reactive without `$state()`
2. **Using `$effect` for derived values** - Use `$derived` instead
3. **Using `on:click` syntax** - Use `onclick` in Svelte 5
4. **Using `createEventDispatcher`** - Use callback props instead
5. **Using `<slot>`** - Use snippets with `{@render}`
6. **Forgetting `$bindable()`** - Required for `bind:` to work
7. **Setting module-level state in SSR** - Causes cross-request leaks
8. **Sequential awaits in load functions** - Use `Promise.all` for parallel requests

© ejirocodes · MIT · ejirocodes/agent-skills

Similar skills

Everything for Frontend and UI →

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