/sveltekit-best-practices:sveltekit-best-practicesfrom SvelteKit Best Practices
Enforces Svelte 5 runes ($state, $derived, $effect, $props) over Svelte 4 stores, $:, and export let patterns in SvelteKit projects.
Ships in SvelteKit Best Practices. 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.
Use this skill when working with SvelteKit or Svelte 5 code. AI agents are trained on Svelte 4 patterns and frequently generate outdated code using stores, reactive declarations, and export let. This skill enforces Svelte 5 runes, load functions, and form actions.
Wrong (agents do this):
<script>
import { writable, derived } from 'svelte/store';
let count = writable(0);
$: doubled = $count * 2;
$: if (count > 5) alert('too high');
</script>
<p>{$count}</p>
Correct:
<script>
let count = $state(0);
let doubled = $derived(count * 2);
$effect(() => {
if (count > 5) alert('too high');
});
</script>
<p>{count}</p>
Why: Svelte 5 runes ($state, $derived, $effect) replace stores and $: syntax. Agents default to Svelte 4 patterns.
Wrong:
<script>
let count = 0;
count = count + 1;
</script>
Correct:
<script>
let count = $state(0);
count = count + 1;
</script>
Why: In Svelte 5, reactivity is opt-in via $state. Plain let is not reactive.
Wrong:
<script>
let firstName = $state('John');
let lastName = $state('Doe');
$: fullName = `${firstName} ${lastName}`;
</script>
Correct:
<script>
let firstName = $state('John');
let lastName = $state('Doe');
let fullName = $derived(`${firstName} ${lastName}`);
</script>
Why: $: is Svelte 4. Svelte 5 uses $derived for derivations.
Wrong:
<script>
let count = $state(0);
$: if (count > 5) console.log('count is high');
</script>
Correct:
<script>
let count = $state(0);
$effect(() => {
if (count > 5) console.log('count is high');
});
</script>
Why: $effect runs when dependencies change. $: for side effects is deprecated.
Wrong:
<script>
export let title = 'Default';
export let count;
</script>
<h1>{title}</h1>
Correct:
<script>
let { title = 'Default', count } = $props();
</script>
<h1>{title}</h1>
Why: export let is Svelte 4. Svelte 5 uses $props().
Wrong:
<script>
let { value } = $props();
</script>
<input bind:value={value} />
Correct:
<script>
let { value = $bindable() } = $props();
</script>
<input bind:value={value} />
Why: Props are one-way by default. $bindable() enables bind:value from parent.
Wrong:
<script>
import { onMount } from 'svelte';
let data = $state(null);
onMount(async () => {
data = await fetch('/api/users').then(r => r.json());
});
</script>
{#if data}{data.name}{/if}
Correct:
// +page.server.ts
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ fetch }) => ({
data: await fetch("/api/users").then((r) => r.json()),
});
<!-- +page.svelte -->
<script>
let { data } = $props();
</script>
{#if data}{data.name}{/if}
Why: Load runs on server for SSR, avoids loading flicker, and integrates with SvelteKit routing.
Wrong:
<form on:submit={async (e) => {
e.preventDefault();
await fetch('/api/login', { method: 'POST', body: new FormData(e.target) });
goto('/dashboard');
}}>
Correct:
// +page.server.ts
import type { Actions } from "./$types";
export const actions = {
default: async ({ request, cookies }) => {
const data = await request.formData();
// validate, authenticate, set cookie
return { type: "redirect", location: "/dashboard" };
},
};
<form method="POST" use:enhance>
Why: Form actions enable progressive enhancement, work without JS, and avoid client-side fetch boilerplate.
Wrong:
<!-- Multiple pages each fetch user -->
<script>
let user = $state(null);
onMount(() => fetchUser().then(u => user = u));
</script>
Correct:
// +layout.server.ts
export const load = async ({ locals }) => ({
user: locals.user,
});
Why: Layout load runs once, data is available to all child pages. No duplicate fetches.
Correct:
<!-- +error.svelte -->
<script>
let { status, message } = $props();
</script>
<h1>{status}</h1>
<p>{message}</p>
Why: SvelteKit uses +error.svelte to render load/action errors. Use it instead of try/catch in every page.
When data is needed on both server and client (e.g. from $app/stores or browser APIs), put logic in +page.ts. Use +page.server.ts when data is server-only.
Correct:
// hooks.server.ts
export const handle = async ({ event, resolve }) => {
event.locals.user = await getUser(event);
if (!event.locals.user && event.url.pathname.startsWith("/dashboard")) {
return redirect(302, "/login");
}
return resolve(event);
};
Why: Handle runs before every request. Use for auth, redirects, and setting locals.
Prefer passing data via load props. Use $page, $navigating, etc. only when you need client-side routing state.
Wrong:
<script>
export let slots;
</script>
{#if slots.header}<slot name="header" />{/if}
Correct:
<script>
let { header = @render(() => {}) } = $props();
</script>
{@render header()}
Why: Svelte 5 snippets replace slot-based composition with @render and snippet props.
datamethod="POST" and use:enhance from $app/forms{#await data.promise} in templateimport type { PageServerLoad, PageProps } from './$types'What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (ofershap/sveltekit-best-practices) — no native marketplace selected
npx claudepluginhub p/ofershap-sveltekit-best-practicesOther plugins' skills for the same job