Svelte and AI coding tools

By Esteban Trillonew today8 min readWhy SvelteSvelte

Piwi patches every hole the autofixer knows about and the tag says "clean". Two leaks still drip through, into a tray marked types and tests.
Piwi patches every hole the autofixer knows about and the tag says "clean". Two leaks still drip through, into a tray marked types and tests.

Part 22, and the last, of a series on Svelte in 2026. Part 21 set up Tailwind v4. This part is about the other thing writing your components now: a coding agent.

Ask a coding agent for a Svelte component and there’s a fair chance you get Svelte 4. export let for props, $: for derived values, on:click, a <slot />. Svelte 5 came out in October 2024, and most of the Svelte code a model saw in training was written before that.1

That would be a small problem if the build complained. It doesn’t. Svelte 5 decides per file whether a component uses runes, and a file without any is compiled in legacy mode, on purpose, so that old components keep working during a migration. The same feature that made part 16’s upgrade gentle means a model can write you the old language and nothing in your toolchain will say so.

The Svelte team saw this coming and shipped tooling for it: an MCP server, a CLI, agent skills and a subagent, all in sveltejs/ai-tools.2 I wanted to know which piece matters, so I gave the main one the code that models tend to get wrong and wrote down what it said.

The lab ran Svelte 5.57.3, @sveltejs/mcp 0.1.28, svelte-check 4.7.7 and sv 1.1.1 on Node 24, with jsdom for the one runtime check.

Svelte 4 compiles clean

Here’s a filterable list written the way a model fluent in 2023 Svelte writes it:

Legacy.svelte
<script>
import { onMount } from "svelte";
export let items = [];
let filter = "";
$: shown = items.filter((i) => i.name.includes(filter));
onMount(() => {
window.addEventListener("keydown", onKey);
});
function onKey(e) {
if (e.key === "Escape") filter = "";
}
</script>
<input bind:value={filter} />
<button on:click={() => (filter = "")}>Clear</button>
<ul>
{#each shown as item}
<li>{item.name}</li>
{/each}
</ul>
<slot />

Svelte 5.57.3’s compile() returned it with no errors and no warnings. Not one deprecation notice, because in legacy mode none of this is deprecated. svelte-check in a strict TypeScript project only complained about implicit any types.

A half-migrated file is where it gets noisy. Swap the props for $props() and the filter for $state, keep on:click, and the compiler now knows it’s in runes mode and warns event_directive_deprecated. The trouble is the version in between, the one that’s entirely old and therefore entirely quiet, and that’s exactly the one an agent with no Svelte 5 context produces.

What the autofixer catches

svelte-autofixer is the tool in the MCP server that matters most here. It’s static analysis over a component, and you can run it without any MCP client at all: npx @sveltejs/mcp svelte-autofixer src/lib/List.svelte --svelte-version 5.57.3 prints issues, suggestions and a flag called require_another_tool_call_after_fixing.3

On the legacy file it reported one issue:

Cannot use `export let` in runes mode — use `$props()` instead
https://svelte.dev/e/legacy_export_invalid at line 3, column 2

So the autofixer analyses everything as runes mode, which is the right call: it treats Svelte 4 syntax as wrong rather than as an alternative. It also reports one compile error at a time, since the compiler stops at the first. I fixed export let and ran it again, and it moved on to $: (legacy_reactive_statement_invalid). Fixing that turned up three at once, because those were warnings rather than errors: on:click deprecated, <slot> deprecated, and “Each block should have a key”. A fourth run came back with empty issues, empty suggestions and require_another_tool_call_after_fixing: false.

That flag tells you how the tool expects to be used. It isn’t a lint report for you to read; it’s one turn in a loop the agent runs until the flag goes false, and the Svelte docs’ own AGENTS.md text tells the model to “keep calling it until no issues or suggestions are returned.”4 Four calls for a component this size is cheap.

It’s also more than a compiler with the strictness turned up. Given the classic runes mistake, syncing a value with an effect:

let shown = $state([]);
$effect(() => {
shown = items.filter((i) => i.name.includes(filter));
});

it came back with suggestions on top of the compiler warnings, among them “The stateful variable “shown” is assigned inside an $effect which is generally consider a malpractice. Consider using $derived if possible.” and “Prefer using writable $derived instead of $state and $effect”. That’s part 5 in two lines, and the Svelte compiler on its own says nothing about it.

A coding agent hands you a component with export let, $: and on:click. Svelte 5's compiler accepts it without a warning. Why?

What a clean report still lets through

The fourth run said the component was clean. It still had a bug from the first draft: onMount adds a keydown listener to window and never removes it. Part 9 measured that exact leak, three unmounted components all still answering one keypress, and the fix, <svelte:window onkeydown={...} />. The autofixer didn’t mention it. Moving the listener into an $effect with no cleanup didn’t get flagged either; it drew only a generic “you are calling a function inside an $effect” suggestion about derived state, nothing about teardown.

The second one is a React habit, and it’s worse because it fails silently at runtime:

<button onClick={() => (open = !open)}>Toggle</button>

Svelte 5 event attributes are case-sensitive. That compiles to $.event('Click', button, ...), a listener for an event called Click, which no browser fires. In jsdom, clicking the button left the list closed; with onclick it opened. The compiler gave no warning and neither did the autofixer. What caught it was svelte-check in a TypeScript project, with “"onClick" does not exist in type HTMLProps<"button", ...>”. Even that only showed up after I removed a className from the same tag, because TypeScript reports one excess property per object literal and className got reported first.

So I’d treat the autofixer as one check in a stack, not as the stack. It’s very good at “this is Svelte 4” and at a handful of runes anti-patterns; types catch a different set; and behaviour still needs a test, part 17’s kind, clicking the button and looking at the DOM.

Docs the model can read

The other half of the tooling is context. Every docs page has an llms.txt version, and svelte.dev/llms.txt indexes three bundles of the whole Svelte and SvelteKit docs.5 The day I fetched them, the full one was about 1.27 MB, the “abridged” one about 877 KB and the “compressed” one 53 KB. Only that last one is something you’d paste into a prompt without thinking about your context window, and it keeps the size down by dropping most of the examples.

The MCP server does this lazily instead. list-sections returned 205 sections, each with a use_cases field, and get-documentation fetches just the ones the agent asks for. The skills go further. svelte-core-bestpractices is the page part 9 tested, packaged as a skill of about 1,100 words plus nine reference files; the agent loads it only when it’s working on a .svelte file. svelte-code-writer teaches the agent the CLI commands, for clients where the MCP server isn’t connected.6

React has a docs index for models too: react.dev/llms.txt lists every page as Markdown. What it doesn’t have is an official tool that runs on a component and says “this is old React”, partly because React’s old code mostly still is React. Class components and useEffect-for-everything are discouraged, not a different syntax. Svelte’s break between 4 and 5 is sharper, which is why its tooling leans so hard on correction rather than reference.

An agent's autofixer loop ends with no issues and require_another_tool_call_after_fixing: false. What does that tell you?

The setup I’d use

npx sv add ai-tools does the wiring. With Claude Code picked and individual tools selected, it wrote an .mcp.json that runs npx -y @sveltejs/mcp, an AGENTS.md with the tool instructions, a .claude/CLAUDE.md that imports it, the best-practices skill and the svelte-file-editor subagent.7 The plugin option does the same through a committed .claude/settings.json and keeps itself updated. There’s also a remote server at mcp.svelte.dev/mcp, and the team says it doesn’t log, store or inspect the code you send it.8

I’d take the local server, the best-practices skill and the AGENTS.md text, and skip the playground tool, which only matters if your agent writes code into a chat window instead of files. The subagent is worth it on a long session: it runs the docs lookup and autofixer loop in its own context, so twenty rounds of tool output don’t crowd out the rest of the conversation.

And keep svelte-check and a component test in CI, because the autofixer agreed with me twice when I was wrong. Svelte’s honest advantage here isn’t that models write it better than React; they mostly don’t, yet. It’s that the gap is small, mechanical and documented, and the people who make the framework have written the tool that closes most of it.

Where the series stops

This is the last part. Part 1 asked you to look, not to switch. Twenty-two posts later that’s still roughly where I land, with better reasons.

The case for Svelte held up when I measured it. The counter shipped about 10 kB gzipped against React’s 69 kB in part 2, and in part 19 ticking one item in a 100-item list re-ran zero component functions in Svelte and 101 in React, Compiler or not. Runes turned out to be a smaller language than hooks, with fewer ways to get the same thing subtly wrong.

The case against held up too. React’s ecosystem and hiring pool are bigger, and remote functions were still experimental when I tested them. Part 20’s library broke on a template that lagged its own docs. And the models writing more of our code are still more fluent in React, and in Svelte 4, than in Svelte 5. If your team already ships React and nothing hurts, none of that adds up to a rewrite. If you’re starting something new, or something keeps re-rendering that shouldn’t, build one real screen in Svelte 5 with the autofixer in the loop. Then decide.

Footnotes

  1. Svelte blog, Svelte 5 is alive, October 2024. ↩

  2. Svelte docs, AI overview: instructions, MCP server, skills and subagents. Source in sveltejs/ai-tools. ↩

  3. Svelte docs, CLI and Tools. ↩

  4. Svelte docs, AGENTS.md. ↩

  5. svelte.dev/llms.txt. Sizes are the bytes downloaded on the day I ran the lab, rounded; they move with every docs change. ↩

  6. Svelte docs, Skills and Subagent. ↩

  7. Svelte CLI docs, ai-tools. ↩

  8. Svelte docs, Remote setup. ↩

Read next

  1. Svelte + Tailwind v4 setupDec 3, 2026 Why Svelte · 8 min
  2. A component library in SvelteDec 3, 2026 Why Svelte · 7 min
  3. Svelte vs React: one component, two waysDec 2, 2026 Why Svelte · 7 min
  4. Observability in SvelteKitDec 2, 2026 Why Svelte · 6 min
  5. Testing Svelte componentsDec 2, 2026 Why Svelte · 7 min
Piwi hands a single letter to the user at a mailbox; a small note reads no noise.

Get the next one in your inbox

One email when a post goes out, with its sketch. Nothing in between, and one link to leave.

Sign in faster next time?

Add a passkey and skip the email link. Your fingerprint, face or device PIN is enough.